Skip to content

Commit 2f2c41b

Browse files
namhyungacmel
authored andcommitted
perf report: Add 'type' sort key
The 'type' sort key is to aggregate hist entries by data type they access. Add mem_type field to hist_entry struct to save the type. If hist_entry__get_data_type() returns NULL, it'd use the 'unknown_type' instance. Committer testing: Before: # perf mem record sleep 2s [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.037 MB perf.data (4 samples) ] root@number:/home/acme/Downloads# perf report --stdio -s type Error: Unknown --sort key: `type' Usage: perf report [<options>] -s, --sort <key[,key2...]> sort by key(s): overhead overhead_sys overhead_us overhead_guest_sys overhead_guest_us overhead_children sample period pid comm dso symbol parent cpu socket srcline srcfile local_weight weight transaction trace symbol_size dso_size cgroup cgroup_id ipc_null time code_page_size local_ins_lat ins_lat local_p_stage_cyc p_stage_cyc addr local_retire_lat retire_lat simd dso_from dso_to symbol_from symbol_to mispredict abort in_tx cycles srcline_from srcline_to ipc_lbr addr_from addr_to symbol_daddr dso_daddr locked tlb mem snoop dcacheline symbol_iaddr phys_daddr data_page_size blocked # After: # perf report --stdio -s type # 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 # ........ ......... # 100.00% (unknown) # # (Tip: Print event counts in CSV format with: perf stat -x,) # # rpm -q kernel-debuginfo kernel-debuginfo-6.6.4-200.fc39.x86_64 # uname -r 6.6.4-200.fc39.x86_64 # Signed-off-by: Namhyung Kim <namhyung@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: linux-toolchains@vger.kernel.org> Cc: linux-trace-devel@vger.kernel.org> Link: https://lore.kernel.org/r/20231213001323.718046-9-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 67bc54b commit 2f2c41b

5 files changed

Lines changed: 75 additions & 2 deletions

File tree

tools/perf/Documentation/perf-report.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ OPTIONS
118118
- retire_lat: On X86, this reports pipeline stall of this instruction compared
119119
to the previous instruction in cycles. And currently supported only on X86
120120
- simd: Flags describing a SIMD operation. "e" for empty Arm SVE predicate. "p" for partial Arm SVE predicate
121+
- type: Data type of sample memory access.
121122

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

tools/perf/util/annotate-data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct annotated_data_type {
2222
int type_size;
2323
};
2424

25+
extern struct annotated_data_type unknown_type;
26+
2527
#ifdef HAVE_DWARF_SUPPORT
2628

2729
/* Returns data type at the location (ip, reg, offset) */

tools/perf/util/hist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ enum hist_column {
8282
HISTC_ADDR_TO,
8383
HISTC_ADDR,
8484
HISTC_SIMD,
85+
HISTC_TYPE,
8586
HISTC_NR_COLS, /* Last entry */
8687
};
8788

tools/perf/util/sort.c

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "strbuf.h"
2525
#include "mem-events.h"
2626
#include "annotate.h"
27+
#include "annotate-data.h"
2728
#include "event.h"
2829
#include "time-utils.h"
2930
#include "cgroup.h"
@@ -2094,7 +2095,7 @@ struct sort_entry sort_dso_size = {
20942095
.se_width_idx = HISTC_DSO_SIZE,
20952096
};
20962097

2097-
/* --sort dso_size */
2098+
/* --sort addr */
20982099

20992100
static int64_t
21002101
sort__addr_cmp(struct hist_entry *left, struct hist_entry *right)
@@ -2131,6 +2132,69 @@ struct sort_entry sort_addr = {
21312132
.se_width_idx = HISTC_ADDR,
21322133
};
21332134

2135+
/* --sort type */
2136+
2137+
struct annotated_data_type unknown_type = {
2138+
.type_name = (char *)"(unknown)",
2139+
};
2140+
2141+
static int64_t
2142+
sort__type_cmp(struct hist_entry *left, struct hist_entry *right)
2143+
{
2144+
return sort__addr_cmp(left, right);
2145+
}
2146+
2147+
static void sort__type_init(struct hist_entry *he)
2148+
{
2149+
if (he->mem_type)
2150+
return;
2151+
2152+
he->mem_type = hist_entry__get_data_type(he);
2153+
if (he->mem_type == NULL)
2154+
he->mem_type = &unknown_type;
2155+
}
2156+
2157+
static int64_t
2158+
sort__type_collapse(struct hist_entry *left, struct hist_entry *right)
2159+
{
2160+
struct annotated_data_type *left_type = left->mem_type;
2161+
struct annotated_data_type *right_type = right->mem_type;
2162+
2163+
if (!left_type) {
2164+
sort__type_init(left);
2165+
left_type = left->mem_type;
2166+
}
2167+
2168+
if (!right_type) {
2169+
sort__type_init(right);
2170+
right_type = right->mem_type;
2171+
}
2172+
2173+
return strcmp(left_type->type_name, right_type->type_name);
2174+
}
2175+
2176+
static int64_t
2177+
sort__type_sort(struct hist_entry *left, struct hist_entry *right)
2178+
{
2179+
return sort__type_collapse(left, right);
2180+
}
2181+
2182+
static int hist_entry__type_snprintf(struct hist_entry *he, char *bf,
2183+
size_t size, unsigned int width)
2184+
{
2185+
return repsep_snprintf(bf, size, "%-*s", width, he->mem_type->type_name);
2186+
}
2187+
2188+
struct sort_entry sort_type = {
2189+
.se_header = "Data Type",
2190+
.se_cmp = sort__type_cmp,
2191+
.se_collapse = sort__type_collapse,
2192+
.se_sort = sort__type_sort,
2193+
.se_init = sort__type_init,
2194+
.se_snprintf = hist_entry__type_snprintf,
2195+
.se_width_idx = HISTC_TYPE,
2196+
};
2197+
21342198

21352199
struct sort_dimension {
21362200
const char *name;
@@ -2185,7 +2249,8 @@ static struct sort_dimension common_sort_dimensions[] = {
21852249
DIM(SORT_ADDR, "addr", sort_addr),
21862250
DIM(SORT_LOCAL_RETIRE_LAT, "local_retire_lat", sort_local_p_stage_cyc),
21872251
DIM(SORT_GLOBAL_RETIRE_LAT, "retire_lat", sort_global_p_stage_cyc),
2188-
DIM(SORT_SIMD, "simd", sort_simd)
2252+
DIM(SORT_SIMD, "simd", sort_simd),
2253+
DIM(SORT_ANNOTATE_DATA_TYPE, "type", sort_type),
21892254
};
21902255

21912256
#undef DIM

tools/perf/util/sort.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
struct option;
1717
struct thread;
18+
struct annotated_data_type;
1819

1920
extern regex_t parent_regex;
2021
extern const char *sort_order;
@@ -34,6 +35,7 @@ extern struct sort_entry sort_dso_to;
3435
extern struct sort_entry sort_sym_from;
3536
extern struct sort_entry sort_sym_to;
3637
extern struct sort_entry sort_srcline;
38+
extern struct sort_entry sort_type;
3739
extern const char default_mem_sort_order[];
3840
extern bool chk_double_cl;
3941

@@ -154,6 +156,7 @@ struct hist_entry {
154156
struct perf_hpp_list *hpp_list;
155157
struct hist_entry *parent_he;
156158
struct hist_entry_ops *ops;
159+
struct annotated_data_type *mem_type;
157160
union {
158161
/* this is for hierarchical entry structure */
159162
struct {
@@ -243,6 +246,7 @@ enum sort_type {
243246
SORT_LOCAL_RETIRE_LAT,
244247
SORT_GLOBAL_RETIRE_LAT,
245248
SORT_SIMD,
249+
SORT_ANNOTATE_DATA_TYPE,
246250

247251
/* branch stack specific sort keys */
248252
__SORT_BRANCH_STACK,

0 commit comments

Comments
 (0)