blob: 500471dffa4fdaf08968fa00e8cf825417262120 [file] [log] [blame]
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -02001/*
2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Refactored from builtin-top.c, see that files for further copyright notes.
5 *
6 * Released under the GPL v2. (and only v2, not any later version)
7 */
8
9#include "cpumap.h"
10#include "event.h"
11#include "evlist.h"
12#include "evsel.h"
13#include "parse-events.h"
14#include "symbol.h"
15#include "top.h"
16#include <inttypes.h>
17
Jiri Olsab9a46bb2011-03-07 21:13:40 +010018#define SNPRINTF(buf, size, fmt, args...) \
19({ \
20 size_t r = snprintf(buf, size, fmt, ## args); \
21 r > size ? size : r; \
22})
23
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020024size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
25{
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020026 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;
29 size_t ret = 0;
30
31 if (!perf_guest) {
Jiri Olsab9a46bb2011-03-07 21:13:40 +010032 ret = SNPRINTF(bf, size,
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020033 " 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) /
36 samples_per_sec)),
37 esamples_percent);
38 } else {
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;
42
Jiri Olsab9a46bb2011-03-07 21:13:40 +010043 ret = SNPRINTF(bf, size,
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020044 " 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) /
48 samples_per_sec)),
49 100.0 - (100.0 * ((samples_per_sec - us_samples_per_sec) /
50 samples_per_sec)),
51 100.0 - (100.0 * ((samples_per_sec -
52 guest_kernel_samples_per_sec) /
53 samples_per_sec)),
54 100.0 - (100.0 * ((samples_per_sec -
55 guest_us_samples_per_sec) /
56 samples_per_sec)),
57 esamples_percent);
58 }
59
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -030060 if (top->evlist->nr_entries == 1) {
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020061 struct perf_evsel *first;
62 first = list_entry(top->evlist->entries.next, struct perf_evsel, node);
Jiri Olsab9a46bb2011-03-07 21:13:40 +010063 ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020064 (uint64_t)first->attr.sample_period,
65 top->freq ? "Hz" : "");
66 }
67
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -030068 ret += SNPRINTF(bf + ret, size - ret, "%s", event_name(top->sym_evsel));
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020069
Jiri Olsab9a46bb2011-03-07 21:13:40 +010070 ret += SNPRINTF(bf + ret, size - ret, "], ");
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020071
72 if (top->target_pid != -1)
Jiri Olsab9a46bb2011-03-07 21:13:40 +010073 ret += SNPRINTF(bf + ret, size - ret, " (target_pid: %d",
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020074 top->target_pid);
75 else if (top->target_tid != -1)
Jiri Olsab9a46bb2011-03-07 21:13:40 +010076 ret += SNPRINTF(bf + ret, size - ret, " (target_tid: %d",
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020077 top->target_tid);
78 else
Jiri Olsab9a46bb2011-03-07 21:13:40 +010079 ret += SNPRINTF(bf + ret, size - ret, " (all");
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020080
81 if (top->cpu_list)
Jiri Olsab9a46bb2011-03-07 21:13:40 +010082 ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)",
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020083 top->evlist->cpus->nr > 1 ? "s" : "", top->cpu_list);
84 else {
85 if (top->target_tid != -1)
Jiri Olsab9a46bb2011-03-07 21:13:40 +010086 ret += SNPRINTF(bf + ret, size - ret, ")");
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020087 else
Jiri Olsab9a46bb2011-03-07 21:13:40 +010088 ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)",
Arnaldo Carvalho de Melo8c3e10e2011-01-31 14:50:39 -020089 top->evlist->cpus->nr,
90 top->evlist->cpus->nr > 1 ? "s" : "");
91 }
92
93 return ret;
94}
95
96void perf_top__reset_sample_counters(struct perf_top *top)
97{
98 top->samples = top->us_samples = top->kernel_samples =
99 top->exact_samples = top->guest_kernel_samples =
100 top->guest_us_samples = 0;
101}