Skip to content

Commit 7841f40

Browse files
Jin Yaoacmel
authored andcommitted
perf hist: Count the total cycles of all samples
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>
1 parent 6041441 commit 7841f40

6 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎tools/perf/builtin-annotate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int process_branch_callback(struct evsel *evsel,
201201
if (a.map != NULL)
202202
a.map->dso->hit = 1;
203203

204-
hist__account_cycles(sample->branch_stack, al, sample, false);
204+
hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
205205

206206
ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
207207
return ret;

‎tools/perf/builtin-diff.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ static int diff__process_sample_event(struct perf_tool *tool,
426426
goto out_put;
427427
}
428428

429-
hist__account_cycles(sample->branch_stack, &al, sample, false);
429+
hist__account_cycles(sample->branch_stack, &al, sample, false,
430+
NULL);
430431
}
431432

432433
/*

‎tools/perf/builtin-report.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int process_sample_event(struct perf_tool *tool,
292292

293293
if (ui__has_annotation() || rep->symbol_ipc) {
294294
hist__account_cycles(sample->branch_stack, &al, sample,
295-
rep->nonany_branch_mode);
295+
rep->nonany_branch_mode, NULL);
296296
}
297297

298298
ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);

‎tools/perf/builtin-top.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,
725725
perf_top__record_precise_ip(top, he, iter->sample, evsel, al->addr);
726726

727727
hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
728-
!(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
728+
!(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY),
729+
NULL);
729730
return 0;
730731
}
731732

‎tools/perf/util/hist.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,8 @@ int hists__unlink(struct hists *hists)
25722572
}
25732573

25742574
void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
2575-
struct perf_sample *sample, bool nonany_branch_mode)
2575+
struct perf_sample *sample, bool nonany_branch_mode,
2576+
u64 *total_cycles)
25762577
{
25772578
struct branch_info *bi;
25782579

@@ -2599,6 +2600,9 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
25992600
nonany_branch_mode ? NULL : prev,
26002601
bi[i].flags.cycles);
26012602
prev = &bi[i].to;
2603+
2604+
if (total_cycles)
2605+
*total_cycles += bi[i].flags.cycles;
26022606
}
26032607
free(bi);
26042608
}

‎tools/perf/util/hist.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ unsigned int hists__sort_list_width(struct hists *hists);
527527
unsigned int hists__overhead_width(struct hists *hists);
528528

529529
void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
530-
struct perf_sample *sample, bool nonany_branch_mode);
530+
struct perf_sample *sample, bool nonany_branch_mode,
531+
u64 *total_cycles);
531532

532533
struct option;
533534
int parse_filter_percentage(const struct option *opt, const char *arg, int unset);

0 commit comments

Comments
 (0)