Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add 'addr' sort key

Sometimes users want to see actual (virtual) address of sampled instructions.
Add a new 'addr' sort key to display the raw addresses.

$ perf record -o- true | perf report -i- -s addr
# To display the perf.data header info, please use --header/--header-only options.
#
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]
#
# Total Lost Samples: 0
#
# Samples: 12 of event 'cycles:u'
# Event count (approx.): 252512
#
# Overhead Address
# ........ ..................
#
42.96% 0x7f96f08443d7
29.55% 0x7f96f0859b50
14.76% 0x7f96f0852e02
8.30% 0x7f96f0855028
4.43% 0xffffffff8de01087

Note that it just compares and displays the sample ip. Each process can
have a different memory layout and the ip will be different even if they run
the same binary. So this sort key is mostly meaningful for per-process
profile data.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20220923173142.805896-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
762461f1 fd941521

+43 -1
+2 -1
tools/perf/Documentation/perf-report.txt
··· 73 73 Sort histogram entries by given key(s) - multiple keys can be specified 74 74 in CSV format. Following sort keys are available: 75 75 pid, comm, dso, symbol, parent, cpu, socket, srcline, weight, 76 - local_weight, cgroup_id. 76 + local_weight, cgroup_id, addr. 77 77 78 78 Each key has following meaning: 79 79 ··· 114 114 - local_ins_lat: Local instruction latency version 115 115 - p_stage_cyc: On powerpc, this presents the number of cycles spent in a 116 116 pipeline stage. And currently supported only on powerpc. 117 + - addr: (Full) virtual address of the sampled instruction 117 118 118 119 By default, comm, dso and symbol keys are used. 119 120 (i.e. --sort comm,dso,symbol)
+1
tools/perf/util/hist.c
··· 215 215 hists__new_col_len(hists, HISTC_GLOBAL_INS_LAT, 13); 216 216 hists__new_col_len(hists, HISTC_LOCAL_P_STAGE_CYC, 13); 217 217 hists__new_col_len(hists, HISTC_GLOBAL_P_STAGE_CYC, 13); 218 + hists__new_col_len(hists, HISTC_ADDR, BITS_PER_LONG / 4 + 2); 218 219 219 220 if (symbol_conf.nanosecs) 220 221 hists__new_col_len(hists, HISTC_TIME, 16);
+1
tools/perf/util/hist.h
··· 79 79 HISTC_GLOBAL_P_STAGE_CYC, 80 80 HISTC_ADDR_FROM, 81 81 HISTC_ADDR_TO, 82 + HISTC_ADDR, 82 83 HISTC_NR_COLS, /* Last entry */ 83 84 }; 84 85
+38
tools/perf/util/sort.c
··· 1948 1948 .se_width_idx = HISTC_DSO_SIZE, 1949 1949 }; 1950 1950 1951 + /* --sort dso_size */ 1952 + 1953 + static int64_t 1954 + sort__addr_cmp(struct hist_entry *left, struct hist_entry *right) 1955 + { 1956 + u64 left_ip = left->ip; 1957 + u64 right_ip = right->ip; 1958 + struct map *left_map = left->ms.map; 1959 + struct map *right_map = right->ms.map; 1960 + 1961 + if (left_map) 1962 + left_ip = left_map->unmap_ip(left_map, left_ip); 1963 + if (right_map) 1964 + right_ip = right_map->unmap_ip(right_map, right_ip); 1965 + 1966 + return _sort__addr_cmp(left_ip, right_ip); 1967 + } 1968 + 1969 + static int hist_entry__addr_snprintf(struct hist_entry *he, char *bf, 1970 + size_t size, unsigned int width) 1971 + { 1972 + u64 ip = he->ip; 1973 + struct map *map = he->ms.map; 1974 + 1975 + if (map) 1976 + ip = map->unmap_ip(map, ip); 1977 + 1978 + return repsep_snprintf(bf, size, "%-#*llx", width, ip); 1979 + } 1980 + 1981 + struct sort_entry sort_addr = { 1982 + .se_header = "Address", 1983 + .se_cmp = sort__addr_cmp, 1984 + .se_snprintf = hist_entry__addr_snprintf, 1985 + .se_width_idx = HISTC_ADDR, 1986 + }; 1987 + 1951 1988 1952 1989 struct sort_dimension { 1953 1990 const char *name; ··· 2034 1997 DIM(SORT_GLOBAL_INS_LAT, "ins_lat", sort_global_ins_lat), 2035 1998 DIM(SORT_LOCAL_PIPELINE_STAGE_CYC, "local_p_stage_cyc", sort_local_p_stage_cyc), 2036 1999 DIM(SORT_GLOBAL_PIPELINE_STAGE_CYC, "p_stage_cyc", sort_global_p_stage_cyc), 2000 + DIM(SORT_ADDR, "addr", sort_addr), 2037 2001 }; 2038 2002 2039 2003 #undef DIM
+1
tools/perf/util/sort.h
··· 236 236 SORT_GLOBAL_INS_LAT, 237 237 SORT_LOCAL_PIPELINE_STAGE_CYC, 238 238 SORT_GLOBAL_PIPELINE_STAGE_CYC, 239 + SORT_ADDR, 239 240 240 241 /* branch stack specific sort keys */ 241 242 __SORT_BRANCH_STACK,