Skip to contentSkip to conversation

perf sort: Add 'addr' sort key

PATCH In review Namhyung Kim 3 participants 6 messages Mar 26, 2013 – Mar 27, 2013 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/3 perf sort: Add 'addr' sort key

From: Namhyung Kim <[email protected]>

New addr sort key provides a way to sort the entries by the symbol addresses.

---
 tools/perf/util/hist.c |  2 ++
 tools/perf/util/hist.h |  1 +
 tools/perf/util/sort.c | 23 +++++++++++++++++++++++
 tools/perf/util/sort.h |  1 +
 4 files changed, 27 insertions(+)
tools/perf/util/hist.c +2 -0
index f855941bebea..82b7542db904 100644
@@ -52,6 +52,8 @@ void hists__reset_col_len(struct hists *hists)
 
 	for (col = 0; col < HISTC_NR_COLS; ++col)
 		hists__set_col_len(hists, col, 0);
+
+	hists__set_col_len(hists, HISTC_ADDR, BITS_PER_LONG / 4 + 2);
 }
 
 static void hists__set_unres_dso_col_len(struct hists *hists, int dso)
tools/perf/util/hist.h +1 -0
index 848331377bdb..72c75bef0c68 100644
@@ -49,6 +49,7 @@ enum hist_column {
 	HISTC_DSO_FROM,
 	HISTC_DSO_TO,
 	HISTC_SRCLINE,
+	HISTC_ADDR,
 	HISTC_NR_COLS, /* Last entry */
 };
 
tools/perf/util/sort.c +23 -0
index d41926cb9e3f..27e55562cbbb 100644
@@ -334,6 +334,28 @@ struct sort_entry sort_cpu = {
 	.se_width_idx	= HISTC_CPU,
 };
 
+/* --sort addr */
+
+static int64_t
+sort__addr_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	return right->ip - left->ip;
+}
+
+static int hist_entry__addr_snprintf(struct hist_entry *self, char *bf,
+				     size_t size, unsigned int width)
+{
+	return repsep_snprintf(bf, size, "%#*"PRIx64, width, (uint64_t)self->ip);
+}
+
+struct sort_entry sort_addr = {
+	.se_header      = "Address",
+	.se_cmp	        = sort__addr_cmp,
+	.se_snprintf    = hist_entry__addr_snprintf,
+	.se_width_idx	= HISTC_ADDR,
+};
+
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -480,6 +502,7 @@ static struct sort_dimension common_sort_dimensions[] = {
 	DIM(SORT_PARENT, "parent", sort_parent),
 	DIM(SORT_CPU, "cpu", sort_cpu),
 	DIM(SORT_SRCLINE, "srcline", sort_srcline),
+	DIM(SORT_ADDR, "addr", sort_addr),
 };
 
 #undef DIM
tools/perf/util/sort.h +1 -0
index b13e56f6ccbe..a24dba16cc8f 100644
@@ -130,6 +130,7 @@ enum sort_type {
 	SORT_PARENT,
 	SORT_CPU,
 	SORT_SRCLINE,
+	SORT_ADDR,
 
 	/* branch stack specific sort keys */
 	__SORT_BRANCH_STACK,
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH 2/3 perf sort: Add 'addr_to/from' sort key

From: Namhyung Kim <[email protected]>

New addr_{to,from} sort keys provide a way to sort the entries by the source/target symbol addresses.

Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c |  2 ++
 tools/perf/util/hist.h |  2 ++
 tools/perf/util/sort.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/sort.h |  2 ++
 4 files changed, 56 insertions(+)
tools/perf/util/hist.c +2 -0
index 82b7542db904..b951f4101d7e 100644
@@ -54,6 +54,8 @@ void hists__reset_col_len(struct hists *hists)
 		hists__set_col_len(hists, col, 0);
 
 	hists__set_col_len(hists, HISTC_ADDR, BITS_PER_LONG / 4 + 2);
+	hists__set_col_len(hists, HISTC_ADDR_FROM, BITS_PER_LONG / 4 + 2);
+	hists__set_col_len(hists, HISTC_ADDR_TO, BITS_PER_LONG / 4 + 2);
 }
 
 static void hists__set_unres_dso_col_len(struct hists *hists, int dso)
tools/perf/util/hist.h +2 -0
index 72c75bef0c68..ad1462c87918 100644
@@ -50,6 +50,8 @@ enum hist_column {
 	HISTC_DSO_TO,
 	HISTC_SRCLINE,
 	HISTC_ADDR,
+	HISTC_ADDR_FROM,
+	HISTC_ADDR_TO,
 	HISTC_NR_COLS, /* Last entry */
 };
 
tools/perf/util/sort.c +50 -0

68 lines not on this page · raw message

tools/perf/util/sort.h +2 -0
index a24dba16cc8f..1c049cf58f34 100644
@@ -138,6 +138,8 @@ enum sort_type {
 	SORT_DSO_TO,
 	SORT_SYM_FROM,
 	SORT_SYM_TO,
+	SORT_ADDR_FROM,
+	SORT_ADDR_TO,
 	SORT_MISPREDICT,
 };
 
Signature · 1 line
1.7.11.7
author maintainer
#2 lore raw

PATCH 3/3 perf report: Fix alignment of symbol column when -v is given

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

When -v option is given, the symbol sort key prints its address also but it wasn't properly aligned since hists__calc_col_len() misses the additional part. Also it missed 2 spaces for 0x prefix when printing.

  $ perf report --stdio -v -s sym
  # Samples: 133  of event 'cycles'
  # Event count (approx.): 50536717
  #
  # Overhead                          Symbol
  # ........  ..............................
  #
      12.20%  0xffffffff81384c50 v [k] intel_idle
       7.62%  0xffffffff8170976a v [k] ftrace_caller
       7.02%  0x2d986d         B [.] 0x00000000002d986d
---
 tools/perf/util/hist.c | 20 +++++++++++++++++---
 tools/perf/util/sort.c |  2 +-
 2 files changed, 18 insertions(+), 4 deletions(-)
tools/perf/util/hist.c +17 -3
index b951f4101d7e..7d4bb1f515d1 100644
@@ -73,8 +73,17 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 	const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
 	u16 len;
 
-	if (h->ms.sym)
-		hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4);
+	if (h->ms.sym) {
+		/*
+		 * +4 accounts for '[x] ' priv level info
+		 * +2 accounts for 0x prefix on raw addresses
+		 * +3 accounts for ' y ' symtab origin info
+		 */
+		len = h->ms.sym->namelen + 4;
+		if (verbose)
+			len += BITS_PER_LONG / 4 + 2 + 3;
+		hists__new_col_len(hists, HISTC_SYMBOL, len);
+	}
 	else
 		hists__set_unres_dso_col_len(hists, HISTC_DSO);
 
@@ -94,10 +103,13 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		int symlen;
 		/*
 		 * +4 accounts for '[x] ' priv level info
-		 * +2 account of 0x prefix on raw addresses
+		 * +2 accounts for 0x prefix on raw addresses
+		 * +3 accounts for ' y ' symtab origin info
 		 */
 		if (h->branch_info->from.sym) {
 			symlen = (int)h->branch_info->from.sym->namelen + 4;
+			if (verbose)
+				symlen += BITS_PER_LONG / 4 + 2 + 3;
 			hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
 
 			symlen = dso__name_len(h->branch_info->from.map->dso);
@@ -110,6 +122,8 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 
 		if (h->branch_info->to.sym) {
 			symlen = (int)h->branch_info->to.sym->namelen + 4;
+			if (verbose)
+				symlen += BITS_PER_LONG / 4 + 2 + 3;
 			hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
 
 			symlen = dso__name_len(h->branch_info->to.map->dso);
tools/perf/util/sort.c +1 -1
index 988d7ea3ecc2..5df020f3f59b 100644
@@ -194,7 +194,7 @@ static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
 	if (verbose) {
 		char o = map ? dso__symtab_origin(map->dso) : '!';
 		ret += repsep_snprintf(bf, size, "%-#*llx %c ",
-				       BITS_PER_LONG / 4, ip, o);
+				       BITS_PER_LONG / 4 + 2, ip, o);
 	}
 
 	ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level);
Signature · 1 line
1.7.11.7
#3 lore raw
In reply to Namhyung Kim
Quoted 4 lines · Namhyung Kim

From: Namhyung Kim <[email protected]>

New addr sort key provides a way to sort the entries by the symbol addresses.

No objections from me - just wondering about the motivation: why would we want to sort by symbol address?

Perhaps to see the overhead layout/distribution within a DSO, to better cache-pack hot functions by placing them next to each other?

Putting a short usecase into the changelog (or even better, the documentation) would be nice.

Thanks,

Ingo

author maintainer
#4 lore raw

Hi Ingo,

Quoted 9 lines · Ingo Molnar
Quoted 4 lines · Namhyung Kim

From: Namhyung Kim <[email protected]>

New addr sort key provides a way to sort the entries by the symbol addresses.

No objections from me - just wondering about the motivation: why would we want to sort by symbol address?

In fact, it came from bugzilla:

https://bugzilla.kernel.org/show_bug.cgi?id=55561

Quoted 6 lines

Perhaps to see the overhead layout/distribution within a DSO, to better cache-pack hot functions by placing them next to each other?

Putting a short usecase into the changelog (or even better, the documentation) would be nice.

Well, I didn't thought it much, but yeah, aforementioned usecase looks promising. Also it might be useful to find out which part is the hotpath in a function if you have some really big functions (possibly due to auto-inlining or something).

Arnaldo, do you have other usecase/scenario in mind?

Thanks,
Namhyung

#5 lore raw

Em Wed, Mar 27, 2013 at 03:12:34PM +0900, Namhyung Kim escreveu:

Quoted 11 lines · Ingo Molnar
Quoted 6 lines · Namhyung Kim
Quoted 2 lines

New addr sort key provides a way to sort the entries by the symbol addresses.

No objections from me - just wondering about the motivation: why would we want to sort by symbol address?

In fact, it came from bugzilla:

https://bugzilla.kernel.org/show_bug.cgi?id=55561

Will Cohen asked if this was possible while trying to figure out why some libxul.so samples were not being resolved to symbols, Will?

Namhyung, I'm using:

Just before the: Link: entry, consider adding it when addressing some bugzilla entry, be it from bugzilla.kernel.org or from some other bugzilla where problems or feature requests were made.

- Arnaldo

Quoted 7 lines
Quoted 6 lines

Perhaps to see the overhead layout/distribution within a DSO, to better cache-pack hot functions by placing them next to each other?

Putting a short usecase into the changelog (or even better, the documentation) would be nice.

Quoted 6 lines

Well, I didn't thought it much, but yeah, aforementioned usecase looks promising. Also it might be useful to find out which part is the hotpath in a function if you have some really big functions (possibly due to auto-inlining or something).

Arnaldo, do you have other usecase/scenario in mind?

See above.