• Home
  • Raw
  • Download

Lines Matching full:trace

2  * builtin-trace.c
4 * Builtin 'trace' command:
6 * Display a continuously updated trace of any workload, CPU, specific PID,
12 * Initially based on the 'trace' prototype by Thomas Gleixner:
14 * http://lwn.net/Articles/415728/ ("Announcing a new utility: 'trace'")
38 #include "trace/beauty/beauty.h"
39 #include "trace-event.h"
72 struct trace { struct
600 #include "trace/beauty/arch_errno_names.c"
601 #include "trace/beauty/eventfd.c"
602 #include "trace/beauty/futex_op.c"
603 #include "trace/beauty/futex_val3.c"
604 #include "trace/beauty/mmap.c"
605 #include "trace/beauty/mode_t.c"
606 #include "trace/beauty/msg_flags.c"
607 #include "trace/beauty/open_flags.c"
608 #include "trace/beauty/perf_event_open.c"
609 #include "trace/beauty/pid.c"
610 #include "trace/beauty/sched_policy.c"
611 #include "trace/beauty/seccomp.c"
612 #include "trace/beauty/signum.c"
613 #include "trace/beauty/socket_type.c"
614 #include "trace/beauty/waitid_options.c"
1026 struct trace *trace) in thread__fd_path() argument
1037 if (!trace->live) in thread__fd_path()
1039 ++trace->stats.proc_getname; in thread__fd_path()
1051 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1059 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) in pid__scnprintf_fd() argument
1062 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1065 const char *path = thread__fd_path(thread, fd, trace); in pid__scnprintf_fd()
1103 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1110 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1112 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1115 static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in __trace__fprintf_tstamp() argument
1117 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1128 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1131 return __trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_tstamp()
1145 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1148 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1151 if (trace->multiple_threads) { in trace__fprintf_entry_head()
1152 if (trace->show_comm) in trace__fprintf_entry_head()
1160 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1167 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1184 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1185 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1206 static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) in trace__symbols_init() argument
1213 trace->host = machine__new_host(); in trace__symbols_init()
1214 if (trace->host == NULL) in trace__symbols_init()
1217 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
1221 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1223 trace->opts.proc_map_timeout, 1); in trace__symbols_init()
1231 static void trace__symbols__exit(struct trace *trace) in trace__symbols__exit() argument
1233 machine__exit(trace->host); in trace__symbols__exit()
1234 trace->host = NULL; in trace__symbols__exit()
1298 static int trace__read_syscall_info(struct trace *trace, int id) in trace__read_syscall_info() argument
1302 const char *name = syscalltbl__name(trace->sctbl, id); in trace__read_syscall_info()
1307 if (id > trace->syscalls.max) { in trace__read_syscall_info()
1308 struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); in trace__read_syscall_info()
1313 if (trace->syscalls.max != -1) { in trace__read_syscall_info()
1314 memset(nsyscalls + trace->syscalls.max + 1, 0, in trace__read_syscall_info()
1315 (id - trace->syscalls.max) * sizeof(*sc)); in trace__read_syscall_info()
1320 trace->syscalls.table = nsyscalls; in trace__read_syscall_info()
1321 trace->syscalls.max = id; in trace__read_syscall_info()
1324 sc = trace->syscalls.table + id; in trace__read_syscall_info()
1360 static int trace__validate_ev_qualifier(struct trace *trace) in trace__validate_ev_qualifier() argument
1366 trace->ev_qualifier_ids.nr = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
1367 trace->ev_qualifier_ids.entries = malloc(trace->ev_qualifier_ids.nr * in trace__validate_ev_qualifier()
1368 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1370 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
1372 trace->output); in trace__validate_ev_qualifier()
1377 nr_allocated = trace->ev_qualifier_ids.nr; in trace__validate_ev_qualifier()
1380 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
1382 int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; in trace__validate_ev_qualifier()
1385 id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1390 fputs("Error:\tInvalid syscall ", trace->output); in trace__validate_ev_qualifier()
1393 fputs(", ", trace->output); in trace__validate_ev_qualifier()
1396 fputs(sc, trace->output); in trace__validate_ev_qualifier()
1399 trace->ev_qualifier_ids.entries[i++] = id; in trace__validate_ev_qualifier()
1404 id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1407 if (nr_allocated == trace->ev_qualifier_ids.nr) { in trace__validate_ev_qualifier()
1411 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
1412 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1415 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
1418 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
1420 trace->ev_qualifier_ids.nr++; in trace__validate_ev_qualifier()
1421 trace->ev_qualifier_ids.entries[i++] = id; in trace__validate_ev_qualifier()
1427 "\nHint:\tand: 'man syscalls'\n", trace->output); in trace__validate_ev_qualifier()
1429 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
1430 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
1475 unsigned char *args, struct trace *trace, in syscall__scnprintf_args() argument
1485 .trace = trace, in syscall__scnprintf_args()
1547 typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel,
1551 static struct syscall *trace__syscall_info(struct trace *trace, in trace__syscall_info() argument
1569 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", in trace__syscall_info()
1575 if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) && in trace__syscall_info()
1576 trace__read_syscall_info(trace, id)) in trace__syscall_info()
1579 if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL)) in trace__syscall_info()
1582 return &trace->syscalls.table[id]; in trace__syscall_info()
1586 fprintf(trace->output, "Problems reading syscall %d", id); in trace__syscall_info()
1587 if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) in trace__syscall_info()
1588 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); in trace__syscall_info()
1589 fputs(" information\n", trace->output); in trace__syscall_info()
1620 static int trace__printf_interrupted_entry(struct trace *trace) in trace__printf_interrupted_entry() argument
1625 if (trace->failure_only || trace->current == NULL) in trace__printf_interrupted_entry()
1628 ttrace = thread__priv(trace->current); in trace__printf_interrupted_entry()
1633 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o… in trace__printf_interrupted_entry()
1634 printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str); in trace__printf_interrupted_entry()
1640 static int trace__fprintf_sample(struct trace *trace, struct perf_evsel *evsel, in trace__fprintf_sample() argument
1645 if (trace->print_sample) { in trace__fprintf_sample()
1648 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", in trace__fprintf_sample()
1657 static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, in trace__sys_enter() argument
1666 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__sys_enter()
1672 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_enter()
1673 ttrace = thread__trace(thread, trace->output); in trace__sys_enter()
1677 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_enter()
1687 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) in trace__sys_enter()
1688 trace__printf_interrupted_entry(trace); in trace__sys_enter()
1695 args, trace, thread); in trace__sys_enter()
1698 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { in trace__sys_enter()
1699 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output); in trace__sys_enter()
1700 fprintf(trace->output, "%-70s)\n", ttrace->entry_str); in trace__sys_enter()
1708 if (trace->current != thread) { in trace__sys_enter()
1709 thread__put(trace->current); in trace__sys_enter()
1710 trace->current = thread__get(thread); in trace__sys_enter()
1718 static int trace__fprintf_sys_enter(struct trace *trace, struct perf_evsel *evsel, in trace__fprintf_sys_enter() argument
1724 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__fprintf_sys_enter()
1731 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__fprintf_sys_enter()
1732 ttrace = thread__trace(thread, trace->output); in trace__fprintf_sys_enter()
1741 syscall__scnprintf_args(sc, msg, sizeof(msg), args, trace, thread); in trace__fprintf_sys_enter()
1742 fprintf(trace->output, "%s", msg); in trace__fprintf_sys_enter()
1749 static int trace__resolve_callchain(struct trace *trace, struct perf_evsel *evsel, in trace__resolve_callchain() argument
1756 trace->max_stack; in trace__resolve_callchain()
1758 if (machine__resolve(trace->host, &al, sample) < 0 || in trace__resolve_callchain()
1765 static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) in trace__fprintf_callchain() argument
1772 return sample__fprintf_callchain(sample, 38, print_opts, &callchain_cursor, trace->output); in trace__fprintf_callchain()
1783 static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, in trace__sys_exit() argument
1792 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__sys_exit()
1798 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_exit()
1799 ttrace = thread__trace(thread, trace->output); in trace__sys_exit()
1803 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_exit()
1805 if (trace->summary) in trace__sys_exit()
1813 ++trace->stats.vfs_getname; in trace__sys_exit()
1818 if (trace__filter_duration(trace, duration)) in trace__sys_exit()
1821 } else if (trace->duration_filter) in trace__sys_exit()
1825 callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor); in trace__sys_exit()
1827 if (callchain_cursor.nr < trace->min_stack) in trace__sys_exit()
1833 if (trace->summary_only || (ret >= 0 && trace->failure_only)) in trace__sys_exit()
1836 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-… in trace__sys_exit()
1839 fprintf(trace->output, "%-70s", ttrace->entry_str); in trace__sys_exit()
1841 fprintf(trace->output, " ... ["); in trace__sys_exit()
1842 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); in trace__sys_exit()
1843 fprintf(trace->output, "]: %s()", sc->name); in trace__sys_exit()
1850 fprintf(trace->output, ") = %ld", ret); in trace__sys_exit()
1857 fprintf(trace->output, ") = -1 %s %s", e, emsg); in trace__sys_exit()
1860 fprintf(trace->output, ") = 0 Timeout"); in trace__sys_exit()
1866 .trace = trace, in trace__sys_exit()
1870 fprintf(trace->output, ") = %s", bf); in trace__sys_exit()
1872 fprintf(trace->output, ") = %#lx", ret); in trace__sys_exit()
1874 struct thread *child = machine__find_thread(trace->host, ret, ret); in trace__sys_exit()
1877 fprintf(trace->output, ") = %ld", ret); in trace__sys_exit()
1879 fprintf(trace->output, " (%s)", thread__comm_str(child)); in trace__sys_exit()
1885 fputc('\n', trace->output); in trace__sys_exit()
1888 trace__fprintf_callchain(trace, sample); in trace__sys_exit()
1899 static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, in trace__vfs_getname() argument
1903 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__vfs_getname()
1960 static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evsel, in trace__sched_stat_runtime() argument
1966 struct thread *thread = machine__findnew_thread(trace->host, in trace__sched_stat_runtime()
1969 struct thread_trace *ttrace = thread__trace(thread, trace->output); in trace__sched_stat_runtime()
1975 trace->runtime_ms += runtime_ms; in trace__sched_stat_runtime()
1981 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", in trace__sched_stat_runtime()
2014 static void bpf_output__fprintf(struct trace *trace, in bpf_output__fprintf() argument
2018 bpf_output__printer, NULL, trace->output); in bpf_output__fprintf()
2021 static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel, in trace__event_handler() argument
2028 callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor); in trace__event_handler()
2030 if (callchain_cursor.nr < trace->min_stack) in trace__event_handler()
2036 trace__printf_interrupted_entry(trace); in trace__event_handler()
2037 trace__fprintf_tstamp(trace, sample->time, trace->output); in trace__event_handler()
2039 if (trace->trace_syscalls) in trace__event_handler()
2040 fprintf(trace->output, "( ): "); in trace__event_handler()
2042 fprintf(trace->output, "%s:", evsel->name); in trace__event_handler()
2045 if (evsel == trace->syscalls.events.augmented) in trace__event_handler()
2046 trace__fprintf_sys_enter(trace, evsel, sample); in trace__event_handler()
2048 bpf_output__fprintf(trace, sample); in trace__event_handler()
2051 trace__fprintf_sys_enter(trace, evsel, sample)) { in trace__event_handler()
2054 trace->output); in trace__event_handler()
2058 fprintf(trace->output, "\n"); in trace__event_handler()
2061 trace__fprintf_callchain(trace, sample); in trace__event_handler()
2085 static int trace__pgfault(struct trace *trace, in trace__pgfault() argument
2097 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__pgfault()
2100 callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor); in trace__pgfault()
2102 if (callchain_cursor.nr < trace->min_stack) in trace__pgfault()
2108 ttrace = thread__trace(thread, trace->output); in trace__pgfault()
2117 if (trace->summary_only) in trace__pgfault()
2122 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output); in trace__pgfault()
2124 fprintf(trace->output, "%sfault [", in trace__pgfault()
2128 print_location(trace->output, sample, &al, false, true); in trace__pgfault()
2130 fprintf(trace->output, "] => "); in trace__pgfault()
2143 print_location(trace->output, sample, &al, true, false); in trace__pgfault()
2145 fprintf(trace->output, " (%c%c)\n", map_type, al.level); in trace__pgfault()
2148 trace__fprintf_callchain(trace, sample); in trace__pgfault()
2158 static void trace__set_base_time(struct trace *trace, in trace__set_base_time() argument
2170 if (trace->base_time == 0 && !trace->full_time && in trace__set_base_time()
2172 trace->base_time = sample->time; in trace__set_base_time()
2181 struct trace *trace = container_of(tool, struct trace, tool); in trace__process_sample() local
2187 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__process_sample()
2191 trace__set_base_time(trace, evsel, sample); in trace__process_sample()
2194 ++trace->nr_events; in trace__process_sample()
2195 handler(trace, evsel, event, sample); in trace__process_sample()
2202 static int trace__record(struct trace *trace, int argc, const char **argv) in trace__record() argument
2232 if (trace->trace_syscalls) { in trace__record()
2248 if (trace->trace_pgfaults & TRACE_PFMAJ) in trace__record()
2252 if (trace->trace_pgfaults & TRACE_PFMIN) in trace__record()
2262 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
2312 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… in trace__handle_event() argument
2318 trace__process_event(trace, trace->host, event, sample); in trace__handle_event()
2322 evsel = perf_evlist__id2evsel(trace->evlist, sample->id); in trace__handle_event()
2324 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); in trace__handle_event()
2328 trace__set_base_time(trace, evsel, sample); in trace__handle_event()
2332 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", in trace__handle_event()
2337 handler(trace, evsel, event, sample); in trace__handle_event()
2341 static int trace__add_syscall_newtp(struct trace *trace) in trace__add_syscall_newtp() argument
2344 struct perf_evlist *evlist = trace->evlist; in trace__add_syscall_newtp()
2361 perf_evsel__config_callchain(sys_enter, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
2362 perf_evsel__config_callchain(sys_exit, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
2367 if (callchain_param.enabled && !trace->kernel_syscallchains) { in trace__add_syscall_newtp()
2376 trace->syscalls.events.sys_enter = sys_enter; in trace__add_syscall_newtp()
2377 trace->syscalls.events.sys_exit = sys_exit; in trace__add_syscall_newtp()
2390 static int trace__set_ev_qualifier_filter(struct trace *trace) in trace__set_ev_qualifier_filter() argument
2394 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, in trace__set_ev_qualifier_filter()
2395 trace->ev_qualifier_ids.nr, in trace__set_ev_qualifier_filter()
2396 trace->ev_qualifier_ids.entries); in trace__set_ev_qualifier_filter()
2401 if (!perf_evsel__append_tp_filter(trace->syscalls.events.sys_enter, in trace__set_ev_qualifier_filter()
2403 sys_exit = trace->syscalls.events.sys_exit; in trace__set_ev_qualifier_filter()
2415 static int trace__set_filter_loop_pids(struct trace *trace) in trace__set_filter_loop_pids() argument
2421 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]); in trace__set_filter_loop_pids()
2424 struct thread *parent = machine__find_thread(trace->host, thread->ppid, thread->ppid); in trace__set_filter_loop_pids()
2436 return perf_evlist__set_filter_pids(trace->evlist, nr, pids); in trace__set_filter_loop_pids()
2439 static int trace__run(struct trace *trace, int argc, const char **argv) in trace__run() argument
2441 struct perf_evlist *evlist = trace->evlist; in trace__run()
2448 trace->live = true; in trace__run()
2450 if (trace->trace_syscalls && trace__add_syscall_newtp(trace)) in trace__run()
2453 if (trace->trace_syscalls) in trace__run()
2454 trace->vfs_getname = perf_evlist__add_vfs_getname(evlist); in trace__run()
2456 if ((trace->trace_pgfaults & TRACE_PFMAJ)) { in trace__run()
2460 perf_evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param); in trace__run()
2464 if ((trace->trace_pgfaults & TRACE_PFMIN)) { in trace__run()
2468 perf_evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param); in trace__run()
2472 if (trace->sched && in trace__run()
2481 * trace -G A -e sched:*switch in trace__run()
2486 * trace -e sched:*switch -G A in trace__run()
2494 * trace -G A -e sched:*switch -G B in trace__run()
2502 if (trace->cgroup) in trace__run()
2503 evlist__set_default_cgroup(trace->evlist, trace->cgroup); in trace__run()
2505 err = perf_evlist__create_maps(evlist, &trace->opts.target); in trace__run()
2507 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); in trace__run()
2511 err = trace__symbols_init(trace, evlist); in trace__run()
2513 fprintf(trace->output, "Problems initializing symbol libraries!\n"); in trace__run()
2517 perf_evlist__config(evlist, &trace->opts, &callchain_param); in trace__run()
2523 err = perf_evlist__prepare_workload(evlist, &trace->opts.target, in trace__run()
2526 fprintf(trace->output, "Couldn't run the workload!\n"); in trace__run()
2551 if (trace->filter_pids.nr > 0) in trace__run()
2552 err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); in trace__run()
2554 err = trace__set_filter_loop_pids(trace); in trace__run()
2559 if (trace->ev_qualifier_ids.nr > 0) { in trace__run()
2560 err = trace__set_ev_qualifier_filter(trace); in trace__run()
2565 trace->syscalls.events.sys_exit->filter); in trace__run()
2572 err = perf_evlist__mmap(evlist, trace->opts.mmap_pages); in trace__run()
2576 if (!target__none(&trace->opts.target) && !trace->opts.initial_delay) in trace__run()
2582 if (trace->opts.initial_delay) { in trace__run()
2583 usleep(trace->opts.initial_delay * 1000); in trace__run()
2587 trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 || in trace__run()
2600 evsel->attr.sample_max_stack = trace->max_stack; in trace__run()
2603 before = trace->nr_events; in trace__run()
2616 ++trace->nr_events; in trace__run()
2620 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); in trace__run()
2624 trace__handle_event(trace, event, &sample); in trace__run()
2639 if (trace->nr_events == before) { in trace__run()
2653 thread__zput(trace->current); in trace__run()
2658 if (trace->summary) in trace__run()
2659 trace__fprintf_thread_summary(trace, trace->output); in trace__run()
2661 if (trace->show_tool_stats) { in trace__run()
2662 fprintf(trace->output, "Stats:\n " in trace__run()
2665 trace->stats.vfs_getname, in trace__run()
2666 trace->stats.proc_getname); in trace__run()
2671 trace__symbols__exit(trace); in trace__run()
2674 cgroup__put(trace->cgroup); in trace__run()
2675 trace->evlist = NULL; in trace__run()
2676 trace->live = false; in trace__run()
2697 fprintf(trace->output, "%s\n", errbuf); in trace__run()
2701 fprintf(trace->output, in trace__run()
2708 fprintf(trace->output, "Not enough memory to run!\n"); in trace__run()
2712 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno)); in trace__run()
2716 static int trace__replay(struct trace *trace) in trace__replay() argument
2726 .force = trace->force, in trace__replay()
2732 trace->tool.sample = trace__process_sample; in trace__replay()
2733 trace->tool.mmap = perf_event__process_mmap; in trace__replay()
2734 trace->tool.mmap2 = perf_event__process_mmap2; in trace__replay()
2735 trace->tool.comm = perf_event__process_comm; in trace__replay()
2736 trace->tool.exit = perf_event__process_exit; in trace__replay()
2737 trace->tool.fork = perf_event__process_fork; in trace__replay()
2738 trace->tool.attr = perf_event__process_attr; in trace__replay()
2739 trace->tool.tracing_data = perf_event__process_tracing_data; in trace__replay()
2740 trace->tool.build_id = perf_event__process_build_id; in trace__replay()
2741 trace->tool.namespaces = perf_event__process_namespaces; in trace__replay()
2743 trace->tool.ordered_events = true; in trace__replay()
2744 trace->tool.ordering_requires_timestamps = true; in trace__replay()
2747 trace->multiple_threads = true; in trace__replay()
2749 session = perf_session__new(&data, false, &trace->tool); in trace__replay()
2753 if (trace->opts.target.pid) in trace__replay()
2754 symbol_conf.pid_list_str = strdup(trace->opts.target.pid); in trace__replay()
2756 if (trace->opts.target.tid) in trace__replay()
2757 symbol_conf.tid_list_str = strdup(trace->opts.target.tid); in trace__replay()
2762 trace->host = &session->machines.host; in trace__replay()
2808 else if (trace->summary) in trace__replay()
2809 trace__fprintf_thread_summary(trace, trace->output); in trace__replay()
2841 struct trace *trace, FILE *fp) in thread__dump_stats() argument
2869 sc = &trace->syscalls.table[syscall_stats_entry->syscall]; in thread__dump_stats()
2883 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) in trace__fprintf_thread() argument
2892 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; in trace__fprintf_thread()
2901 if (trace->sched) in trace__fprintf_thread()
2906 printed += thread__dump_stats(ttrace, trace, fp); in trace__fprintf_thread()
2923 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) in trace__fprintf_thread_summary() argument
2930 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i); in trace__fprintf_thread_summary()
2938 printed += trace__fprintf_thread(fp, threads_entry->thread, trace); in trace__fprintf_thread_summary()
2948 struct trace *trace = opt->value; in trace__set_duration() local
2950 trace->duration_filter = atof(str); in trace__set_duration()
2959 struct trace *trace = opt->value; in trace__set_filter_pids() local
2969 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; in trace__set_filter_pids()
2970 trace->filter_pids.entries = calloc(i, sizeof(pid_t)); in trace__set_filter_pids()
2972 if (trace->filter_pids.entries == NULL) in trace__set_filter_pids()
2975 trace->filter_pids.entries[0] = getpid(); in trace__set_filter_pids()
2977 for (i = 1; i < trace->filter_pids.nr; ++i) in trace__set_filter_pids()
2978 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; in trace__set_filter_pids()
2986 static int trace__open_output(struct trace *trace, const char *filename) in trace__open_output() argument
2998 trace->output = fopen(filename, "w"); in trace__open_output()
3000 return trace->output == NULL ? -errno : 0; in trace__open_output()
3061 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
3069 struct trace *trace = (struct trace *)opt->value; in trace__parse_events_option() local
3081 trace->not_ev_qualifier = true; in trace__parse_events_option()
3089 if (syscalltbl__id(trace->sctbl, s) >= 0 || in trace__parse_events_option()
3090 syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) { in trace__parse_events_option()
3119 trace->ev_qualifier = strlist__new(lists[1], &slist_config); in trace__parse_events_option()
3120 if (trace->ev_qualifier == NULL) { in trace__parse_events_option()
3121 fputs("Not enough memory to parse event qualifier", trace->output); in trace__parse_events_option()
3125 if (trace__validate_ev_qualifier(trace)) in trace__parse_events_option()
3127 trace->trace_syscalls = true; in trace__parse_events_option()
3133 struct option o = OPT_CALLBACK('e', "event", &trace->evlist, "event", in trace__parse_events_option()
3147 struct trace *trace = opt->value; in trace__parse_cgroups() local
3149 if (!list_empty(&trace->evlist->entries)) in trace__parse_cgroups()
3152 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str); in trace__parse_cgroups()
3160 "perf trace [<options>] [<command>]", in cmd_trace()
3161 "perf trace [<options>] -- <command> [<options>]", in cmd_trace()
3162 "perf trace record [<options>] [<command>]", in cmd_trace()
3163 "perf trace record [<options>] -- <command> [<options>]", in cmd_trace()
3166 struct trace trace = { in cmd_trace() local
3189 OPT_CALLBACK('e', "event", &trace, "event", in cmd_trace()
3192 OPT_BOOLEAN(0, "comm", &trace.show_comm, in cmd_trace()
3194 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), in cmd_trace()
3195 OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace", in cmd_trace()
3199 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", in cmd_trace()
3200 "trace events on existing process id"), in cmd_trace()
3201 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", in cmd_trace()
3202 "trace events on existing thread id"), in cmd_trace()
3203 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids", in cmd_trace()
3205 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, in cmd_trace()
3207 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", in cmd_trace()
3209 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, in cmd_trace()
3211 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", in cmd_trace()
3214 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", in cmd_trace()
3216 OPT_CALLBACK(0, "duration", &trace, "float", in cmd_trace()
3219 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), in cmd_trace()
3221 OPT_BOOLEAN('T', "time", &trace.full_time, in cmd_trace()
3223 OPT_BOOLEAN(0, "failure", &trace.failure_only, in cmd_trace()
3225 OPT_BOOLEAN('s', "summary", &trace.summary_only, in cmd_trace()
3227 OPT_BOOLEAN('S', "with-summary", &trace.summary, in cmd_trace()
3229 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", in cmd_trace()
3230 "Trace pagefaults", parse_pagefaults, "maj"), in cmd_trace()
3231 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), in cmd_trace()
3232 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), in cmd_trace()
3233 OPT_CALLBACK(0, "call-graph", &trace.opts, in cmd_trace()
3236 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, in cmd_trace()
3238 OPT_UINTEGER(0, "min-stack", &trace.min_stack, in cmd_trace()
3241 OPT_UINTEGER(0, "max-stack", &trace.max_stack, in cmd_trace()
3245 OPT_BOOLEAN(0, "print-sample", &trace.print_sample, in cmd_trace()
3247 OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout, in cmd_trace()
3249 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only", in cmd_trace()
3251 OPT_UINTEGER('D', "delay", &trace.opts.initial_delay, in cmd_trace()
3266 trace.evlist = perf_evlist__new(); in cmd_trace()
3267 trace.sctbl = syscalltbl__new(); in cmd_trace()
3269 if (trace.evlist == NULL || trace.sctbl == NULL) { in cmd_trace()
3278 if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) { in cmd_trace()
3283 evsel = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__"); in cmd_trace()
3285 bpf__strerror_setup_output_event(trace.evlist, PTR_ERR(evsel), bf, sizeof(bf)); in cmd_trace()
3286 pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf); in cmd_trace()
3294 trace.syscalls.events.augmented = evsel; in cmd_trace()
3297 err = bpf__setup_stdout(trace.evlist); in cmd_trace()
3299 bpf__strerror_setup_stdout(trace.evlist, err, bf, sizeof(bf)); in cmd_trace()
3306 if (trace.trace_pgfaults) { in cmd_trace()
3307 trace.opts.sample_address = true; in cmd_trace()
3308 trace.opts.sample_time = true; in cmd_trace()
3311 if (trace.opts.mmap_pages == UINT_MAX) in cmd_trace()
3314 if (trace.max_stack == UINT_MAX) { in cmd_trace()
3315 trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack(); in cmd_trace()
3320 if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) { in cmd_trace()
3321 record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false); in cmd_trace()
3327 trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4; in cmd_trace()
3332 if (trace.evlist->nr_entries > 0) { in cmd_trace()
3333 evlist__set_evsel_handler(trace.evlist, trace__event_handler); in cmd_trace()
3334 if (evlist__set_syscall_tp_fields(trace.evlist)) { in cmd_trace()
3341 return trace__record(&trace, argc-1, &argv[1]); in cmd_trace()
3344 if (trace.summary_only) in cmd_trace()
3345 trace.summary = trace.summary_only; in cmd_trace()
3347 if (!trace.trace_syscalls && !trace.trace_pgfaults && in cmd_trace()
3348 trace.evlist->nr_entries == 0 /* Was --events used? */) { in cmd_trace()
3349 trace.trace_syscalls = true; in cmd_trace()
3353 err = trace__open_output(&trace, output_name); in cmd_trace()
3360 err = target__validate(&trace.opts.target); in cmd_trace()
3362 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
3363 fprintf(trace.output, "%s", bf); in cmd_trace()
3367 err = target__parse_uid(&trace.opts.target); in cmd_trace()
3369 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
3370 fprintf(trace.output, "%s", bf); in cmd_trace()
3374 if (!argc && target__none(&trace.opts.target)) in cmd_trace()
3375 trace.opts.target.system_wide = true; in cmd_trace()
3378 err = trace__replay(&trace); in cmd_trace()
3380 err = trace__run(&trace, argc, argv); in cmd_trace()
3384 fclose(trace.output); in cmd_trace()