Skip to content

Commit c35aeb9

Browse files
kliang2acmel
authored andcommitted
perf mem: Support physical address
Add option phys-data in "perf mem" to record/report physical address. The default mem sort order for physical address is changed accordingly. Signed-off-by: Kan Liang <[email protected]> Tested-by: Jiri Olsa <[email protected]> Acked-by: Stephane Eranian <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8780fb2 commit c35aeb9

File tree

2 files changed

+75
-26
lines changed

2 files changed

+75
-26
lines changed

tools/perf/Documentation/perf-mem.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ OPTIONS
5959
--ldload::
6060
Specify desired latency for loads event.
6161

62+
-p::
63+
--phys-data::
64+
Record/Report sample physical addresses
65+
6266
SEE ALSO
6367
--------
6468
linkperf:perf-record[1], linkperf:perf-report[1]

tools/perf/builtin-mem.c

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct perf_mem {
2323
bool hide_unresolved;
2424
bool dump_raw;
2525
bool force;
26+
bool phys_addr;
2627
int operation;
2728
const char *cpu_list;
2829
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -101,6 +102,9 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
101102

102103
rec_argv[i++] = "-d";
103104

105+
if (mem->phys_addr)
106+
rec_argv[i++] = "--phys-data";
107+
104108
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
105109
if (!perf_mem_events[j].record)
106110
continue;
@@ -161,30 +165,60 @@ dump_raw_samples(struct perf_tool *tool,
161165
if (al.map != NULL)
162166
al.map->dso->hit = 1;
163167

164-
if (symbol_conf.field_sep) {
165-
fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s%"PRIu64
166-
"%s0x%"PRIx64"%s%s:%s\n";
168+
if (mem->phys_addr) {
169+
if (symbol_conf.field_sep) {
170+
fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s0x%016"PRIx64
171+
"%s%"PRIu64"%s0x%"PRIx64"%s%s:%s\n";
172+
} else {
173+
fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64
174+
"%s0x%016"PRIx64"%s%5"PRIu64"%s0x%06"PRIx64
175+
"%s%s:%s\n";
176+
symbol_conf.field_sep = " ";
177+
}
178+
179+
printf(fmt,
180+
sample->pid,
181+
symbol_conf.field_sep,
182+
sample->tid,
183+
symbol_conf.field_sep,
184+
sample->ip,
185+
symbol_conf.field_sep,
186+
sample->addr,
187+
symbol_conf.field_sep,
188+
sample->phys_addr,
189+
symbol_conf.field_sep,
190+
sample->weight,
191+
symbol_conf.field_sep,
192+
sample->data_src,
193+
symbol_conf.field_sep,
194+
al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
195+
al.sym ? al.sym->name : "???");
167196
} else {
168-
fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64
169-
"%s%5"PRIu64"%s0x%06"PRIx64"%s%s:%s\n";
170-
symbol_conf.field_sep = " ";
171-
}
197+
if (symbol_conf.field_sep) {
198+
fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s%"PRIu64
199+
"%s0x%"PRIx64"%s%s:%s\n";
200+
} else {
201+
fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64
202+
"%s%5"PRIu64"%s0x%06"PRIx64"%s%s:%s\n";
203+
symbol_conf.field_sep = " ";
204+
}
172205

173-
printf(fmt,
174-
sample->pid,
175-
symbol_conf.field_sep,
176-
sample->tid,
177-
symbol_conf.field_sep,
178-
sample->ip,
179-
symbol_conf.field_sep,
180-
sample->addr,
181-
symbol_conf.field_sep,
182-
sample->weight,
183-
symbol_conf.field_sep,
184-
sample->data_src,
185-
symbol_conf.field_sep,
186-
al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
187-
al.sym ? al.sym->name : "???");
206+
printf(fmt,
207+
sample->pid,
208+
symbol_conf.field_sep,
209+
sample->tid,
210+
symbol_conf.field_sep,
211+
sample->ip,
212+
symbol_conf.field_sep,
213+
sample->addr,
214+
symbol_conf.field_sep,
215+
sample->weight,
216+
symbol_conf.field_sep,
217+
sample->data_src,
218+
symbol_conf.field_sep,
219+
al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
220+
al.sym ? al.sym->name : "???");
221+
}
188222
out_put:
189223
addr_location__put(&al);
190224
return 0;
@@ -224,7 +258,10 @@ static int report_raw_events(struct perf_mem *mem)
224258
if (ret < 0)
225259
goto out_delete;
226260

227-
printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
261+
if (mem->phys_addr)
262+
printf("# PID, TID, IP, ADDR, PHYS ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
263+
else
264+
printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
228265

229266
ret = perf_session__process_events(session);
230267

@@ -254,9 +291,16 @@ static int report_events(int argc, const char **argv, struct perf_mem *mem)
254291
* there is no weight (cost) associated with stores, so don't print
255292
* the column
256293
*/
257-
if (!(mem->operation & MEM_OPERATION_LOAD))
258-
rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr,"
259-
"dso_daddr,tlb,locked";
294+
if (!(mem->operation & MEM_OPERATION_LOAD)) {
295+
if (mem->phys_addr)
296+
rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr,"
297+
"dso_daddr,tlb,locked,phys_daddr";
298+
else
299+
rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr,"
300+
"dso_daddr,tlb,locked";
301+
} else if (mem->phys_addr)
302+
rep_argv[i++] = "--sort=local_weight,mem,sym,dso,symbol_daddr,"
303+
"dso_daddr,snoop,tlb,locked,phys_daddr";
260304

261305
for (j = 1; j < argc; j++, i++)
262306
rep_argv[i] = argv[j];
@@ -373,6 +417,7 @@ int cmd_mem(int argc, const char **argv)
373417
"separator for columns, no spaces will be added"
374418
" between columns '.' is reserved."),
375419
OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
420+
OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record/Report sample physical addresses"),
376421
OPT_END()
377422
};
378423
const char *const mem_subcommands[] = { "record", "report", NULL };

0 commit comments

Comments
 (0)