9 #include <subcmd/parse-options.h> 18 #define MEM_OPERATION_LOAD 0x1 19 #define MEM_OPERATION_STORE 0x2 34 const char *
str,
int unset __maybe_unused)
39 if (strcmp(str,
"list")) {
50 fprintf(stderr,
"%-13s%-*s%s\n",
60 "perf mem record [<options>] [<command>]",
61 "perf mem record [<options>] -- <command> [<options>]",
69 int rec_argc, i = 0, j;
70 const char **rec_argv;
72 bool all_user =
false, all_kernel =
false;
73 struct option options[] = {
74 OPT_CALLBACK(
'e',
"event", &mem,
"event",
75 "event selector. use 'perf mem record -e list' to list available events",
78 OPT_INCR(
'v',
"verbose", &
verbose,
79 "be more verbose (show counter open errors, etc)"),
80 OPT_BOOLEAN(
'U',
"all-user", &all_user,
"collect only user level data"),
81 OPT_BOOLEAN(
'K',
"all-kernel", &all_kernel,
"collect only kernel level data"),
86 PARSE_OPT_KEEP_UNKNOWN);
89 rec_argv = calloc(rec_argc + 1,
sizeof(
char *));
93 rec_argv[i++] =
"record";
102 rec_argv[i++] =
"-W";
104 rec_argv[i++] =
"-d";
107 rec_argv[i++] =
"--phys-data";
114 pr_err(
"failed: event '%s' not supported\n",
120 rec_argv[i++] =
"-e";
125 rec_argv[i++] =
"--all-user";
128 rec_argv[i++] =
"--all-kernel";
130 for (j = 0; j <
argc; j++, i++)
131 rec_argv[i] = argv[j];
136 while (rec_argv[j]) {
159 fprintf(stderr,
"problem processing %d event, skipping it.\n",
172 fmt =
"%d%s%d%s0x%"PRIx64
"%s0x%"PRIx64
"%s0x%016"PRIx64
173 "%s%"PRIu64
"%s0x%"PRIx64
"%s%s:%s\n";
175 fmt =
"%5d%s%5d%s0x%016"PRIx64
"%s0x016%"PRIx64
176 "%s0x%016"PRIx64
"%s%5"PRIu64
"%s0x%06"PRIx64
200 fmt =
"%d%s%d%s0x%"PRIx64
"%s0x%"PRIx64
"%s%"PRIu64
201 "%s0x%"PRIx64
"%s%s:%s\n";
203 fmt =
"%5d%s%5d%s0x%016"PRIx64
"%s0x016%"PRIx64
204 "%s%5"PRIu64
"%s0x%06"PRIx64
"%s%s:%s\n";
266 printf(
"# PID, TID, IP, ADDR, PHYS ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
268 printf(
"# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
279 const char **rep_argv;
280 int ret, i = 0, j, rep_argc;
286 rep_argv = calloc(rep_argc + 1,
sizeof(
char *));
290 rep_argv[i++] =
"report";
291 rep_argv[i++] =
"--mem-mode";
292 rep_argv[i++] =
"-n";
300 rep_argv[i++] =
"--sort=mem,sym,dso,symbol_daddr," 301 "dso_daddr,tlb,locked,phys_daddr";
303 rep_argv[i++] =
"--sort=mem,sym,dso,symbol_daddr," 304 "dso_daddr,tlb,locked";
306 rep_argv[i++] =
"--sort=local_weight,mem,sym,dso,symbol_daddr," 307 "dso_daddr,snoop,tlb,locked,phys_daddr";
309 for (j = 1; j <
argc; j++, i++)
310 rep_argv[i] = argv[j];
322 #define MEM_OPT(n, m) \ 323 { .name = n, .mode = (m) } 325 #define MEM_END { .name = NULL } 336 int *
mode = (
int *)opt->value;
338 char *s, *os = NULL, *p;
347 s = os = strdup(str);
359 for (
m = mem_modes;
m->name;
m++) {
360 if (!strcasecmp(s,
m->name))
364 fprintf(stderr,
"unknown sampling op %s," 365 " check man page\n", s);
399 .ordered_events =
true,
401 .input_name =
"perf.data",
407 const struct option mem_options[] = {
408 OPT_CALLBACK(
't',
"type", &mem.
operation,
409 "type",
"memory operations(load,store) Default load,store",
411 OPT_BOOLEAN(
'D',
"dump-raw-samples", &mem.
dump_raw,
412 "dump raw samples in ASCII"),
414 "Only display entries resolved to a symbol"),
417 OPT_STRING(
'C',
"cpu", &mem.
cpu_list,
"cpu",
418 "list of cpus to profile"),
421 "separator for columns, no spaces will be added" 422 " between columns '.' is reserved."),
423 OPT_BOOLEAN(
'f',
"force", &mem.
force,
"don't complain, do it"),
424 OPT_BOOLEAN(
'p',
"phys-data", &mem.
phys_addr,
"Record/Report sample physical addresses"),
427 const char *
const mem_subcommands[] = {
"record",
"report", NULL };
428 const char *mem_usage[] = {
434 pr_err(
"failed: memory events not supported\n");
438 argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
439 mem_usage, PARSE_OPT_KEEP_UNKNOWN);
441 if (!argc || !(strncmp(argv[0],
"rec", 3) || mem.
operation))
442 usage_with_options(mem_usage, mem_options);
445 if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
451 if (!strncmp(argv[0],
"rec", 3))
453 else if (!strncmp(argv[0],
"rep", 3))
456 usage_with_options(mem_usage, mem_options);
int cmd_mem(int argc, const char **argv)
int cmd_report(int argc, const char **argv)
static const struct mem_mode mem_modes[]
static int parse_mem_ops(const struct option *opt, const char *str, int unset)
int machine__resolve(struct machine *machine, struct addr_location *al, struct perf_sample *sample)
int cmd_record(int argc, const char **argv)
static int dump_raw_samples(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int perf_event__process_mmap(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
struct perf_data_file file
int perf_mem_events__init(void)
int perf_event__process_comm(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int perf_event__process_fork(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
unsigned int perf_mem_events__loads_ldlat
void perf_session__delete(struct perf_session *session)
static const char *const * record_mem_usage
char * perf_mem_events__name(int i)
void addr_location__put(struct addr_location *al)
#define pr_debug(fmt,...)
static struct perf_session * session
static int process_sample_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel __maybe_unused, struct machine *machine)
static int str(yyscan_t scanner, int token)
static int report_events(int argc, const char **argv, struct perf_mem *mem)
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS)
struct perf_event_header header
#define MEM_OPERATION_LOAD
static int report_raw_events(struct perf_mem *mem)
struct perf_session * perf_session__new(struct perf_data *data, bool repipe, struct perf_tool *tool)
int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int perf_session__process_events(struct perf_session *session)
#define MEM_OPERATION_STORE
static int parse_record_events(const struct option *opt, const char *str, int unset __maybe_unused)
static const char *const __usage[]
int perf_mem_events__parse(const char *str)
struct perf_header header
int symbol__init(struct perf_env *env)
int perf_event__process_lost(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int perf_session__cpu_bitmap(struct perf_session *session, const char *cpu_list, unsigned long *cpu_bitmap)
int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX]