Skip to content

Commit e2c1c8f

Browse files
namhyungacmel
authored andcommitted
perf report: Add 'symoff' sort key
The symoff sort key is to print symbol and offset of sample. This is useful for data type profiling to show exact instruction in the function which refers the data. $ perf report -s type,sym,typeoff,symoff --hierarchy ... # Overhead Data Type / Symbol / Data Type Offset / Symbol Offset # .............. ..................................................... # 1.23% struct cfs_rq 0.84% update_blocked_averages 0.19% struct cfs_rq +336 (leaf_cfs_rq_list.next) 0.19% [k] update_blocked_averages+0x96 0.19% struct cfs_rq +0 (load.weight) 0.14% [k] update_blocked_averages+0x104 0.04% [k] update_blocked_averages+0x31c 0.17% struct cfs_rq +404 (throttle_count) 0.12% [k] update_blocked_averages+0x9d 0.05% [k] update_blocked_averages+0x1f9 0.08% struct cfs_rq +272 (propagate) 0.07% [k] update_blocked_averages+0x3d3 0.02% [k] update_blocked_averages+0x45b ... Committer testing: # perf report --stdio -s type,typeoff,symoff # To display the perf.data header info, please use --header/--header-only options. # # # Total Lost Samples: 0 # # Samples: 4 of event 'cpu_atom/mem-loads,ldlat=30/P' # Event count (approx.): 7 # # Overhead Data Type Data Type Offset Symbol Offset # ........ ......... ................ ............. # 42.86% struct list_head struct list_head +8 (prev) [k] __list_del_entry_valid_or_report+0x7 28.57% (unknown) (unknown) +0 (no field) [.] _nl_intern_locale_data+0x25 14.29% char char +0 (no field) [k] strncpy_from_user+0xa5 14.29% (unknown) (unknown) +0 (no field) [.] _dl_lookup_symbol_x+0x50 # # (Tip: To change sampling frequency to 100 Hz: perf record -F 100) # Signed-off-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 871304a commit e2c1c8f

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

tools/perf/Documentation/perf-report.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ OPTIONS
120120
- simd: Flags describing a SIMD operation. "e" for empty Arm SVE predicate. "p" for partial Arm SVE predicate
121121
- type: Data type of sample memory access.
122122
- typeoff: Offset in the data type of sample memory access.
123+
- symoff: Offset in the symbol.
123124

124125
By default, comm, dso and symbol keys are used.
125126
(i.e. --sort comm,dso,symbol)

tools/perf/util/hist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ enum hist_column {
8484
HISTC_SIMD,
8585
HISTC_TYPE,
8686
HISTC_TYPE_OFFSET,
87+
HISTC_SYMBOL_OFFSET,
8788
HISTC_NR_COLS, /* Last entry */
8889
};
8990

tools/perf/util/sort.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,52 @@ struct sort_entry sort_sym = {
419419
.se_width_idx = HISTC_SYMBOL,
420420
};
421421

422+
/* --sort symoff */
423+
424+
static int64_t
425+
sort__symoff_cmp(struct hist_entry *left, struct hist_entry *right)
426+
{
427+
int64_t ret;
428+
429+
ret = sort__sym_cmp(left, right);
430+
if (ret)
431+
return ret;
432+
433+
return left->ip - right->ip;
434+
}
435+
436+
static int64_t
437+
sort__symoff_sort(struct hist_entry *left, struct hist_entry *right)
438+
{
439+
int64_t ret;
440+
441+
ret = sort__sym_sort(left, right);
442+
if (ret)
443+
return ret;
444+
445+
return left->ip - right->ip;
446+
}
447+
448+
static int
449+
hist_entry__symoff_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width)
450+
{
451+
struct symbol *sym = he->ms.sym;
452+
453+
if (sym == NULL)
454+
return repsep_snprintf(bf, size, "[%c] %-#.*llx", he->level, width - 4, he->ip);
455+
456+
return repsep_snprintf(bf, size, "[%c] %s+0x%llx", he->level, sym->name, he->ip - sym->start);
457+
}
458+
459+
struct sort_entry sort_sym_offset = {
460+
.se_header = "Symbol Offset",
461+
.se_cmp = sort__symoff_cmp,
462+
.se_sort = sort__symoff_sort,
463+
.se_snprintf = hist_entry__symoff_snprintf,
464+
.se_filter = hist_entry__sym_filter,
465+
.se_width_idx = HISTC_SYMBOL_OFFSET,
466+
};
467+
422468
/* --sort srcline */
423469

424470
char *hist_entry__srcline(struct hist_entry *he)
@@ -2335,6 +2381,7 @@ static struct sort_dimension common_sort_dimensions[] = {
23352381
DIM(SORT_SIMD, "simd", sort_simd),
23362382
DIM(SORT_ANNOTATE_DATA_TYPE, "type", sort_type),
23372383
DIM(SORT_ANNOTATE_DATA_TYPE_OFFSET, "typeoff", sort_type_offset),
2384+
DIM(SORT_SYM_OFFSET, "symoff", sort_sym_offset),
23382385
};
23392386

23402387
#undef DIM

tools/perf/util/sort.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ enum sort_type {
249249
SORT_SIMD,
250250
SORT_ANNOTATE_DATA_TYPE,
251251
SORT_ANNOTATE_DATA_TYPE_OFFSET,
252+
SORT_SYM_OFFSET,
252253

253254
/* branch stack specific sort keys */
254255
__SORT_BRANCH_STACK,

0 commit comments

Comments
 (0)