Commit da06d568 authored by He Kuang's avatar He Kuang Committed by Arnaldo Carvalho de Melo

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: default avatarHe Kuang <hekuang@huawei.com>
Reviewed-by: default avatarJiri 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 1497e804
...@@ -224,20 +224,24 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser) ...@@ -224,20 +224,24 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser)
return ret; return ret;
} }
static int disasm__cmp(struct annotation_line *a, struct annotation_line *b) static double disasm__cmp(struct annotation_line *a, struct annotation_line *b,
int percent_type)
{ {
int i; int i;
for (i = 0; i < a->data_nr; i++) { for (i = 0; i < a->data_nr; i++) {
if (a->data[i].percent == b->data[i].percent) if (a->data[i].percent[percent_type] == b->data[i].percent[percent_type])
continue; continue;
return a->data[i].percent < b->data[i].percent; return a->data[i].percent[percent_type] -
b->data[i].percent[percent_type];
} }
return 0; return 0;
} }
static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line *al) static void disasm_rb_tree__insert(struct annotate_browser *browser,
struct annotation_line *al)
{ {
struct rb_root *root = &browser->entries;
struct rb_node **p = &root->rb_node; struct rb_node **p = &root->rb_node;
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
struct annotation_line *l; struct annotation_line *l;
...@@ -246,7 +250,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line ...@@ -246,7 +250,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line
parent = *p; parent = *p;
l = rb_entry(parent, struct annotation_line, rb_node); l = rb_entry(parent, struct annotation_line, rb_node);
if (disasm__cmp(al, l)) if (disasm__cmp(al, l, browser->opts->percent_type) < 0)
p = &(*p)->rb_left; p = &(*p)->rb_left;
else else
p = &(*p)->rb_right; p = &(*p)->rb_right;
...@@ -329,7 +333,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, ...@@ -329,7 +333,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
RB_CLEAR_NODE(&pos->al.rb_node); RB_CLEAR_NODE(&pos->al.rb_node);
continue; continue;
} }
disasm_rb_tree__insert(&browser->entries, &pos->al); disasm_rb_tree__insert(browser, &pos->al);
} }
pthread_mutex_unlock(&notes->lock); pthread_mutex_unlock(&notes->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment