Skip to content

Commit f381081

Browse files
Jin Yaoacmel
authored andcommitted
perf diff: Link same basic blocks among different data
The target is to compare the performance difference (cycles diff) for the same basic blocks in different data files. The same basic block means same function, same start address and same end address. This patch finds the same basic blocks from different data files and link them together and resort by the cycles diff. v3: --- The block stuffs are maintained by new structure 'block_hist', so this patch is update accordingly. v2: --- Since now the basic block hists is changed to per symbol, the patch only links the basic block hists for the same symbol in different data files. 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://lkml.kernel.org/r/1561713784-30533-6-git-send-email-yao.jin@linux.intel.com [ sym->name is an array, not a pointer, so no need to check it for NULL, fixes de build in some distros ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 99150a1 commit f381081

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

‎tools/perf/builtin-diff.c‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,82 @@ static int process_block_per_sym(struct hist_entry *he)
641641
return 0;
642642
}
643643

644+
static int block_pair_cmp(struct hist_entry *a, struct hist_entry *b)
645+
{
646+
struct block_info *bi_a = a->block_info;
647+
struct block_info *bi_b = b->block_info;
648+
int cmp;
649+
650+
if (!bi_a->sym || !bi_b->sym)
651+
return -1;
652+
653+
cmp = strcmp(bi_a->sym->name, bi_b->sym->name);
654+
655+
if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end))
656+
return 0;
657+
658+
return -1;
659+
}
660+
661+
static struct hist_entry *get_block_pair(struct hist_entry *he,
662+
struct hists *hists_pair)
663+
{
664+
struct rb_root_cached *root = hists_pair->entries_in;
665+
struct rb_node *next = rb_first_cached(root);
666+
int cmp;
667+
668+
while (next != NULL) {
669+
struct hist_entry *he_pair = rb_entry(next, struct hist_entry,
670+
rb_node_in);
671+
672+
next = rb_next(&he_pair->rb_node_in);
673+
674+
cmp = block_pair_cmp(he_pair, he);
675+
if (!cmp)
676+
return he_pair;
677+
}
678+
679+
return NULL;
680+
}
681+
682+
static void compute_cycles_diff(struct hist_entry *he,
683+
struct hist_entry *pair)
684+
{
685+
pair->diff.computed = true;
686+
if (pair->block_info->num && he->block_info->num) {
687+
pair->diff.cycles =
688+
pair->block_info->cycles_aggr / pair->block_info->num_aggr -
689+
he->block_info->cycles_aggr / he->block_info->num_aggr;
690+
}
691+
}
692+
693+
static void block_hists_match(struct hists *hists_base,
694+
struct hists *hists_pair)
695+
{
696+
struct rb_root_cached *root = hists_base->entries_in;
697+
struct rb_node *next = rb_first_cached(root);
698+
699+
while (next != NULL) {
700+
struct hist_entry *he = rb_entry(next, struct hist_entry,
701+
rb_node_in);
702+
struct hist_entry *pair = get_block_pair(he, hists_pair);
703+
704+
next = rb_next(&he->rb_node_in);
705+
706+
if (pair) {
707+
hist_entry__add_pair(pair, he);
708+
compute_cycles_diff(he, pair);
709+
}
710+
}
711+
}
712+
713+
static int filter_cb(struct hist_entry *he, void *arg __maybe_unused)
714+
{
715+
/* Skip the calculation of column length in output_resort */
716+
he->filtered = true;
717+
return 0;
718+
}
719+
644720
static void hists__precompute(struct hists *hists)
645721
{
646722
struct rb_root_cached *root;
@@ -653,6 +729,7 @@ static void hists__precompute(struct hists *hists)
653729

654730
next = rb_first_cached(root);
655731
while (next != NULL) {
732+
struct block_hist *bh, *pair_bh;
656733
struct hist_entry *he, *pair;
657734
struct data__file *d;
658735
int i;
@@ -681,6 +758,16 @@ static void hists__precompute(struct hists *hists)
681758
break;
682759
case COMPUTE_CYCLES:
683760
process_block_per_sym(pair);
761+
bh = container_of(he, struct block_hist, he);
762+
pair_bh = container_of(pair, struct block_hist,
763+
he);
764+
765+
if (bh->valid && pair_bh->valid) {
766+
block_hists_match(&bh->block_hists,
767+
&pair_bh->block_hists);
768+
hists__output_resort_cb(&pair_bh->block_hists,
769+
NULL, filter_cb);
770+
}
684771
break;
685772
default:
686773
BUG_ON(1);

0 commit comments

Comments
 (0)