linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	David Ahern <dsahern@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Andi Kleen <andi@firstfloor.org>
Subject: Re: [PATCH 35/35] perf annotate: Align source and offset lines
Date: Tue, 7 Nov 2017 11:10:47 -0300	[thread overview]
Message-ID: <20171107141047.GF3216@kernel.org> (raw)
In-Reply-To: <20171011150158.11895-36-jolsa@kernel.org>

Em Wed, Oct 11, 2017 at 05:01:58PM +0200, Jiri Olsa escreveu:
> Aligning source with offset lines, which are more advanced,
> because of the address column.
> 
>   Before:
>          :      static void *worker_thread(void *__tdata)
>          :      {
>     0.00 :        48a971:       push   %rbp
>     0.00 :        48a972:       mov    %rsp,%rbp
>     0.00 :        48a975:       sub    $0x30,%rsp
>     0.00 :        48a979:       mov    %rdi,-0x28(%rbp)
>     0.00 :        48a97d:       mov    %fs:0x28,%rax
>     0.00 :        48a986:       mov    %rax,-0x8(%rbp)
>     0.00 :        48a98a:       xor    %eax,%eax
>          :              struct thread_data *td = __tdata;
>     0.00 :        48a98c:       mov    -0x28(%rbp),%rax
>     0.00 :        48a990:       mov    %rax,-0x10(%rbp)
>          :              int m = 0, i;
>     0.00 :        48a994:       movl   $0x0,-0x1c(%rbp)
>          :              int ret;
>          :
>          :              for (i = 0; i < loops; i++) {
>     0.00 :        48a99b:       movl   $0x0,-0x18(%rbp)
> 
>   After:
>          :              static void *worker_thread(void *__tdata)
>          :              {
>     0.00 :       48a971:       push   %rbp
>     0.00 :       48a972:       mov    %rsp,%rbp
>     0.00 :       48a975:       sub    $0x30,%rsp
>     0.00 :       48a979:       mov    %rdi,-0x28(%rbp)
>     0.00 :       48a97d:       mov    %fs:0x28,%rax
>     0.00 :       48a986:       mov    %rax,-0x8(%rbp)
>     0.00 :       48a98a:       xor    %eax,%eax
>          :                      struct thread_data *td = __tdata;
>     0.00 :       48a98c:       mov    -0x28(%rbp),%rax
>     0.00 :       48a990:       mov    %rax,-0x10(%rbp)
>          :                      int m = 0, i;
>     0.00 :       48a994:       movl   $0x0,-0x1c(%rbp)
>          :                      int ret;
>          :
>          :                      for (i = 0; i < loops; i++) {
>     0.00 :       48a99b:       movl   $0x0,-0x18(%rbp)
> 
> It makes bigger different when displaying script sources,
> where the comment lines looks oddly shifted from the lines
> which actually hold code. I'll send script support separately.
> 
> Link: http://lkml.kernel.org/n/tip-uamk3iiewlii40o4mlog2cpp@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/util/annotate.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 2516e53104be..530961a343fc 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -1082,6 +1082,7 @@ static void annotate__branch_printf(struct block_range *br, u64 addr)
>  	}
>  }
>  
> +#define ADDR_LEN 10

This doesn't align kernel addresses well, as they will take more
columns, so I'm trying the patch below, on top of yours, ok?

I will combine both to elliminate unnecessary churn, ok?

- Arnaldo

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e17e5d6252bc..54321b947de8 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1092,16 +1092,14 @@ static void annotate__branch_printf(struct block_range *br, u64 addr)
 	}
 }
 
-#define ADDR_LEN 10
-
-static int disasm_line__print(struct disasm_line *dl, u64 start)
+static int disasm_line__print(struct disasm_line *dl, u64 start, int addr_fmt_width)
 {
 	s64 offset = dl->al.offset;
 	const u64 addr = start + offset;
 	struct block_range *br;
 
 	br = block_range__find(addr);
-	color_fprintf(stdout, annotate__address_color(br), "  %*" PRIx64 ":", ADDR_LEN, addr);
+	color_fprintf(stdout, annotate__address_color(br), "  %*" PRIx64 ":", addr_fmt_width, addr);
 	color_fprintf(stdout, annotate__asm_color(br), "%s", dl->al.line);
 	annotate__branch_printf(br, addr);
 	return 0;
@@ -1110,7 +1108,7 @@ static int disasm_line__print(struct disasm_line *dl, u64 start)
 static int
 annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start,
 		       struct perf_evsel *evsel, u64 len, int min_pcnt, int printed,
-		       int max_lines, struct annotation_line *queue)
+		       int max_lines, struct annotation_line *queue, int addr_fmt_width)
 {
 	struct disasm_line *dl = container_of(al, struct disasm_line, al);
 	static const char *prev_line;
@@ -1140,7 +1138,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 				if (queue == al)
 					break;
 				annotation_line__print(queue, sym, start, evsel, len,
-						       0, 0, 1, NULL);
+						       0, 0, 1, NULL, addr_fmt_width);
 			}
 		}
 
@@ -1177,7 +1175,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 
 		printf(" : ");
 
-		disasm_line__print(dl, start);
+		disasm_line__print(dl, start, addr_fmt_width);
 		printf("\n");
 	} else if (max_lines && printed >= max_lines)
 		return 1;
@@ -1193,7 +1191,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		if (!*al->line)
 			printf(" %*s:\n", width, " ");
 		else
-			printf(" %*s:     %*s %s\n", width, " ", ADDR_LEN, " ", al->line);
+			printf(" %*s:     %*s %s\n", width, " ", addr_fmt_width, " ", al->line);
 	}
 
 	return 0;
@@ -1800,6 +1798,19 @@ static void symbol__annotate_hits(struct symbol *sym, struct perf_evsel *evsel)
 	printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->nr_samples", h->nr_samples);
 }
 
+static int annotated_source__addr_fmt_width(struct list_head *lines, u64 start)
+{
+	char bf[32];
+	struct annotation_line *line;
+
+	list_for_each_entry_reverse(line, lines, node) {
+		if (line->offset != -1)
+			return scnprintf(bf, sizeof(bf), "%" PRIx64, start + line->offset);
+	}
+
+	return 0;
+}
+
 int symbol__annotate_printf(struct symbol *sym, struct map *map,
 			    struct perf_evsel *evsel, bool full_paths,
 			    int min_pcnt, int max_lines, int context)
@@ -1812,7 +1823,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 	struct sym_hist *h = annotation__histogram(notes, evsel->idx);
 	struct annotation_line *pos, *queue = NULL;
 	u64 start = map__rip_2objdump(map, sym->start);
-	int printed = 2, queue_len = 0;
+	int printed = 2, queue_len = 0, addr_fmt_width;
 	int more = 0;
 	u64 len;
 	int width = symbol_conf.show_total_period ? 12 : 8;
@@ -1843,6 +1854,8 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 	if (verbose > 0)
 		symbol__annotate_hits(sym, evsel);
 
+	addr_fmt_width = annotated_source__addr_fmt_width(&notes->src->source, start);
+
 	list_for_each_entry(pos, &notes->src->source, node) {
 		int err;
 
@@ -1853,7 +1866,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 
 		err = annotation_line__print(pos, sym, start, evsel, len,
 					     min_pcnt, printed, max_lines,
-					     queue);
+					     queue, addr_fmt_width);
 
 		switch (err) {
 		case 0:

  reply	other threads:[~2017-11-07 14:19 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11 15:01 [PATCH 00/35] perf annotate: Use generic annotation line Jiri Olsa
2017-10-11 15:01 ` [PATCH 01/35] perf annotate: Remove arch::cpuid_parse callback Jiri Olsa
2017-10-24 10:14   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 02/35] perf annotate: Add annotation_line struct Jiri Olsa
2017-10-11 15:29   ` Arnaldo Carvalho de Melo
2017-10-11 19:12     ` Jiri Olsa
2017-11-18  8:10   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 03/35] perf annotate: Move line/offset into " Jiri Olsa
2017-11-18  8:11   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 04/35] perf annotate: Move ipc/cycles " Jiri Olsa
2017-11-18  8:11   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 05/35] perf annotate: Add symbol__annotate function Jiri Olsa
2017-11-18  8:12   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 06/35] perf annotate: Add struct annotate_args Jiri Olsa
2017-11-18  8:12   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 07/35] perf annotate: Add arch into " Jiri Olsa
2017-11-18  8:13   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 08/35] perf annotate: Add map " Jiri Olsa
2017-11-18  8:13   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 09/35] perf annotate: Add offset/line/line_nr " Jiri Olsa
2017-11-18  8:13   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 10/35] perf annotate: Add evsel into struct annotation_line_args Jiri Olsa
2017-11-18  8:14   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 11/35] perf annotate: Add annotation_line__next function Jiri Olsa
2017-11-18  8:14   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 12/35] perf annotate: Add annotation_line__add function Jiri Olsa
2017-11-18  8:15   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 13/35] perf annotate: Move rb_node into struct annotation_line Jiri Olsa
2017-11-18  8:15   ` [tip:perf/core] perf annotate: Move rb_node to " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 14/35] perf annotate: Add annotation_line__(new|free) functions Jiri Olsa
2017-11-18  8:15   ` [tip:perf/core] perf annotate: Add annotation_line__(new|delete) functions tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 15/35] perf annotate: Add annotated_source__purge function Jiri Olsa
2017-11-18  8:16   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 16/35] perf annotate: Add samples into struct annotation_line Jiri Olsa
2017-11-13 15:46   ` Ravi Bangoria
2017-11-13 20:14     ` Jiri Olsa
2017-11-14  9:31       ` Jiri Olsa
2017-11-14 10:15         ` Ravi Bangoria
2017-11-14 10:29           ` Jiri Olsa
2017-11-15 14:04             ` Jiri Olsa
2017-11-16  4:27               ` Ravi Bangoria
2017-11-18  8:16   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 17/35] perf annotate: Add symbol__calc_percent function Jiri Olsa
2017-11-18  8:17   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 18/35] perf annotate: Add symbol__calc_lines function Jiri Olsa
2017-11-18  8:17   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 19/35] perf annotate: Remove disasm__calc_percent from disasm_line__print Jiri Olsa
2017-11-18  8:17   ` [tip:perf/core] perf annotate: Remove disasm__calc_percent() from disasm_line__print() tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 20/35] perf annotate: Remove disasm__calc_percent from annotate_browser__calc_percent Jiri Olsa
2017-11-18  8:18   ` [tip:perf/core] perf annotate: Remove disasm__calc_percent() from annotate_browser__calc_percent() tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 21/35] perf annotate: Remove disasm__calc_percent function Jiri Olsa
2017-11-18  8:18   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 22/35] perf annotate: Remove struct source_line Jiri Olsa
2017-11-18  8:19   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 23/35] perf annotate: Add annotation_line__print function Jiri Olsa
2017-11-18  8:19   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 24/35] perf annotate: Factor annotation_line__print from disasm_line__print Jiri Olsa
2017-11-18  8:19   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 25/35] perf annotate browser: Use samples data from struct annotation_line Jiri Olsa
2017-11-18  8:20   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 26/35] perf annotate browser: Do not pass nr_events in disasm_rb_tree__insert Jiri Olsa
2017-11-18  8:20   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 27/35] perf annotate browser: Rename struct browser_disasm_line to browser_line Jiri Olsa
2017-11-06 10:55   ` [PATCHv2 " Jiri Olsa
2017-11-18  8:21     ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 28/35] perf annotate browser: Rename disasm_line__browser " Jiri Olsa
2017-11-06 10:55   ` [PATCHv2 " Jiri Olsa
2017-11-18  8:21     ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 29/35] perf annotate browser: Change selection to struct annotation_line Jiri Olsa
2017-11-06 10:56   ` [PATCHv2 " Jiri Olsa
2017-11-18  8:21     ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 30/35] perf annotate browser: Change offsets " Jiri Olsa
2017-11-18  8:22   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 31/35] perf annotate browser: Use struct annotation_line in browser_line Jiri Olsa
2017-11-18  8:22   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 32/35] perf annotate browser: Use struct annotation_line in find functions Jiri Olsa
2017-11-18  8:23   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 33/35] perf annotate browser: Use struct annotation_line in browser top Jiri Olsa
2017-11-18  8:23   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 34/35] perf annotate browser: Add disasm_line__write function Jiri Olsa
2017-11-18  8:23   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:01 ` [PATCH 35/35] perf annotate: Align source and offset lines Jiri Olsa
2017-11-07 14:10   ` Arnaldo Carvalho de Melo [this message]
2017-11-07 14:50     ` Jiri Olsa
2017-11-18  8:24   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-10-11 15:27 ` [PATCH 00/35] perf annotate: Use generic annotation line Arnaldo Carvalho de Melo
2017-10-11 19:10   ` Jiri Olsa
2017-10-11 19:18     ` Arnaldo Carvalho de Melo
2017-10-11 19:30       ` Jiri Olsa
2017-10-11 19:43         ` Arnaldo Carvalho de Melo
2017-11-02 12:16 ` Jiri Olsa
2017-11-03 16:59   ` Arnaldo Carvalho de Melo
2017-11-04 10:29     ` Jiri Olsa
2017-11-06 10:56       ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171107141047.GF3216@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).