Skip to contentSkip to conversation

perf annotate-data: Show offset and size in hex

PATCH In review Namhyung Kim 2 participants 4 messages Aug 19, 2024 – Aug 21, 2024 1 message not in the archive perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/2 perf annotate-data: Show offset and size in hex

It'd be better to have them in hex to check cacheline alignment.

Percent offset size field

  100.00          0      0x1c0  struct cfs_rq    {
    0.00          0       0x10      struct load_weight  load {
    0.00          0        0x8          long unsigned int       weight;
    0.00        0x8        0x4          u32     inv_weight;
                                    };
    0.00       0x10        0x4      unsigned int        nr_running;
   14.56       0x14        0x4      unsigned int        h_nr_running;
    0.00       0x18        0x4      unsigned int        idle_nr_running;
    0.00       0x1c        0x4      unsigned int        idle_h_nr_running;

...

---
 tools/perf/ui/browsers/annotate-data.c | 4 ++--
 tools/perf/util/annotate-data.c        | 2 +-
 tools/perf/util/sort.c                 | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/ui/browsers/annotate-data.c +2 -2
index f563a3bb072c..cd562a8822b7 100644
@@ -427,12 +427,12 @@ static void browser__write(struct ui_browser *uib, void *entry, int row)
 
 	/* print type info */
 	if (be->indent == 0 && !member->var_name) {
-		ui_browser__printf(uib, " %10d %10d  %s%s",
+		ui_browser__printf(uib, " %#10x %#10x  %s%s",
 				   member->offset, member->size,
 				   member->type_name,
 				   list_empty(&member->children) || be->folded? ";" : " {");
 	} else {
-		ui_browser__printf(uib, " %10d %10d  %*s%s\t%s%s",
+		ui_browser__printf(uib, " %#10x %#10x  %*s%s\t%s%s",
 				   member->offset, member->size,
 				   be->indent * 4, "", member->type_name,
 				   member->var_name ?: "",
tools/perf/util/annotate-data.c +1 -1
index aa330c7d8edd..25105b3b9a13 100644
@@ -1660,7 +1660,7 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type,
 		nr_events++;
 	}
 
-	printf(" %10d %10d  %*s%s\t%s",
+	printf(" %#10x %#10x  %*s%s\t%s",
 	       member->offset, member->size, indent, "", member->type_name,
 	       member->var_name ?: "");
 
tools/perf/util/sort.c +1 -1
index c4046d5d1749..d315308f9170 100644
@@ -2312,7 +2312,7 @@ static int hist_entry__typeoff_snprintf(struct hist_entry *he, char *bf,
 				 he->mem_type_off, true);
 	buf[4095] = '\0';
 
-	return repsep_snprintf(bf, size, "%s %+d (%s)", he_type->self.type_name,
+	return repsep_snprintf(bf, size, "%s +%#x (%s)", he_type->self.type_name,
 			       he->mem_type_off, buf);
 }
 
Signature · 1 line
2.46.0.184.g6999bdac58-goog
author maintainer
#1 lore raw

PATCH 2/2 perf annotate-data: Add 'typecln' sort key

Sometimes it's useful to organize member fields in cache-line boundary. The 'typecln' sort key is short for type-cacheline and to show samples in each cacheline. The cacheline size is fixed to 64 for now, but it can read the actual size once it saves the value from sysfs.

For example, you maybe want to which cacheline in a target is hot or cold. The following shows members in the cfs_rq's first cache line.

  $ perf report -s type,typecln,typeoff -H
  ...
  -    2.67%        struct cfs_rq
     +    1.23%        struct cfs_rq: cache-line 2
     +    0.57%        struct cfs_rq: cache-line 4
     +    0.46%        struct cfs_rq: cache-line 6
     -    0.41%        struct cfs_rq: cache-line 0
             0.39%        struct cfs_rq +0x14 (h_nr_running)
             0.02%        struct cfs_rq +0x38 (tasks_timeline.rb_leftmost)
  ...
---
 tools/perf/util/hist.h |  1 +
 tools/perf/util/sort.c | 52 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/sort.h |  1 +
 3 files changed, 54 insertions(+)
tools/perf/util/hist.h +1 -0
index 30c13fc8cbe4..deb1087c5948 100644
@@ -86,6 +86,7 @@ enum hist_column {
 	HISTC_TYPE,
 	HISTC_TYPE_OFFSET,
 	HISTC_SYMBOL_OFFSET,
+	HISTC_TYPE_CACHELINE,
 	HISTC_NR_COLS, /* Last entry */
 };
 
tools/perf/util/sort.c +52 -0

64 lines not on this page · raw message

tools/perf/util/sort.h +1 -0
index 6357bc32c5ca..9ff68c6786e7 100644
@@ -71,6 +71,7 @@ enum sort_type {
 	SORT_ANNOTATE_DATA_TYPE,
 	SORT_ANNOTATE_DATA_TYPE_OFFSET,
 	SORT_SYM_OFFSET,
+	SORT_ANNOTATE_DATA_TYPE_CACHELINE,
 
 	/* branch stack specific sort keys */
 	__SORT_BRANCH_STACK,
Signature · 1 line
2.46.0.184.g6999bdac58-goog

A message that is not in the archive (sent off-list or not yet received): CA+JHD93fa33YL_AHL9RfxUOoBm+hw8zHbk13BU4qD8B3p4KHug@mail.gmail.com

author maintainer
#3 lore raw
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 4 lines · Namhyung Kim

It'd be better to have them in hex to check cacheline alignment.

Why is it better? To compare with the usual output of some other tool?

Spelling out reasons helps reviewers/users.

Cache line sizes are power of 2 so it'd be natural to use hex and check whether an offset is in the same boundary. Also perf annotate shows instruction offsets in hex.

Quoted 2 lines

Maybe this should be selectable?

I can add an option and/or a config if you want.

Thanks,
Namhyung

Quoted 71 lines
Quoted 71 lines

Percent offset size field

  100.00          0      0x1c0  struct cfs_rq    {
    0.00          0       0x10      struct load_weight  load {
    0.00          0        0x8          long unsigned int       weight;
    0.00        0x8        0x4          u32     inv_weight;
                                    };
    0.00       0x10        0x4      unsigned int        nr_running;
   14.56       0x14        0x4      unsigned int        h_nr_running;
    0.00       0x18        0x4      unsigned int        idle_nr_running;
    0.00       0x1c        0x4      unsigned int        idle_h_nr_running;

...

---
 tools/perf/ui/browsers/annotate-data.c | 4 ++--
 tools/perf/util/annotate-data.c        | 2 +-
 tools/perf/util/sort.c                 | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/ui/browsers/annotate-data.c +2 -2
index f563a3bb072c..cd562a8822b7 100644
@@ -427,12 +427,12 @@ static void browser__write(struct ui_browser *uib, void *entry, int row)
 
        /* print type info */
        if (be->indent == 0 && !member->var_name) {
-               ui_browser__printf(uib, " %10d %10d  %s%s",
+               ui_browser__printf(uib, " %#10x %#10x  %s%s",
                                   member->offset, member->size,
                                   member->type_name,
                                   list_empty(&member->children) || be->folded? ";" : " {");
        } else {
-               ui_browser__printf(uib, " %10d %10d  %*s%s\t%s%s",
+               ui_browser__printf(uib, " %#10x %#10x  %*s%s\t%s%s",
                                   member->offset, member->size,
                                   be->indent * 4, "", member->type_name,
                                   member->var_name ?: "",
tools/perf/util/annotate-data.c +1 -1
index aa330c7d8edd..25105b3b9a13 100644
@@ -1660,7 +1660,7 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type,
                nr_events++;
        }
 
-       printf(" %10d %10d  %*s%s\t%s",
+       printf(" %#10x %#10x  %*s%s\t%s",
               member->offset, member->size, indent, "", member->type_name,
               member->var_name ?: "");
 
tools/perf/util/sort.c +1 -2
index c4046d5d1749..d315308f9170 100644
@@ -2312,7 +2312,7 @@ static int hist_entry__typeoff_snprintf(struct hist_entry *he, char *bf,
                                 he->mem_type_off, true);
        buf[4095] = '\0';
 
-       return repsep_snprintf(bf, size, "%s %+d (%s)", he_type->self.type_name,
+       return repsep_snprintf(bf, size, "%s +%#x (%s)", he_type->self.type_name,
                               he->mem_type_off, buf);
 }
 
--

2.46.0.184.g6999bdac58-goog

#4 lore raw
Quoted 14 lines · Namhyung Kim
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 4 lines · Namhyung Kim

It'd be better to have them in hex to check cacheline alignment.

Why is it better? To compare with the usual output of some other tool?

Spelling out reasons helps reviewers/users.

Quoted 8 lines

Cache line sizes are power of 2 so it'd be natural to use hex and check whether an offset is in the same boundary. Also perf annotate shows instruction offsets in hex.

Quoted 2 lines

Maybe this should be selectable?

I can add an option and/or a config if you want.

It would be interesting to have, but I'm merging the patches to make progress...

- Arnaldo