perf hist: Count the total cycles of all samples
authorJin Yao <yao.jin@linux.intel.com>
Thu, 7 Nov 2019 07:47:15 +0000 (15:47 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 7 Nov 2019 12:14:15 +0000 (09:14 -0300)
We can get the per sample cycles by hist__account_cycles(). It's also
useful to know the total cycles of all samples in order to get the
cycles coverage for a single program block in further. For example:

  coverage = per block sampled cycles / total sampled cycles

This patch creates a new argument 'total_cycles' in hist__account_cycles(),
which will be added with the cycles of each sample.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20191107074719.26139-4-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-annotate.c
tools/perf/builtin-diff.c
tools/perf/builtin-report.c
tools/perf/builtin-top.c
tools/perf/util/hist.c
tools/perf/util/hist.h

index 8db8fc9bddef3b9cd820f0daf233675c4b065b38..6ab0cc45b287f9318ec7202f292cf331e60a3510 100644 (file)
@@ -201,7 +201,7 @@ static int process_branch_callback(struct evsel *evsel,
        if (a.map != NULL)
                a.map->dso->hit = 1;
 
-       hist__account_cycles(sample->branch_stack, al, sample, false);
+       hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
        ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
        return ret;
index 6728568fe5c4f6c366bf752dd66d3f9fba97747c..376dbf10ad6490d84763d63e3700f90437a81832 100644 (file)
@@ -426,7 +426,8 @@ static int diff__process_sample_event(struct perf_tool *tool,
                        goto out_put;
                }
 
-               hist__account_cycles(sample->branch_stack, &al, sample, false);
+               hist__account_cycles(sample->branch_stack, &al, sample, false,
+                                    NULL);
        }
 
        /*
index 3bbad039abf2ef6b6d0eb581e492e0a82daeb467..bc15b9dcccd6ae26401160afc214ca30911659fe 100644 (file)
@@ -292,7 +292,7 @@ static int process_sample_event(struct perf_tool *tool,
 
        if (ui__has_annotation() || rep->symbol_ipc) {
                hist__account_cycles(sample->branch_stack, &al, sample,
-                                    rep->nonany_branch_mode);
+                                    rep->nonany_branch_mode, NULL);
        }
 
        ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
index d96f24c8770d9dfc14fc7d34961eb62fcd34c712..14c52e4d47f63b05fc8689fc05e1c1359965aa1e 100644 (file)
@@ -725,7 +725,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,
                perf_top__record_precise_ip(top, he, iter->sample, evsel, al->addr);
 
        hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
-                    !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
+                    !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY),
+                    NULL);
        return 0;
 }
 
index a7fa061987e48de57a43780b95a1dc311e95d1d1..0e27d68300119719c01c96c2600b9724dfbfb509 100644 (file)
@@ -2572,7 +2572,8 @@ int hists__unlink(struct hists *hists)
 }
 
 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
-                         struct perf_sample *sample, bool nonany_branch_mode)
+                         struct perf_sample *sample, bool nonany_branch_mode,
+                         u64 *total_cycles)
 {
        struct branch_info *bi;
 
@@ -2599,6 +2600,9 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
                                        nonany_branch_mode ? NULL : prev,
                                        bi[i].flags.cycles);
                                prev = &bi[i].to;
+
+                               if (total_cycles)
+                                       *total_cycles += bi[i].flags.cycles;
                        }
                        free(bi);
                }
index 6a186b6683033838157c6dd9bd588b57c21814b4..4d87c7b4c1b263bb5550e77092b19457ccbee676 100644 (file)
@@ -527,7 +527,8 @@ unsigned int hists__sort_list_width(struct hists *hists);
 unsigned int hists__overhead_width(struct hists *hists);
 
 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
-                         struct perf_sample *sample, bool nonany_branch_mode);
+                         struct perf_sample *sample, bool nonany_branch_mode,
+                         u64 *total_cycles);
 
 struct option;
 int parse_filter_percentage(const struct option *opt, const char *arg, int unset);