2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 * Refactored from builtin-top.c, see that files for further copyright notes.
6 * Released under the GPL v2. (and only v2, not any later version)
13 #include "parse-events.h"
18 #define SNPRINTF(buf, size, fmt, args...) \
20 size_t r = snprintf(buf, size, fmt, ## args); \
21 r > size ? size : r; \
24 size_t perf_top__header_snprintf(struct perf_top
*top
, char *bf
, size_t size
)
26 float samples_per_sec
;
27 float ksamples_per_sec
;
28 float esamples_percent
;
29 struct record_opts
*opts
= &top
->record_opts
;
30 struct target
*target
= &opts
->target
;
34 samples_per_sec
= top
->samples
/ top
->delay_secs
;
35 ksamples_per_sec
= top
->kernel_samples
/ top
->delay_secs
;
36 esamples_percent
= (100.0 * top
->exact_samples
) / top
->samples
;
38 samples_per_sec
= ksamples_per_sec
= esamples_percent
= 0.0;
42 float ksamples_percent
= 0.0;
45 ksamples_percent
= (100.0 * ksamples_per_sec
) /
47 ret
= SNPRINTF(bf
, size
,
48 " PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
49 " exact: %4.1f%% lost: %" PRIu64
"/%" PRIu64
" drop: %" PRIu64
"/%" PRIu64
" [",
50 samples_per_sec
, ksamples_percent
, esamples_percent
,
51 top
->lost
, top
->lost_total
, top
->drop
, top
->drop_total
);
53 float us_samples_per_sec
= top
->us_samples
/ top
->delay_secs
;
54 float guest_kernel_samples_per_sec
= top
->guest_kernel_samples
/ top
->delay_secs
;
55 float guest_us_samples_per_sec
= top
->guest_us_samples
/ top
->delay_secs
;
57 ret
= SNPRINTF(bf
, size
,
58 " PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%"
59 " guest kernel:%4.1f%% guest us:%4.1f%%"
60 " exact: %4.1f%% [", samples_per_sec
,
61 100.0 - (100.0 * ((samples_per_sec
- ksamples_per_sec
) /
63 100.0 - (100.0 * ((samples_per_sec
- us_samples_per_sec
) /
65 100.0 - (100.0 * ((samples_per_sec
-
66 guest_kernel_samples_per_sec
) /
68 100.0 - (100.0 * ((samples_per_sec
-
69 guest_us_samples_per_sec
) /
74 if (top
->evlist
->nr_entries
== 1) {
75 struct perf_evsel
*first
= perf_evlist__first(top
->evlist
);
76 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, "%" PRIu64
"%s ",
77 (uint64_t)first
->attr
.sample_period
,
78 opts
->freq
? "Hz" : "");
81 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, "%s", perf_evsel__name(top
->sym_evsel
));
83 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, "], ");
86 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (target_pid: %s",
89 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (target_tid: %s",
91 else if (target
->uid_str
!= NULL
)
92 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (uid: %s",
95 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (all");
98 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, ", CPU%s: %s)",
99 top
->evlist
->cpus
->nr
> 1 ? "s" : "",
103 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, ")");
105 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, ", %d CPU%s)",
106 top
->evlist
->cpus
->nr
,
107 top
->evlist
->cpus
->nr
> 1 ? "s" : "");
110 perf_top__reset_sample_counters(top
);
114 void perf_top__reset_sample_counters(struct perf_top
*top
)
116 top
->samples
= top
->us_samples
= top
->kernel_samples
=
117 top
->exact_samples
= top
->guest_kernel_samples
=
118 top
->guest_us_samples
= top
->lost
= top
->drop
= 0;