Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | #include "perf.h" |
| 3 | |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 4 | #include <subcmd/parse-options.h> |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 5 | #include "util/trace-event.h" |
| 6 | #include "util/tool.h" |
| 7 | #include "util/session.h" |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 8 | #include "util/data.h" |
Jiri Olsa | acbe613 | 2016-02-15 09:34:34 +0100 | [diff] [blame] | 9 | #include "util/mem-events.h" |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 10 | #include "util/debug.h" |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 11 | |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 12 | #define MEM_OPERATION_LOAD 0x1 |
| 13 | #define MEM_OPERATION_STORE 0x2 |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 14 | |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 15 | struct perf_mem { |
| 16 | struct perf_tool tool; |
| 17 | char const *input_name; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 18 | bool hide_unresolved; |
| 19 | bool dump_raw; |
Yunlong Song | 62a1a63 | 2015-04-02 21:47:15 +0800 | [diff] [blame] | 20 | bool force; |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 21 | int operation; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 22 | const char *cpu_list; |
| 23 | DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
| 24 | }; |
| 25 | |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 26 | static int parse_record_events(const struct option *opt, |
| 27 | const char *str, int unset __maybe_unused) |
| 28 | { |
| 29 | struct perf_mem *mem = *(struct perf_mem **)opt->value; |
| 30 | int j; |
| 31 | |
| 32 | if (strcmp(str, "list")) { |
| 33 | if (!perf_mem_events__parse(str)) { |
| 34 | mem->operation = 0; |
| 35 | return 0; |
| 36 | } |
| 37 | exit(-1); |
| 38 | } |
| 39 | |
| 40 | for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { |
| 41 | struct perf_mem_event *e = &perf_mem_events[j]; |
| 42 | |
Jiri Olsa | 54fbad5 | 2016-02-24 09:46:42 +0100 | [diff] [blame] | 43 | fprintf(stderr, "%-13s%-*s%s\n", |
| 44 | e->tag, |
| 45 | verbose ? 25 : 0, |
Jiri Olsa | 2ba7ac5 | 2016-02-24 09:46:43 +0100 | [diff] [blame] | 46 | verbose ? perf_mem_events__name(j) : "", |
Jiri Olsa | 54fbad5 | 2016-02-24 09:46:42 +0100 | [diff] [blame] | 47 | e->supported ? ": available" : ""); |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 48 | } |
| 49 | exit(0); |
| 50 | } |
| 51 | |
| 52 | static const char * const __usage[] = { |
| 53 | "perf mem record [<options>] [<command>]", |
| 54 | "perf mem record [<options>] -- <command> [<options>]", |
| 55 | NULL |
| 56 | }; |
| 57 | |
| 58 | static const char * const *record_mem_usage = __usage; |
| 59 | |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 60 | static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 61 | { |
| 62 | int rec_argc, i = 0, j; |
| 63 | const char **rec_argv; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 64 | int ret; |
Jiri Olsa | ad16511 | 2016-03-24 13:52:16 +0100 | [diff] [blame] | 65 | bool all_user = false, all_kernel = false; |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 66 | struct option options[] = { |
| 67 | OPT_CALLBACK('e', "event", &mem, "event", |
| 68 | "event selector. use 'perf mem record -e list' to list available events", |
| 69 | parse_record_events), |
Jiri Olsa | b0d745b | 2016-06-14 20:19:11 +0200 | [diff] [blame] | 70 | OPT_UINTEGER(0, "ldlat", &perf_mem_events__loads_ldlat, "mem-loads latency"), |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 71 | OPT_INCR('v', "verbose", &verbose, |
| 72 | "be more verbose (show counter open errors, etc)"), |
Jiri Olsa | ad16511 | 2016-03-24 13:52:16 +0100 | [diff] [blame] | 73 | OPT_BOOLEAN('U', "--all-user", &all_user, "collect only user level data"), |
| 74 | OPT_BOOLEAN('K', "--all-kernel", &all_kernel, "collect only kernel level data"), |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 75 | OPT_END() |
| 76 | }; |
| 77 | |
| 78 | argc = parse_options(argc, argv, options, record_mem_usage, |
| 79 | PARSE_OPT_STOP_AT_NON_OPTION); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 80 | |
Jiri Olsa | ad16511 | 2016-03-24 13:52:16 +0100 | [diff] [blame] | 81 | rec_argc = argc + 9; /* max number of arguments */ |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 82 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 83 | if (!rec_argv) |
| 84 | return -1; |
| 85 | |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 86 | rec_argv[i++] = "record"; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 87 | |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 88 | if (mem->operation & MEM_OPERATION_LOAD) |
Jiri Olsa | acbe613 | 2016-02-15 09:34:34 +0100 | [diff] [blame] | 89 | perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true; |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 90 | |
Jiri Olsa | 33da54f | 2016-08-11 10:50:57 +0200 | [diff] [blame] | 91 | if (mem->operation & MEM_OPERATION_STORE) |
| 92 | perf_mem_events[PERF_MEM_EVENTS__STORE].record = true; |
| 93 | |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 94 | if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record) |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 95 | rec_argv[i++] = "-W"; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 96 | |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 97 | rec_argv[i++] = "-d"; |
| 98 | |
Jiri Olsa | acbe613 | 2016-02-15 09:34:34 +0100 | [diff] [blame] | 99 | for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { |
| 100 | if (!perf_mem_events[j].record) |
| 101 | continue; |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 102 | |
Jiri Olsa | 54fbad5 | 2016-02-24 09:46:42 +0100 | [diff] [blame] | 103 | if (!perf_mem_events[j].supported) { |
| 104 | pr_err("failed: event '%s' not supported\n", |
Jiri Olsa | 2ba7ac5 | 2016-02-24 09:46:43 +0100 | [diff] [blame] | 105 | perf_mem_events__name(j)); |
Jiri Olsa | 54fbad5 | 2016-02-24 09:46:42 +0100 | [diff] [blame] | 106 | return -1; |
| 107 | } |
| 108 | |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 109 | rec_argv[i++] = "-e"; |
Jiri Olsa | 2ba7ac5 | 2016-02-24 09:46:43 +0100 | [diff] [blame] | 110 | rec_argv[i++] = perf_mem_events__name(j); |
Jiri Olsa | acbe613 | 2016-02-15 09:34:34 +0100 | [diff] [blame] | 111 | }; |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 112 | |
Jiri Olsa | ad16511 | 2016-03-24 13:52:16 +0100 | [diff] [blame] | 113 | if (all_user) |
| 114 | rec_argv[i++] = "--all-user"; |
| 115 | |
| 116 | if (all_kernel) |
| 117 | rec_argv[i++] = "--all-kernel"; |
| 118 | |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 119 | for (j = 0; j < argc; j++, i++) |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 120 | rec_argv[i] = argv[j]; |
| 121 | |
Jiri Olsa | ce1e22b | 2016-02-15 09:34:35 +0100 | [diff] [blame] | 122 | if (verbose > 0) { |
| 123 | pr_debug("calling: record "); |
| 124 | |
| 125 | while (rec_argv[j]) { |
| 126 | pr_debug("%s ", rec_argv[j]); |
| 127 | j++; |
| 128 | } |
| 129 | pr_debug("\n"); |
| 130 | } |
| 131 | |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 132 | ret = cmd_record(i, rec_argv, NULL); |
| 133 | free(rec_argv); |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | static int |
| 138 | dump_raw_samples(struct perf_tool *tool, |
| 139 | union perf_event *event, |
| 140 | struct perf_sample *sample, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 141 | struct machine *machine) |
| 142 | { |
| 143 | struct perf_mem *mem = container_of(tool, struct perf_mem, tool); |
| 144 | struct addr_location al; |
| 145 | const char *fmt; |
| 146 | |
Arnaldo Carvalho de Melo | bb3eb56 | 2016-03-22 18:39:09 -0300 | [diff] [blame] | 147 | if (machine__resolve(machine, &al, sample) < 0) { |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 148 | fprintf(stderr, "problem processing %d event, skipping it.\n", |
| 149 | event->header.type); |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | if (al.filtered || (mem->hide_unresolved && al.sym == NULL)) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 154 | goto out_put; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 155 | |
| 156 | if (al.map != NULL) |
| 157 | al.map->dso->hit = 1; |
| 158 | |
| 159 | if (symbol_conf.field_sep) { |
| 160 | fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s%"PRIu64 |
| 161 | "%s0x%"PRIx64"%s%s:%s\n"; |
| 162 | } else { |
| 163 | fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64 |
| 164 | "%s%5"PRIu64"%s0x%06"PRIx64"%s%s:%s\n"; |
| 165 | symbol_conf.field_sep = " "; |
| 166 | } |
| 167 | |
| 168 | printf(fmt, |
| 169 | sample->pid, |
| 170 | symbol_conf.field_sep, |
| 171 | sample->tid, |
| 172 | symbol_conf.field_sep, |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 173 | sample->ip, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 174 | symbol_conf.field_sep, |
| 175 | sample->addr, |
| 176 | symbol_conf.field_sep, |
| 177 | sample->weight, |
| 178 | symbol_conf.field_sep, |
| 179 | sample->data_src, |
| 180 | symbol_conf.field_sep, |
| 181 | al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???", |
| 182 | al.sym ? al.sym->name : "???"); |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 183 | out_put: |
| 184 | addr_location__put(&al); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static int process_sample_event(struct perf_tool *tool, |
| 189 | union perf_event *event, |
| 190 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 8b640cc | 2013-12-19 17:00:45 -0300 | [diff] [blame] | 191 | struct perf_evsel *evsel __maybe_unused, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 192 | struct machine *machine) |
| 193 | { |
Arnaldo Carvalho de Melo | 8b640cc | 2013-12-19 17:00:45 -0300 | [diff] [blame] | 194 | return dump_raw_samples(tool, event, sample, machine); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static int report_raw_events(struct perf_mem *mem) |
| 198 | { |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 199 | struct perf_data_file file = { |
| 200 | .path = input_name, |
| 201 | .mode = PERF_DATA_MODE_READ, |
Yunlong Song | 62a1a63 | 2015-04-02 21:47:15 +0800 | [diff] [blame] | 202 | .force = mem->force, |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 203 | }; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 204 | int ret; |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 205 | struct perf_session *session = perf_session__new(&file, false, |
| 206 | &mem->tool); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 207 | |
| 208 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 209 | return -1; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 210 | |
| 211 | if (mem->cpu_list) { |
| 212 | ret = perf_session__cpu_bitmap(session, mem->cpu_list, |
| 213 | mem->cpu_bitmap); |
Taeung Song | 1df9fade | 2015-07-01 21:08:19 +0900 | [diff] [blame] | 214 | if (ret < 0) |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 215 | goto out_delete; |
| 216 | } |
| 217 | |
Taeung Song | 1df9fade | 2015-07-01 21:08:19 +0900 | [diff] [blame] | 218 | ret = symbol__init(&session->header.env); |
| 219 | if (ret < 0) |
| 220 | goto out_delete; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 221 | |
| 222 | printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n"); |
| 223 | |
Taeung Song | 1df9fade | 2015-07-01 21:08:19 +0900 | [diff] [blame] | 224 | ret = perf_session__process_events(session); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 225 | |
| 226 | out_delete: |
| 227 | perf_session__delete(session); |
Taeung Song | 1df9fade | 2015-07-01 21:08:19 +0900 | [diff] [blame] | 228 | return ret; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static int report_events(int argc, const char **argv, struct perf_mem *mem) |
| 232 | { |
| 233 | const char **rep_argv; |
| 234 | int ret, i = 0, j, rep_argc; |
| 235 | |
| 236 | if (mem->dump_raw) |
| 237 | return report_raw_events(mem); |
| 238 | |
| 239 | rep_argc = argc + 3; |
| 240 | rep_argv = calloc(rep_argc + 1, sizeof(char *)); |
| 241 | if (!rep_argv) |
| 242 | return -1; |
| 243 | |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 244 | rep_argv[i++] = "report"; |
| 245 | rep_argv[i++] = "--mem-mode"; |
| 246 | rep_argv[i++] = "-n"; /* display number of samples */ |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 247 | |
| 248 | /* |
| 249 | * there is no weight (cost) associated with stores, so don't print |
| 250 | * the column |
| 251 | */ |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 252 | if (!(mem->operation & MEM_OPERATION_LOAD)) |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 253 | rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr," |
| 254 | "dso_daddr,tlb,locked"; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 255 | |
| 256 | for (j = 1; j < argc; j++, i++) |
| 257 | rep_argv[i] = argv[j]; |
| 258 | |
| 259 | ret = cmd_report(i, rep_argv, NULL); |
| 260 | free(rep_argv); |
| 261 | return ret; |
| 262 | } |
| 263 | |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 264 | struct mem_mode { |
| 265 | const char *name; |
| 266 | int mode; |
| 267 | }; |
| 268 | |
| 269 | #define MEM_OPT(n, m) \ |
| 270 | { .name = n, .mode = (m) } |
| 271 | |
| 272 | #define MEM_END { .name = NULL } |
| 273 | |
| 274 | static const struct mem_mode mem_modes[]={ |
| 275 | MEM_OPT("load", MEM_OPERATION_LOAD), |
| 276 | MEM_OPT("store", MEM_OPERATION_STORE), |
| 277 | MEM_END |
| 278 | }; |
| 279 | |
| 280 | static int |
| 281 | parse_mem_ops(const struct option *opt, const char *str, int unset) |
| 282 | { |
| 283 | int *mode = (int *)opt->value; |
| 284 | const struct mem_mode *m; |
| 285 | char *s, *os = NULL, *p; |
| 286 | int ret = -1; |
| 287 | |
| 288 | if (unset) |
| 289 | return 0; |
| 290 | |
| 291 | /* str may be NULL in case no arg is passed to -t */ |
| 292 | if (str) { |
| 293 | /* because str is read-only */ |
| 294 | s = os = strdup(str); |
| 295 | if (!s) |
| 296 | return -1; |
| 297 | |
| 298 | /* reset mode */ |
| 299 | *mode = 0; |
| 300 | |
| 301 | for (;;) { |
| 302 | p = strchr(s, ','); |
| 303 | if (p) |
| 304 | *p = '\0'; |
| 305 | |
| 306 | for (m = mem_modes; m->name; m++) { |
| 307 | if (!strcasecmp(s, m->name)) |
| 308 | break; |
| 309 | } |
| 310 | if (!m->name) { |
| 311 | fprintf(stderr, "unknown sampling op %s," |
| 312 | " check man page\n", s); |
| 313 | goto error; |
| 314 | } |
| 315 | |
| 316 | *mode |= m->mode; |
| 317 | |
| 318 | if (!p) |
| 319 | break; |
| 320 | |
| 321 | s = p + 1; |
| 322 | } |
| 323 | } |
| 324 | ret = 0; |
| 325 | |
| 326 | if (*mode == 0) |
| 327 | *mode = MEM_OPERATION_LOAD; |
| 328 | error: |
| 329 | free(os); |
| 330 | return ret; |
| 331 | } |
| 332 | |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 333 | int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused) |
| 334 | { |
| 335 | struct stat st; |
| 336 | struct perf_mem mem = { |
| 337 | .tool = { |
| 338 | .sample = process_sample_event, |
| 339 | .mmap = perf_event__process_mmap, |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 340 | .mmap2 = perf_event__process_mmap2, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 341 | .comm = perf_event__process_comm, |
| 342 | .lost = perf_event__process_lost, |
| 343 | .fork = perf_event__process_fork, |
| 344 | .build_id = perf_event__process_build_id, |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 345 | .ordered_events = true, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 346 | }, |
| 347 | .input_name = "perf.data", |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 348 | /* |
| 349 | * default to both load an store sampling |
| 350 | */ |
| 351 | .operation = MEM_OPERATION_LOAD | MEM_OPERATION_STORE, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 352 | }; |
| 353 | const struct option mem_options[] = { |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 354 | OPT_CALLBACK('t', "type", &mem.operation, |
Stephane Eranian | 67121f8 | 2014-12-17 16:23:55 +0100 | [diff] [blame] | 355 | "type", "memory operations(load,store) Default load,store", |
| 356 | parse_mem_ops), |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 357 | OPT_BOOLEAN('D', "dump-raw-samples", &mem.dump_raw, |
| 358 | "dump raw samples in ASCII"), |
| 359 | OPT_BOOLEAN('U', "hide-unresolved", &mem.hide_unresolved, |
| 360 | "Only display entries resolved to a symbol"), |
| 361 | OPT_STRING('i', "input", &input_name, "file", |
| 362 | "input file name"), |
| 363 | OPT_STRING('C', "cpu", &mem.cpu_list, "cpu", |
| 364 | "list of cpus to profile"), |
Wang Nan | 8b8ca6e | 2015-03-20 02:57:52 +0000 | [diff] [blame] | 365 | OPT_STRING_NOEMPTY('x', "field-separator", &symbol_conf.field_sep, |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 366 | "separator", |
| 367 | "separator for columns, no spaces will be added" |
| 368 | " between columns '.' is reserved."), |
Yunlong Song | 62a1a63 | 2015-04-02 21:47:15 +0800 | [diff] [blame] | 369 | OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"), |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 370 | OPT_END() |
| 371 | }; |
Ramkumar Ramachandra | 8d2a2a1 | 2014-03-14 23:17:52 -0400 | [diff] [blame] | 372 | const char *const mem_subcommands[] = { "record", "report", NULL }; |
| 373 | const char *mem_usage[] = { |
| 374 | NULL, |
| 375 | NULL |
| 376 | }; |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 377 | |
Jiri Olsa | 54fbad5 | 2016-02-24 09:46:42 +0100 | [diff] [blame] | 378 | if (perf_mem_events__init()) { |
| 379 | pr_err("failed: memory events not supported\n"); |
| 380 | return -1; |
| 381 | } |
| 382 | |
Ramkumar Ramachandra | 8d2a2a1 | 2014-03-14 23:17:52 -0400 | [diff] [blame] | 383 | argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands, |
| 384 | mem_usage, PARSE_OPT_STOP_AT_NON_OPTION); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 385 | |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 386 | if (!argc || !(strncmp(argv[0], "rec", 3) || mem.operation)) |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 387 | usage_with_options(mem_usage, mem_options); |
| 388 | |
| 389 | if (!mem.input_name || !strlen(mem.input_name)) { |
| 390 | if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) |
| 391 | mem.input_name = "-"; |
| 392 | else |
| 393 | mem.input_name = "perf.data"; |
| 394 | } |
| 395 | |
| 396 | if (!strncmp(argv[0], "rec", 3)) |
Arnaldo Carvalho de Melo | 6602412 | 2014-12-17 13:53:27 -0300 | [diff] [blame] | 397 | return __cmd_record(argc, argv, &mem); |
Stephane Eranian | 028f12e | 2013-01-24 16:10:38 +0100 | [diff] [blame] | 398 | else if (!strncmp(argv[0], "rep", 3)) |
| 399 | return report_events(argc, argv, &mem); |
| 400 | else |
| 401 | usage_with_options(mem_usage, mem_options); |
| 402 | |
| 403 | return 0; |
| 404 | } |