diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-04-03 14:19:47 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-04-03 14:22:55 -0400 |
commit | b213eac245aa2d29a3b9dd90f3b96ab182337ee8 (patch) | |
tree | b448fa46d69a64d6ff809a58eb95fdf000f3f48e | |
parent | ef9ff6017e3c4593f3efa5776784cb417c58ad6c (diff) |
perf annotate: Introduce annotation__scnprintf_samples_period() method
To print a string using the total period (nr_events) and the number of
samples for a given annotation, i.e. for a given symbol, the counterpart
to hists__scnprintf_samples_period(), that is for all the samples in a
session (be it a live session, think 'perf top' or a perf.data file,
think 'perf report').
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Martin Liška <mliska@suse.cz>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=196935
Link: https://lkml.kernel.org/n/tip-goj2wu4fxutc8vd46mw3yg14@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/annotate.c | 38 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 12 |
2 files changed, 50 insertions, 0 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3a428d7c59b9..b956bb7eabcf 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "config.h" | 17 | #include "config.h" |
18 | #include "cache.h" | 18 | #include "cache.h" |
19 | #include "symbol.h" | 19 | #include "symbol.h" |
20 | #include "units.h" | ||
20 | #include "debug.h" | 21 | #include "debug.h" |
21 | #include "annotate.h" | 22 | #include "annotate.h" |
22 | #include "evsel.h" | 23 | #include "evsel.h" |
@@ -2597,6 +2598,43 @@ out_free_offsets: | |||
2597 | return -1; | 2598 | return -1; |
2598 | } | 2599 | } |
2599 | 2600 | ||
2601 | int __annotation__scnprintf_samples_period(struct annotation *notes, | ||
2602 | char *bf, size_t size, | ||
2603 | struct perf_evsel *evsel, | ||
2604 | bool show_freq) | ||
2605 | { | ||
2606 | const char *ev_name = perf_evsel__name(evsel); | ||
2607 | char ref[30] = " show reference callgraph, "; | ||
2608 | char sample_freq_str[64] = ""; | ||
2609 | unsigned long nr_samples = 0; | ||
2610 | int nr_members = 1; | ||
2611 | bool enable_ref = false; | ||
2612 | u64 nr_events = 0; | ||
2613 | char unit; | ||
2614 | int i; | ||
2615 | |||
2616 | if (perf_evsel__is_group_event(evsel)) | ||
2617 | nr_members = evsel->nr_members; | ||
2618 | |||
2619 | for (i = 0; i < nr_members; i++) { | ||
2620 | struct sym_hist *ah = annotation__histogram(notes, evsel->idx + i); | ||
2621 | |||
2622 | nr_samples += ah->nr_samples; | ||
2623 | nr_events += ah->period; | ||
2624 | } | ||
2625 | |||
2626 | if (symbol_conf.show_ref_callgraph && strstr(ev_name, "call-graph=no")) | ||
2627 | enable_ref = true; | ||
2628 | |||
2629 | if (show_freq) | ||
2630 | scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq); | ||
2631 | |||
2632 | nr_samples = convert_unit(nr_samples, &unit); | ||
2633 | return scnprintf(bf, size, "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64, | ||
2634 | nr_samples, unit, evsel->nr_members > 1 ? "s" : "", | ||
2635 | ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events); | ||
2636 | } | ||
2637 | |||
2600 | #define ANNOTATION__CFG(n) \ | 2638 | #define ANNOTATION__CFG(n) \ |
2601 | { .name = #n, .value = &annotation__default_options.n, } | 2639 | { .name = #n, .value = &annotation__default_options.n, } |
2602 | 2640 | ||
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index ff7e3df31efa..db8d09bea07e 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -151,6 +151,18 @@ double annotation_line__max_percent(struct annotation_line *al, struct annotatio | |||
151 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, | 151 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, |
152 | struct annotation_write_ops *ops); | 152 | struct annotation_write_ops *ops); |
153 | 153 | ||
154 | int __annotation__scnprintf_samples_period(struct annotation *notes, | ||
155 | char *bf, size_t size, | ||
156 | struct perf_evsel *evsel, | ||
157 | bool show_freq); | ||
158 | |||
159 | static inline int annotation__scnprintf_samples_period(struct annotation *notes, | ||
160 | char *bf, size_t size, | ||
161 | struct perf_evsel *evsel) | ||
162 | { | ||
163 | return __annotation__scnprintf_samples_period(notes, bf, size, evsel, true); | ||
164 | } | ||
165 | |||
154 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); | 166 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
155 | size_t disasm__fprintf(struct list_head *head, FILE *fp); | 167 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |
156 | void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); | 168 | void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); |