4 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
6 struct perf_evsel
*perf_evsel__new(u32 type
, u64 config
, int idx
)
8 struct perf_evsel
*evsel
= zalloc(sizeof(*evsel
));
12 evsel
->attr
.type
= type
;
13 evsel
->attr
.config
= config
;
14 INIT_LIST_HEAD(&evsel
->node
);
20 int perf_evsel__alloc_fd(struct perf_evsel
*evsel
, int ncpus
, int nthreads
)
22 evsel
->fd
= xyarray__new(ncpus
, nthreads
, sizeof(int));
23 return evsel
->fd
!= NULL
? 0 : -ENOMEM
;
26 int perf_evsel__alloc_counts(struct perf_evsel
*evsel
, int ncpus
)
28 evsel
->counts
= zalloc((sizeof(*evsel
->counts
) +
29 (ncpus
* sizeof(struct perf_counts_values
))));
30 return evsel
->counts
!= NULL
? 0 : -ENOMEM
;
33 void perf_evsel__free_fd(struct perf_evsel
*evsel
)
35 xyarray__delete(evsel
->fd
);
39 void perf_evsel__close_fd(struct perf_evsel
*evsel
, int ncpus
, int nthreads
)
43 for (cpu
= 0; cpu
< ncpus
; cpu
++)
44 for (thread
= 0; thread
< nthreads
; ++thread
) {
45 close(FD(evsel
, cpu
, thread
));
46 FD(evsel
, cpu
, thread
) = -1;
50 void perf_evsel__delete(struct perf_evsel
*evsel
)
52 assert(list_empty(&evsel
->node
));
53 xyarray__delete(evsel
->fd
);
57 int __perf_evsel__read_on_cpu(struct perf_evsel
*evsel
,
58 int cpu
, int thread
, bool scale
)
60 struct perf_counts_values count
;
61 size_t nv
= scale
? 3 : 1;
63 if (FD(evsel
, cpu
, thread
) < 0)
66 if (readn(FD(evsel
, cpu
, thread
), &count
, nv
* sizeof(u64
)) < 0)
72 else if (count
.run
< count
.ena
)
73 count
.val
= (u64
)((double)count
.val
* count
.ena
/ count
.run
+ 0.5);
75 count
.ena
= count
.run
= 0;
77 evsel
->counts
->cpu
[cpu
] = count
;
81 int __perf_evsel__read(struct perf_evsel
*evsel
,
82 int ncpus
, int nthreads
, bool scale
)
84 size_t nv
= scale
? 3 : 1;
86 struct perf_counts_values
*aggr
= &evsel
->counts
->aggr
, count
;
90 for (cpu
= 0; cpu
< ncpus
; cpu
++) {
91 for (thread
= 0; thread
< nthreads
; thread
++) {
92 if (FD(evsel
, cpu
, thread
) < 0)
95 if (readn(FD(evsel
, cpu
, thread
),
96 &count
, nv
* sizeof(u64
)) < 0)
99 aggr
->val
+= count
.val
;
101 aggr
->ena
+= count
.ena
;
102 aggr
->run
+= count
.run
;
107 evsel
->counts
->scaled
= 0;
109 if (aggr
->run
== 0) {
110 evsel
->counts
->scaled
= -1;
115 if (aggr
->run
< aggr
->ena
) {
116 evsel
->counts
->scaled
= 1;
117 aggr
->val
= (u64
)((double)aggr
->val
* aggr
->ena
/ aggr
->run
+ 0.5);
120 aggr
->ena
= aggr
->run
= 0;
This page took 0.056833 seconds and 5 git commands to generate.