Commit | Line | Data |
---|---|---|
514f1c67 | 1 | #include "builtin.h" |
752fde44 | 2 | #include "util/color.h" |
514f1c67 | 3 | #include "util/evlist.h" |
752fde44 ACM |
4 | #include "util/machine.h" |
5 | #include "util/thread.h" | |
514f1c67 ACM |
6 | #include "util/parse-options.h" |
7 | #include "util/thread_map.h" | |
8 | #include "event-parse.h" | |
9 | ||
10 | #include <libaudit.h> | |
11 | #include <stdlib.h> | |
12 | ||
13 | static struct syscall_fmt { | |
14 | const char *name; | |
aec1930b | 15 | const char *alias; |
514f1c67 ACM |
16 | bool errmsg; |
17 | bool timeout; | |
18 | } syscall_fmts[] = { | |
8b745263 | 19 | { .name = "access", .errmsg = true, }, |
aec1930b ACM |
20 | { .name = "arch_prctl", .errmsg = true, .alias = "prctl", }, |
21 | { .name = "fstat", .errmsg = true, .alias = "newfstat", }, | |
22 | { .name = "fstatat", .errmsg = true, .alias = "newfstatat", }, | |
23 | { .name = "futex", .errmsg = true, }, | |
8b745263 | 24 | { .name = "open", .errmsg = true, }, |
aec1930b ACM |
25 | { .name = "poll", .errmsg = true, .timeout = true, }, |
26 | { .name = "ppoll", .errmsg = true, .timeout = true, }, | |
27 | { .name = "read", .errmsg = true, }, | |
28 | { .name = "recvfrom", .errmsg = true, }, | |
29 | { .name = "select", .errmsg = true, .timeout = true, }, | |
8b745263 | 30 | { .name = "socket", .errmsg = true, }, |
aec1930b | 31 | { .name = "stat", .errmsg = true, .alias = "newstat", }, |
514f1c67 ACM |
32 | }; |
33 | ||
34 | static int syscall_fmt__cmp(const void *name, const void *fmtp) | |
35 | { | |
36 | const struct syscall_fmt *fmt = fmtp; | |
37 | return strcmp(name, fmt->name); | |
38 | } | |
39 | ||
40 | static struct syscall_fmt *syscall_fmt__find(const char *name) | |
41 | { | |
42 | const int nmemb = ARRAY_SIZE(syscall_fmts); | |
43 | return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); | |
44 | } | |
45 | ||
46 | struct syscall { | |
47 | struct event_format *tp_format; | |
48 | const char *name; | |
49 | struct syscall_fmt *fmt; | |
50 | }; | |
51 | ||
60c907ab ACM |
52 | static size_t fprintf_duration(unsigned long t, FILE *fp) |
53 | { | |
54 | double duration = (double)t / NSEC_PER_MSEC; | |
55 | size_t printed = fprintf(fp, "("); | |
56 | ||
57 | if (duration >= 1.0) | |
58 | printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration); | |
59 | else if (duration >= 0.01) | |
60 | printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration); | |
61 | else | |
62 | printed += color_fprintf(fp, PERF_COLOR_NORMAL, "%6.3f ms", duration); | |
63 | return printed + fprintf(stdout, "): "); | |
64 | } | |
65 | ||
752fde44 ACM |
66 | struct thread_trace { |
67 | u64 entry_time; | |
68 | u64 exit_time; | |
69 | bool entry_pending; | |
efd5745e | 70 | unsigned long nr_events; |
752fde44 ACM |
71 | char *entry_str; |
72 | }; | |
73 | ||
74 | static struct thread_trace *thread_trace__new(void) | |
75 | { | |
76 | return zalloc(sizeof(struct thread_trace)); | |
77 | } | |
78 | ||
79 | static struct thread_trace *thread__trace(struct thread *thread) | |
80 | { | |
efd5745e ACM |
81 | struct thread_trace *ttrace; |
82 | ||
752fde44 ACM |
83 | if (thread == NULL) |
84 | goto fail; | |
85 | ||
86 | if (thread->priv == NULL) | |
87 | thread->priv = thread_trace__new(); | |
efd5745e | 88 | |
752fde44 ACM |
89 | if (thread->priv == NULL) |
90 | goto fail; | |
91 | ||
efd5745e ACM |
92 | ttrace = thread->priv; |
93 | ++ttrace->nr_events; | |
94 | ||
95 | return ttrace; | |
752fde44 ACM |
96 | fail: |
97 | color_fprintf(stdout, PERF_COLOR_RED, | |
98 | "WARNING: not enough memory, dropping samples!\n"); | |
99 | return NULL; | |
100 | } | |
101 | ||
514f1c67 ACM |
102 | struct trace { |
103 | int audit_machine; | |
104 | struct { | |
105 | int max; | |
106 | struct syscall *table; | |
107 | } syscalls; | |
108 | struct perf_record_opts opts; | |
752fde44 ACM |
109 | struct machine host; |
110 | u64 base_time; | |
efd5745e | 111 | unsigned long nr_events; |
752fde44 | 112 | bool multiple_threads; |
ae9ed035 | 113 | double duration_filter; |
514f1c67 ACM |
114 | }; |
115 | ||
ae9ed035 ACM |
116 | static bool trace__filter_duration(struct trace *trace, double t) |
117 | { | |
118 | return t < (trace->duration_filter * NSEC_PER_MSEC); | |
119 | } | |
120 | ||
752fde44 ACM |
121 | static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) |
122 | { | |
123 | double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; | |
124 | ||
60c907ab | 125 | return fprintf(fp, "%10.3f ", ts); |
752fde44 ACM |
126 | } |
127 | ||
f15eb531 NK |
128 | static bool done = false; |
129 | ||
130 | static void sig_handler(int sig __maybe_unused) | |
131 | { | |
132 | done = true; | |
133 | } | |
134 | ||
752fde44 | 135 | static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, |
60c907ab | 136 | u64 duration, u64 tstamp, FILE *fp) |
752fde44 ACM |
137 | { |
138 | size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); | |
60c907ab | 139 | printed += fprintf_duration(duration, fp); |
752fde44 ACM |
140 | |
141 | if (trace->multiple_threads) | |
142 | printed += fprintf(fp, "%d ", thread->pid); | |
143 | ||
144 | return printed; | |
145 | } | |
146 | ||
147 | static int trace__process_event(struct machine *machine, union perf_event *event) | |
148 | { | |
149 | int ret = 0; | |
150 | ||
151 | switch (event->header.type) { | |
152 | case PERF_RECORD_LOST: | |
153 | color_fprintf(stdout, PERF_COLOR_RED, | |
154 | "LOST %" PRIu64 " events!\n", event->lost.lost); | |
155 | ret = machine__process_lost_event(machine, event); | |
156 | default: | |
157 | ret = machine__process_event(machine, event); | |
158 | break; | |
159 | } | |
160 | ||
161 | return ret; | |
162 | } | |
163 | ||
164 | static int trace__tool_process(struct perf_tool *tool __maybe_unused, | |
165 | union perf_event *event, | |
166 | struct perf_sample *sample __maybe_unused, | |
167 | struct machine *machine) | |
168 | { | |
169 | return trace__process_event(machine, event); | |
170 | } | |
171 | ||
172 | static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) | |
173 | { | |
174 | int err = symbol__init(); | |
175 | ||
176 | if (err) | |
177 | return err; | |
178 | ||
179 | machine__init(&trace->host, "", HOST_KERNEL_ID); | |
180 | machine__create_kernel_maps(&trace->host); | |
181 | ||
182 | if (perf_target__has_task(&trace->opts.target)) { | |
183 | err = perf_event__synthesize_thread_map(NULL, evlist->threads, | |
184 | trace__tool_process, | |
185 | &trace->host); | |
186 | } else { | |
187 | err = perf_event__synthesize_threads(NULL, trace__tool_process, | |
188 | &trace->host); | |
189 | } | |
190 | ||
191 | if (err) | |
192 | symbol__exit(); | |
193 | ||
194 | return err; | |
195 | } | |
196 | ||
514f1c67 ACM |
197 | static int trace__read_syscall_info(struct trace *trace, int id) |
198 | { | |
199 | char tp_name[128]; | |
200 | struct syscall *sc; | |
3a531260 ACM |
201 | const char *name = audit_syscall_to_name(id, trace->audit_machine); |
202 | ||
203 | if (name == NULL) | |
204 | return -1; | |
514f1c67 ACM |
205 | |
206 | if (id > trace->syscalls.max) { | |
207 | struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); | |
208 | ||
209 | if (nsyscalls == NULL) | |
210 | return -1; | |
211 | ||
212 | if (trace->syscalls.max != -1) { | |
213 | memset(nsyscalls + trace->syscalls.max + 1, 0, | |
214 | (id - trace->syscalls.max) * sizeof(*sc)); | |
215 | } else { | |
216 | memset(nsyscalls, 0, (id + 1) * sizeof(*sc)); | |
217 | } | |
218 | ||
219 | trace->syscalls.table = nsyscalls; | |
220 | trace->syscalls.max = id; | |
221 | } | |
222 | ||
223 | sc = trace->syscalls.table + id; | |
3a531260 ACM |
224 | sc->name = name; |
225 | sc->fmt = syscall_fmt__find(sc->name); | |
514f1c67 | 226 | |
aec1930b | 227 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); |
514f1c67 | 228 | sc->tp_format = event_format__new("syscalls", tp_name); |
aec1930b ACM |
229 | |
230 | if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) { | |
231 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); | |
232 | sc->tp_format = event_format__new("syscalls", tp_name); | |
233 | } | |
514f1c67 ACM |
234 | |
235 | return sc->tp_format != NULL ? 0 : -1; | |
236 | } | |
237 | ||
752fde44 ACM |
238 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, |
239 | unsigned long *args) | |
514f1c67 ACM |
240 | { |
241 | int i = 0; | |
242 | size_t printed = 0; | |
243 | ||
244 | if (sc->tp_format != NULL) { | |
245 | struct format_field *field; | |
246 | ||
247 | for (field = sc->tp_format->format.fields->next; field; field = field->next) { | |
752fde44 ACM |
248 | printed += scnprintf(bf + printed, size - printed, |
249 | "%s%s: %ld", printed ? ", " : "", | |
250 | field->name, args[i++]); | |
514f1c67 ACM |
251 | } |
252 | } else { | |
253 | while (i < 6) { | |
752fde44 ACM |
254 | printed += scnprintf(bf + printed, size - printed, |
255 | "%sarg%d: %ld", | |
256 | printed ? ", " : "", i, args[i]); | |
514f1c67 ACM |
257 | ++i; |
258 | } | |
259 | } | |
260 | ||
261 | return printed; | |
262 | } | |
263 | ||
ba3d7dee ACM |
264 | typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel, |
265 | struct perf_sample *sample); | |
266 | ||
267 | static struct syscall *trace__syscall_info(struct trace *trace, | |
268 | struct perf_evsel *evsel, | |
269 | struct perf_sample *sample) | |
270 | { | |
271 | int id = perf_evsel__intval(evsel, sample, "id"); | |
272 | ||
273 | if (id < 0) { | |
274 | printf("Invalid syscall %d id, skipping...\n", id); | |
275 | return NULL; | |
276 | } | |
277 | ||
278 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) && | |
279 | trace__read_syscall_info(trace, id)) | |
280 | goto out_cant_read; | |
281 | ||
282 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL)) | |
283 | goto out_cant_read; | |
284 | ||
285 | return &trace->syscalls.table[id]; | |
286 | ||
287 | out_cant_read: | |
814d7a4d ACM |
288 | printf("Problems reading syscall %d", id); |
289 | if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) | |
290 | printf("(%s)", trace->syscalls.table[id].name); | |
291 | puts(" information"); | |
ba3d7dee ACM |
292 | return NULL; |
293 | } | |
294 | ||
295 | static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, | |
296 | struct perf_sample *sample) | |
297 | { | |
752fde44 | 298 | char *msg; |
ba3d7dee | 299 | void *args; |
752fde44 ACM |
300 | size_t printed = 0; |
301 | struct thread *thread = machine__findnew_thread(&trace->host, sample->tid); | |
ba3d7dee | 302 | struct syscall *sc = trace__syscall_info(trace, evsel, sample); |
752fde44 | 303 | struct thread_trace *ttrace = thread__trace(thread); |
ba3d7dee | 304 | |
752fde44 | 305 | if (ttrace == NULL || sc == NULL) |
ba3d7dee ACM |
306 | return -1; |
307 | ||
308 | args = perf_evsel__rawptr(evsel, sample, "args"); | |
309 | if (args == NULL) { | |
310 | printf("Problems reading syscall arguments\n"); | |
311 | return -1; | |
312 | } | |
313 | ||
752fde44 ACM |
314 | ttrace = thread->priv; |
315 | ||
316 | if (ttrace->entry_str == NULL) { | |
317 | ttrace->entry_str = malloc(1024); | |
318 | if (!ttrace->entry_str) | |
319 | return -1; | |
320 | } | |
321 | ||
322 | ttrace->entry_time = sample->time; | |
323 | msg = ttrace->entry_str; | |
324 | printed += scnprintf(msg + printed, 1024 - printed, "%s(", sc->name); | |
325 | ||
326 | printed += syscall__scnprintf_args(sc, msg + printed, 1024 - printed, args); | |
327 | ||
328 | if (!strcmp(sc->name, "exit_group") || !strcmp(sc->name, "exit")) { | |
ae9ed035 ACM |
329 | if (!trace->duration_filter) { |
330 | trace__fprintf_entry_head(trace, thread, 1, sample->time, stdout); | |
331 | printf("%-70s\n", ttrace->entry_str); | |
332 | } | |
752fde44 ACM |
333 | } else |
334 | ttrace->entry_pending = true; | |
ba3d7dee ACM |
335 | |
336 | return 0; | |
337 | } | |
338 | ||
339 | static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, | |
340 | struct perf_sample *sample) | |
341 | { | |
342 | int ret; | |
60c907ab | 343 | u64 duration = 0; |
752fde44 ACM |
344 | struct thread *thread = machine__findnew_thread(&trace->host, sample->tid); |
345 | struct thread_trace *ttrace = thread__trace(thread); | |
ba3d7dee ACM |
346 | struct syscall *sc = trace__syscall_info(trace, evsel, sample); |
347 | ||
752fde44 | 348 | if (ttrace == NULL || sc == NULL) |
ba3d7dee ACM |
349 | return -1; |
350 | ||
351 | ret = perf_evsel__intval(evsel, sample, "ret"); | |
352 | ||
752fde44 ACM |
353 | ttrace = thread->priv; |
354 | ||
355 | ttrace->exit_time = sample->time; | |
356 | ||
ae9ed035 | 357 | if (ttrace->entry_time) { |
60c907ab | 358 | duration = sample->time - ttrace->entry_time; |
ae9ed035 ACM |
359 | if (trace__filter_duration(trace, duration)) |
360 | goto out; | |
361 | } else if (trace->duration_filter) | |
362 | goto out; | |
60c907ab ACM |
363 | |
364 | trace__fprintf_entry_head(trace, thread, duration, sample->time, stdout); | |
752fde44 ACM |
365 | |
366 | if (ttrace->entry_pending) { | |
367 | printf("%-70s", ttrace->entry_str); | |
368 | } else { | |
369 | printf(" ... ["); | |
370 | color_fprintf(stdout, PERF_COLOR_YELLOW, "continued"); | |
371 | printf("]: %s()", sc->name); | |
372 | } | |
373 | ||
ba3d7dee ACM |
374 | if (ret < 0 && sc->fmt && sc->fmt->errmsg) { |
375 | char bf[256]; | |
376 | const char *emsg = strerror_r(-ret, bf, sizeof(bf)), | |
377 | *e = audit_errno_to_name(-ret); | |
378 | ||
379 | printf(") = -1 %s %s", e, emsg); | |
380 | } else if (ret == 0 && sc->fmt && sc->fmt->timeout) | |
381 | printf(") = 0 Timeout"); | |
382 | else | |
383 | printf(") = %d", ret); | |
384 | ||
385 | putchar('\n'); | |
ae9ed035 | 386 | out: |
752fde44 ACM |
387 | ttrace->entry_pending = false; |
388 | ||
ba3d7dee ACM |
389 | return 0; |
390 | } | |
391 | ||
f15eb531 | 392 | static int trace__run(struct trace *trace, int argc, const char **argv) |
514f1c67 ACM |
393 | { |
394 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | |
ba3d7dee | 395 | struct perf_evsel *evsel; |
efd5745e ACM |
396 | int err = -1, i; |
397 | unsigned long before; | |
f15eb531 | 398 | const bool forks = argc > 0; |
514f1c67 ACM |
399 | |
400 | if (evlist == NULL) { | |
401 | printf("Not enough memory to run!\n"); | |
402 | goto out; | |
403 | } | |
404 | ||
39876e7d ACM |
405 | if (perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_enter", trace__sys_enter) || |
406 | perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit)) { | |
407 | printf("Couldn't read the raw_syscalls tracepoints information!\n"); | |
514f1c67 ACM |
408 | goto out_delete_evlist; |
409 | } | |
410 | ||
514f1c67 ACM |
411 | err = perf_evlist__create_maps(evlist, &trace->opts.target); |
412 | if (err < 0) { | |
413 | printf("Problems parsing the target to trace, check your options!\n"); | |
414 | goto out_delete_evlist; | |
415 | } | |
416 | ||
752fde44 ACM |
417 | err = trace__symbols_init(trace, evlist); |
418 | if (err < 0) { | |
419 | printf("Problems initializing symbol libraries!\n"); | |
420 | goto out_delete_evlist; | |
421 | } | |
422 | ||
514f1c67 ACM |
423 | perf_evlist__config_attrs(evlist, &trace->opts); |
424 | ||
f15eb531 NK |
425 | signal(SIGCHLD, sig_handler); |
426 | signal(SIGINT, sig_handler); | |
427 | ||
428 | if (forks) { | |
429 | err = perf_evlist__prepare_workload(evlist, &trace->opts, argv); | |
430 | if (err < 0) { | |
431 | printf("Couldn't run the workload!\n"); | |
432 | goto out_delete_evlist; | |
433 | } | |
434 | } | |
435 | ||
514f1c67 ACM |
436 | err = perf_evlist__open(evlist); |
437 | if (err < 0) { | |
438 | printf("Couldn't create the events: %s\n", strerror(errno)); | |
439 | goto out_delete_evlist; | |
440 | } | |
441 | ||
442 | err = perf_evlist__mmap(evlist, UINT_MAX, false); | |
443 | if (err < 0) { | |
444 | printf("Couldn't mmap the events: %s\n", strerror(errno)); | |
445 | goto out_delete_evlist; | |
446 | } | |
447 | ||
448 | perf_evlist__enable(evlist); | |
f15eb531 NK |
449 | |
450 | if (forks) | |
451 | perf_evlist__start_workload(evlist); | |
452 | ||
752fde44 | 453 | trace->multiple_threads = evlist->threads->map[0] == -1 || evlist->threads->nr > 1; |
514f1c67 | 454 | again: |
efd5745e | 455 | before = trace->nr_events; |
514f1c67 ACM |
456 | |
457 | for (i = 0; i < evlist->nr_mmaps; i++) { | |
458 | union perf_event *event; | |
459 | ||
460 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { | |
461 | const u32 type = event->header.type; | |
ba3d7dee | 462 | tracepoint_handler handler; |
514f1c67 | 463 | struct perf_sample sample; |
514f1c67 | 464 | |
efd5745e | 465 | ++trace->nr_events; |
514f1c67 | 466 | |
514f1c67 ACM |
467 | err = perf_evlist__parse_sample(evlist, event, &sample); |
468 | if (err) { | |
469 | printf("Can't parse sample, err = %d, skipping...\n", err); | |
470 | continue; | |
471 | } | |
472 | ||
752fde44 ACM |
473 | if (trace->base_time == 0) |
474 | trace->base_time = sample.time; | |
475 | ||
476 | if (type != PERF_RECORD_SAMPLE) { | |
477 | trace__process_event(&trace->host, event); | |
478 | continue; | |
479 | } | |
480 | ||
514f1c67 ACM |
481 | evsel = perf_evlist__id2evsel(evlist, sample.id); |
482 | if (evsel == NULL) { | |
483 | printf("Unknown tp ID %" PRIu64 ", skipping...\n", sample.id); | |
484 | continue; | |
485 | } | |
486 | ||
752fde44 ACM |
487 | if (sample.raw_data == NULL) { |
488 | printf("%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", | |
489 | perf_evsel__name(evsel), sample.tid, | |
490 | sample.cpu, sample.raw_size); | |
491 | continue; | |
492 | } | |
514f1c67 | 493 | |
fc551f8d ACM |
494 | if (sample.raw_data == NULL) { |
495 | printf("%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", | |
496 | perf_evsel__name(evsel), sample.tid, | |
497 | sample.cpu, sample.raw_size); | |
498 | continue; | |
499 | } | |
500 | ||
ba3d7dee ACM |
501 | handler = evsel->handler.func; |
502 | handler(trace, evsel, &sample); | |
514f1c67 ACM |
503 | } |
504 | } | |
505 | ||
efd5745e | 506 | if (trace->nr_events == before) { |
f15eb531 NK |
507 | if (done) |
508 | goto out_delete_evlist; | |
509 | ||
514f1c67 | 510 | poll(evlist->pollfd, evlist->nr_fds, -1); |
f15eb531 NK |
511 | } |
512 | ||
513 | if (done) | |
514 | perf_evlist__disable(evlist); | |
514f1c67 ACM |
515 | |
516 | goto again; | |
517 | ||
518 | out_delete_evlist: | |
519 | perf_evlist__delete(evlist); | |
520 | out: | |
521 | return err; | |
522 | } | |
523 | ||
ae9ed035 ACM |
524 | static int trace__set_duration(const struct option *opt, const char *str, |
525 | int unset __maybe_unused) | |
526 | { | |
527 | struct trace *trace = opt->value; | |
528 | ||
529 | trace->duration_filter = atof(str); | |
530 | return 0; | |
531 | } | |
532 | ||
514f1c67 ACM |
533 | int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) |
534 | { | |
535 | const char * const trace_usage[] = { | |
f15eb531 NK |
536 | "perf trace [<options>] [<command>]", |
537 | "perf trace [<options>] -- <command> [<options>]", | |
514f1c67 ACM |
538 | NULL |
539 | }; | |
540 | struct trace trace = { | |
541 | .audit_machine = audit_detect_machine(), | |
542 | .syscalls = { | |
543 | . max = -1, | |
544 | }, | |
545 | .opts = { | |
546 | .target = { | |
547 | .uid = UINT_MAX, | |
548 | .uses_mmap = true, | |
549 | }, | |
550 | .user_freq = UINT_MAX, | |
551 | .user_interval = ULLONG_MAX, | |
552 | .no_delay = true, | |
553 | .mmap_pages = 1024, | |
554 | }, | |
555 | }; | |
556 | const struct option trace_options[] = { | |
557 | OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", | |
558 | "trace events on existing process id"), | |
559 | OPT_STRING(0, "tid", &trace.opts.target.tid, "tid", | |
560 | "trace events on existing thread id"), | |
561 | OPT_BOOLEAN(0, "all-cpus", &trace.opts.target.system_wide, | |
562 | "system-wide collection from all CPUs"), | |
563 | OPT_STRING(0, "cpu", &trace.opts.target.cpu_list, "cpu", | |
564 | "list of cpus to monitor"), | |
565 | OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, | |
566 | "child tasks do not inherit counters"), | |
567 | OPT_UINTEGER(0, "mmap-pages", &trace.opts.mmap_pages, | |
568 | "number of mmap data pages"), | |
569 | OPT_STRING(0, "uid", &trace.opts.target.uid_str, "user", | |
570 | "user to profile"), | |
ae9ed035 ACM |
571 | OPT_CALLBACK(0, "duration", &trace, "float", |
572 | "show only events with duration > N.M ms", | |
573 | trace__set_duration), | |
514f1c67 ACM |
574 | OPT_END() |
575 | }; | |
576 | int err; | |
32caf0d1 | 577 | char bf[BUFSIZ]; |
514f1c67 ACM |
578 | |
579 | argc = parse_options(argc, argv, trace_options, trace_usage, 0); | |
514f1c67 | 580 | |
32caf0d1 NK |
581 | err = perf_target__validate(&trace.opts.target); |
582 | if (err) { | |
583 | perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf)); | |
584 | printf("%s", bf); | |
585 | return err; | |
586 | } | |
587 | ||
514f1c67 ACM |
588 | err = perf_target__parse_uid(&trace.opts.target); |
589 | if (err) { | |
514f1c67 ACM |
590 | perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
591 | printf("%s", bf); | |
592 | return err; | |
593 | } | |
594 | ||
f15eb531 | 595 | if (!argc && perf_target__none(&trace.opts.target)) |
ee76120e NK |
596 | trace.opts.target.system_wide = true; |
597 | ||
f15eb531 | 598 | return trace__run(&trace, argc, argv); |
514f1c67 | 599 | } |