linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf top: Fix wrong hottest instruction highlighted
@ 2019-01-20 16:05 He Kuang
  2019-01-20 18:40 ` Jiri Olsa
  2019-01-22 11:37 ` [tip:perf/urgent] " tip-bot for He Kuang
  0 siblings, 2 replies; 4+ messages in thread
From: He Kuang @ 2019-01-20 16:05 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, hekuang

Annotation line's percentage is compared and inserted into 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>
---
 tools/perf/ui/browsers/annotate.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 1d00e5ec7906..82e16bf84466 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -224,20 +224,24 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser)
 	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;
 
 	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;
-		return a->data[i].percent < b->data[i].percent;
+		return a->data[i].percent[percent_type] -
+			   b->data[i].percent[percent_type];
 	}
 	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 *parent = NULL;
 	struct annotation_line *l;
@@ -246,7 +250,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line
 		parent = *p;
 		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;
 		else
 			p = &(*p)->rb_right;
@@ -329,7 +333,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 			RB_CLEAR_NODE(&pos->al.rb_node);
 			continue;
 		}
-		disasm_rb_tree__insert(&browser->entries, &pos->al);
+		disasm_rb_tree__insert(browser, &pos->al);
 	}
 	pthread_mutex_unlock(&notes->lock);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf top: Fix wrong hottest instruction highlighted
  2019-01-20 16:05 [PATCH] perf top: Fix wrong hottest instruction highlighted He Kuang
@ 2019-01-20 18:40 ` Jiri Olsa
  2019-01-21 14:10   ` Arnaldo Carvalho de Melo
  2019-01-22 11:37 ` [tip:perf/urgent] " tip-bot for He Kuang
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2019-01-20 18:40 UTC (permalink / raw)
  To: He Kuang; +Cc: peterz, mingo, acme, alexander.shishkin, namhyung, linux-kernel

On Mon, Jan 21, 2019 at 12:05:22AM +0800, He Kuang wrote:
> Annotation line's percentage is compared and inserted into 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>

thanks,
jirka

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf top: Fix wrong hottest instruction highlighted
  2019-01-20 18:40 ` Jiri Olsa
@ 2019-01-21 14:10   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-01-21 14:10 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: He Kuang, peterz, mingo, alexander.shishkin, namhyung, linux-kernel

Em Sun, Jan 20, 2019 at 07:40:43PM +0100, Jiri Olsa escreveu:
> On Mon, Jan 21, 2019 at 12:05:22AM +0800, He Kuang wrote:
> > Annotation line's percentage is compared and inserted into 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>

Thanks, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:perf/urgent] perf top: Fix wrong hottest instruction highlighted
  2019-01-20 16:05 [PATCH] perf top: Fix wrong hottest instruction highlighted He Kuang
  2019-01-20 18:40 ` Jiri Olsa
@ 2019-01-22 11:37 ` tip-bot for He Kuang
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for He Kuang @ 2019-01-22 11:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, jolsa, namhyung, mingo, acme, tglx,
	linux-kernel, hpa, hekuang, peterz

Commit-ID:  da06d568386877809532e8ec678f4a5e300f0951
Gitweb:     https://git.kernel.org/tip/da06d568386877809532e8ec678f4a5e300f0951
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Mon, 21 Jan 2019 00:05:22 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 21 Jan 2019 11:29:07 -0300

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>
---
 tools/perf/ui/browsers/annotate.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 1d00e5ec7906..82e16bf84466 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -224,20 +224,24 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser)
 	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;
 
 	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;
-		return a->data[i].percent < b->data[i].percent;
+		return a->data[i].percent[percent_type] -
+			   b->data[i].percent[percent_type];
 	}
 	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 *parent = NULL;
 	struct annotation_line *l;
@@ -246,7 +250,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line
 		parent = *p;
 		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;
 		else
 			p = &(*p)->rb_right;
@@ -329,7 +333,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 			RB_CLEAR_NODE(&pos->al.rb_node);
 			continue;
 		}
-		disasm_rb_tree__insert(&browser->entries, &pos->al);
+		disasm_rb_tree__insert(browser, &pos->al);
 	}
 	pthread_mutex_unlock(&notes->lock);
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-22 11:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-20 16:05 [PATCH] perf top: Fix wrong hottest instruction highlighted He Kuang
2019-01-20 18:40 ` Jiri Olsa
2019-01-21 14:10   ` Arnaldo Carvalho de Melo
2019-01-22 11:37 ` [tip:perf/urgent] " tip-bot for He Kuang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).