Skip to content

Commit da06d56

Browse files
He Kuangacmel
authored andcommitted
perf top: Fix wrong hottest instruction highlighted
The annotation line percentage is compared and inserted into the rbtree, but the percent field of 'struct annotation_data' is an array, the comparison result between them is the address difference. This patch compares the right slot of percent array according to opts->percent_type and makes things right. The problem can be reproduced by pressing 'H' in perf top annotation view. It should highlight the instruction line which has the highest sampling percentage. Signed-off-by: He Kuang <hekuang@huawei.com> Reviewed-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20190120160523.4391-1-hekuang@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 1497e80 commit da06d56

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,24 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser)
224224
return ret;
225225
}
226226

227-
static int disasm__cmp(struct annotation_line *a, struct annotation_line *b)
227+
static double disasm__cmp(struct annotation_line *a, struct annotation_line *b,
228+
int percent_type)
228229
{
229230
int i;
230231

231232
for (i = 0; i < a->data_nr; i++) {
232-
if (a->data[i].percent == b->data[i].percent)
233+
if (a->data[i].percent[percent_type] == b->data[i].percent[percent_type])
233234
continue;
234-
return a->data[i].percent < b->data[i].percent;
235+
return a->data[i].percent[percent_type] -
236+
b->data[i].percent[percent_type];
235237
}
236238
return 0;
237239
}
238240

239-
static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line *al)
241+
static void disasm_rb_tree__insert(struct annotate_browser *browser,
242+
struct annotation_line *al)
240243
{
244+
struct rb_root *root = &browser->entries;
241245
struct rb_node **p = &root->rb_node;
242246
struct rb_node *parent = NULL;
243247
struct annotation_line *l;
@@ -246,7 +250,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line
246250
parent = *p;
247251
l = rb_entry(parent, struct annotation_line, rb_node);
248252

249-
if (disasm__cmp(al, l))
253+
if (disasm__cmp(al, l, browser->opts->percent_type) < 0)
250254
p = &(*p)->rb_left;
251255
else
252256
p = &(*p)->rb_right;
@@ -329,7 +333,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
329333
RB_CLEAR_NODE(&pos->al.rb_node);
330334
continue;
331335
}
332-
disasm_rb_tree__insert(&browser->entries, &pos->al);
336+
disasm_rb_tree__insert(browser, &pos->al);
333337
}
334338
pthread_mutex_unlock(&notes->lock);
335339

0 commit comments

Comments
 (0)