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 = top->samples / top->delay_secs;
27 float ksamples_per_sec = top->kernel_samples / top->delay_secs;
28 float esamples_percent = (100.0 * top->exact_samples) / top->samples;
32 ret = SNPRINTF(bf, size,
33 " PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
34 " exact: %4.1f%% [", samples_per_sec,
35 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) /
39 float us_samples_per_sec = top->us_samples / top->delay_secs;
40 float guest_kernel_samples_per_sec = top->guest_kernel_samples / top->delay_secs;
41 float guest_us_samples_per_sec = top->guest_us_samples / top->delay_secs;
43 ret = SNPRINTF(bf, size,
44 " PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%"
45 " guest kernel:%4.1f%% guest us:%4.1f%%"
46 " exact: %4.1f%% [", samples_per_sec,
47 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) /
49 100.0 - (100.0 * ((samples_per_sec - us_samples_per_sec) /
51 100.0 - (100.0 * ((samples_per_sec -
52 guest_kernel_samples_per_sec) /
54 100.0 - (100.0 * ((samples_per_sec -
55 guest_us_samples_per_sec) /
60 if (top->evlist->nr_entries == 1) {
61 struct perf_evsel *first = perf_evlist__first(top->evlist);
62 ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
63 (uint64_t)first->attr.sample_period,
64 top->freq ? "Hz" : "");
67 ret += SNPRINTF(bf + ret, size - ret, "%s", perf_evsel__name(top->sym_evsel));
69 ret += SNPRINTF(bf + ret, size - ret, "], ");
72 ret += SNPRINTF(bf + ret, size - ret, " (target_pid: %s",
74 else if (top->target.tid)
75 ret += SNPRINTF(bf + ret, size - ret, " (target_tid: %s",
77 else if (top->target.uid_str != NULL)
78 ret += SNPRINTF(bf + ret, size - ret, " (uid: %s",
81 ret += SNPRINTF(bf + ret, size - ret, " (all");
83 if (top->target.cpu_list)
84 ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)",
85 top->evlist->cpus->nr > 1 ? "s" : "",
86 top->target.cpu_list);
89 ret += SNPRINTF(bf + ret, size - ret, ")");
91 ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)",
92 top->evlist->cpus->nr,
93 top->evlist->cpus->nr > 1 ? "s" : "");
99 void perf_top__reset_sample_counters(struct perf_top *top)
101 top->samples = top->us_samples = top->kernel_samples =
102 top->exact_samples = top->guest_kernel_samples =
103 top->guest_us_samples = 0;