1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5 * Refactored from builtin-top.c, see that files for further copyright notes.
11 #include "parse-events.h"
17 #define SNPRINTF(buf, size, fmt, args...) \
19 size_t r = snprintf(buf, size, fmt, ## args); \
20 r > size ? size : r; \
23 size_t perf_top__header_snprintf(struct perf_top
*top
, char *bf
, size_t size
)
25 float samples_per_sec
;
26 float ksamples_per_sec
;
27 float esamples_percent
;
28 struct record_opts
*opts
= &top
->record_opts
;
29 struct target
*target
= &opts
->target
;
33 samples_per_sec
= top
->samples
/ top
->delay_secs
;
34 ksamples_per_sec
= top
->kernel_samples
/ top
->delay_secs
;
35 esamples_percent
= (100.0 * top
->exact_samples
) / top
->samples
;
37 samples_per_sec
= ksamples_per_sec
= esamples_percent
= 0.0;
41 float ksamples_percent
= 0.0;
44 ksamples_percent
= (100.0 * ksamples_per_sec
) /
46 ret
= SNPRINTF(bf
, size
,
47 " PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
48 " exact: %4.1f%% lost: %" PRIu64
"/%" PRIu64
" drop: %" PRIu64
"/%" PRIu64
" [",
49 samples_per_sec
, ksamples_percent
, esamples_percent
,
50 top
->lost
, top
->lost_total
, top
->drop
, top
->drop_total
);
52 float us_samples_per_sec
= top
->us_samples
/ top
->delay_secs
;
53 float guest_kernel_samples_per_sec
= top
->guest_kernel_samples
/ top
->delay_secs
;
54 float guest_us_samples_per_sec
= top
->guest_us_samples
/ top
->delay_secs
;
56 ret
= SNPRINTF(bf
, size
,
57 " PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%"
58 " guest kernel:%4.1f%% guest us:%4.1f%%"
59 " exact: %4.1f%% [", samples_per_sec
,
60 100.0 - (100.0 * ((samples_per_sec
- ksamples_per_sec
) /
62 100.0 - (100.0 * ((samples_per_sec
- us_samples_per_sec
) /
64 100.0 - (100.0 * ((samples_per_sec
-
65 guest_kernel_samples_per_sec
) /
67 100.0 - (100.0 * ((samples_per_sec
-
68 guest_us_samples_per_sec
) /
73 if (top
->evlist
->core
.nr_entries
== 1) {
74 struct evsel
*first
= evlist__first(top
->evlist
);
75 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, "%" PRIu64
"%s ",
76 (uint64_t)first
->core
.attr
.sample_period
,
77 opts
->freq
? "Hz" : "");
80 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, "%s", evsel__name(top
->sym_evsel
));
82 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, "], ");
85 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (target_pid: %s",
88 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (target_tid: %s",
90 else if (target
->uid_str
!= NULL
)
91 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (uid: %s",
94 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, " (all");
97 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, ", CPU%s: %s)",
98 top
->evlist
->core
.cpus
->nr
> 1 ? "s" : "",
102 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, ")");
104 ret
+= SNPRINTF(bf
+ ret
, size
- ret
, ", %d CPU%s)",
105 top
->evlist
->core
.cpus
->nr
,
106 top
->evlist
->core
.cpus
->nr
> 1 ? "s" : "");
109 perf_top__reset_sample_counters(top
);
113 void perf_top__reset_sample_counters(struct perf_top
*top
)
115 top
->samples
= top
->us_samples
= top
->kernel_samples
=
116 top
->exact_samples
= top
->guest_kernel_samples
=
117 top
->guest_us_samples
= top
->lost
= top
->drop
= 0;