Skip to content

Commit cca0cc7

Browse files
Jin Yaoacmel
authored andcommitted
perf block-info: Allow selecting which columns to report and its order
Currently we use a predefined array to set the block info output formats, it's fixed and inflexible. This patch adds two parameters "block_hpps" and "nr_hpps" in block_info__create_report and other static functions, in order to let user decide which columns to report and with specified report ordering. It should be more flexible. Buffers will be allocated to contain the new fmts, of course, we need to release them before perf exits. Signed-off-by: Jin Yao <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a8a9f6d commit cca0cc7

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

tools/perf/builtin-report.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct report {
104104
bool symbol_ipc;
105105
bool total_cycles_mode;
106106
struct block_report *block_reports;
107+
int nr_block_reports;
107108
};
108109

109110
static int report__config(const char *var, const char *value, void *cb)
@@ -966,8 +967,19 @@ static int __cmd_report(struct report *rep)
966967
report__output_resort(rep);
967968

968969
if (rep->total_cycles_mode) {
970+
int block_hpps[6] = {
971+
PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT,
972+
PERF_HPP_REPORT__BLOCK_LBR_CYCLES,
973+
PERF_HPP_REPORT__BLOCK_CYCLES_PCT,
974+
PERF_HPP_REPORT__BLOCK_AVG_CYCLES,
975+
PERF_HPP_REPORT__BLOCK_RANGE,
976+
PERF_HPP_REPORT__BLOCK_DSO,
977+
};
978+
969979
rep->block_reports = block_info__create_report(session->evlist,
970-
rep->total_cycles);
980+
rep->total_cycles,
981+
block_hpps, 6,
982+
&rep->nr_block_reports);
971983
if (!rep->block_reports)
972984
return -1;
973985
}
@@ -1551,8 +1563,11 @@ int cmd_report(int argc, const char **argv)
15511563
zfree(&report.ptime_range);
15521564
}
15531565

1554-
if (report.block_reports)
1555-
zfree(&report.block_reports);
1566+
if (report.block_reports) {
1567+
block_info__free_report(report.block_reports,
1568+
report.nr_block_reports);
1569+
report.block_reports = NULL;
1570+
}
15561571

15571572
zstd_fini(&(session->zstd_data));
15581573
perf_session__delete(session);

tools/perf/util/block-info.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,33 +373,41 @@ static void hpp_register(struct block_fmt *block_fmt, int idx,
373373
}
374374

375375
static void register_block_columns(struct perf_hpp_list *hpp_list,
376-
struct block_fmt *block_fmts)
376+
struct block_fmt *block_fmts,
377+
int *block_hpps, int nr_hpps)
377378
{
378-
for (int i = 0; i < PERF_HPP_REPORT__BLOCK_MAX_INDEX; i++)
379-
hpp_register(&block_fmts[i], i, hpp_list);
379+
for (int i = 0; i < nr_hpps; i++)
380+
hpp_register(&block_fmts[i], block_hpps[i], hpp_list);
380381
}
381382

382-
static void init_block_hist(struct block_hist *bh, struct block_fmt *block_fmts)
383+
static void init_block_hist(struct block_hist *bh, struct block_fmt *block_fmts,
384+
int *block_hpps, int nr_hpps)
383385
{
384386
__hists__init(&bh->block_hists, &bh->block_list);
385387
perf_hpp_list__init(&bh->block_list);
386388
bh->block_list.nr_header_lines = 1;
387389

388-
register_block_columns(&bh->block_list, block_fmts);
390+
register_block_columns(&bh->block_list, block_fmts,
391+
block_hpps, nr_hpps);
389392

390-
perf_hpp_list__register_sort_field(&bh->block_list,
391-
&block_fmts[PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT].fmt);
393+
/* Sort by the first fmt */
394+
perf_hpp_list__register_sort_field(&bh->block_list, &block_fmts[0].fmt);
392395
}
393396

394-
static void process_block_report(struct hists *hists,
395-
struct block_report *block_report,
396-
u64 total_cycles)
397+
static int process_block_report(struct hists *hists,
398+
struct block_report *block_report,
399+
u64 total_cycles, int *block_hpps,
400+
int nr_hpps)
397401
{
398402
struct rb_node *next = rb_first_cached(&hists->entries);
399403
struct block_hist *bh = &block_report->hist;
400404
struct hist_entry *he;
401405

402-
init_block_hist(bh, block_report->fmts);
406+
if (nr_hpps > PERF_HPP_REPORT__BLOCK_MAX_INDEX)
407+
return -1;
408+
409+
block_report->nr_fmts = nr_hpps;
410+
init_block_hist(bh, block_report->fmts, block_hpps, nr_hpps);
403411

404412
while (next) {
405413
he = rb_entry(next, struct hist_entry, rb_node);
@@ -408,16 +416,19 @@ static void process_block_report(struct hists *hists,
408416
next = rb_next(&he->rb_node);
409417
}
410418

411-
for (int i = 0; i < PERF_HPP_REPORT__BLOCK_MAX_INDEX; i++) {
419+
for (int i = 0; i < nr_hpps; i++) {
412420
block_report->fmts[i].total_cycles = total_cycles;
413421
block_report->fmts[i].block_cycles = block_report->cycles;
414422
}
415423

416424
hists__output_resort(&bh->block_hists, NULL);
425+
return 0;
417426
}
418427

419428
struct block_report *block_info__create_report(struct evlist *evlist,
420-
u64 total_cycles)
429+
u64 total_cycles,
430+
int *block_hpps, int nr_hpps,
431+
int *nr_reps)
421432
{
422433
struct block_report *block_reports;
423434
int nr_hists = evlist->core.nr_entries, i = 0;
@@ -430,13 +441,23 @@ struct block_report *block_info__create_report(struct evlist *evlist,
430441
evlist__for_each_entry(evlist, pos) {
431442
struct hists *hists = evsel__hists(pos);
432443

433-
process_block_report(hists, &block_reports[i], total_cycles);
444+
process_block_report(hists, &block_reports[i], total_cycles,
445+
block_hpps, nr_hpps);
434446
i++;
435447
}
436448

449+
*nr_reps = nr_hists;
437450
return block_reports;
438451
}
439452

453+
void block_info__free_report(struct block_report *reps, int nr_reps)
454+
{
455+
for (int i = 0; i < nr_reps; i++)
456+
hists__delete_entries(&reps[i].hist.block_hists);
457+
458+
free(reps);
459+
}
460+
440461
int report__browse_block_hists(struct block_hist *bh, float min_percent,
441462
struct evsel *evsel, struct perf_env *env,
442463
struct annotation_options *annotation_opts)
@@ -448,13 +469,11 @@ int report__browse_block_hists(struct block_hist *bh, float min_percent,
448469
symbol_conf.report_individual_block = true;
449470
hists__fprintf(&bh->block_hists, true, 0, 0, min_percent,
450471
stdout, true);
451-
hists__delete_entries(&bh->block_hists);
452472
return 0;
453473
case 1:
454474
symbol_conf.report_individual_block = true;
455475
ret = block_hists_tui_browse(bh, evsel, min_percent,
456476
env, annotation_opts);
457-
hists__delete_entries(&bh->block_hists);
458477
return ret;
459478
default:
460479
return -1;

tools/perf/util/block-info.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct block_report {
4545
struct block_hist hist;
4646
u64 cycles;
4747
struct block_fmt fmts[PERF_HPP_REPORT__BLOCK_MAX_INDEX];
48+
int nr_fmts;
4849
};
4950

5051
struct block_hist;
@@ -70,7 +71,11 @@ int block_info__process_sym(struct hist_entry *he, struct block_hist *bh,
7071
u64 *block_cycles_aggr, u64 total_cycles);
7172

7273
struct block_report *block_info__create_report(struct evlist *evlist,
73-
u64 total_cycles);
74+
u64 total_cycles,
75+
int *block_hpps, int nr_hpps,
76+
int *nr_reps);
77+
78+
void block_info__free_report(struct block_report *reps, int nr_reps);
7479

7580
int report__browse_block_hists(struct block_hist *bh, float min_percent,
7681
struct evsel *evsel, struct perf_env *env,

0 commit comments

Comments
 (0)