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'")
57 #include "trace/beauty/beauty.h"
58 #include "trace-event.h"
128 struct trace { struct
293 * The evsel->priv as used by 'perf trace'
729 #include "trace/beauty/generated/fsconfig_arrays.c"
899 #include "trace/beauty/arch_errno_names.c"
900 #include "trace/beauty/eventfd.c"
901 #include "trace/beauty/futex_op.c"
902 #include "trace/beauty/futex_val3.c"
903 #include "trace/beauty/mmap.c"
904 #include "trace/beauty/mode_t.c"
905 #include "trace/beauty/msg_flags.c"
906 #include "trace/beauty/open_flags.c"
907 #include "trace/beauty/perf_event_open.c"
908 #include "trace/beauty/pid.c"
909 #include "trace/beauty/sched_policy.c"
910 #include "trace/beauty/seccomp.c"
911 #include "trace/beauty/signum.c"
912 #include "trace/beauty/socket_type.c"
913 #include "trace/beauty/waitid_options.c"
1436 struct trace *trace) in thread__fd_path() argument
1440 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1447 if (!trace->live) in thread__fd_path()
1449 ++trace->stats.proc_getname; in thread__fd_path()
1461 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1469 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) in pid__scnprintf_fd() argument
1472 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1475 const char *path = thread__fd_path(thread, fd, trace); in pid__scnprintf_fd()
1532 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1539 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1541 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1544 static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in __trace__fprintf_tstamp() argument
1546 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1557 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1560 return __trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_tstamp()
1581 static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp) in trace__fprintf_comm_tid() argument
1585 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1586 if (trace->show_comm) in trace__fprintf_comm_tid()
1594 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1599 if (trace->show_tstamp) in trace__fprintf_entry_head()
1600 printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1601 if (trace->show_duration) in trace__fprintf_entry_head()
1603 return printed + trace__fprintf_comm_tid(trace, thread, fp); in trace__fprintf_entry_head()
1606 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1613 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1630 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1631 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1652 static int trace__symbols_init(struct trace *trace, struct evlist *evlist) in trace__symbols_init() argument
1659 trace->host = machine__new_host(); in trace__symbols_init()
1660 if (trace->host == NULL) in trace__symbols_init()
1665 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
1669 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1679 static void trace__symbols__exit(struct trace *trace) in trace__symbols__exit() argument
1681 machine__exit(trace->host); in trace__symbols__exit()
1682 trace->host = NULL; in trace__symbols__exit()
1794 static int trace__read_syscall_info(struct trace *trace, int id) in trace__read_syscall_info() argument
1798 const char *name = syscalltbl__name(trace->sctbl, id); in trace__read_syscall_info()
1801 if (trace->syscalls.table == NULL) { in trace__read_syscall_info()
1802 trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); in trace__read_syscall_info()
1803 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1807 if (id > trace->sctbl->syscalls.max_id || (id == 0 && trace->syscalls.table == NULL)) { in trace__read_syscall_info()
1809 struct syscall *table = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); in trace__read_syscall_info()
1815 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1818 …memset(table + trace->sctbl->syscalls.max_id + 1, 0, (id - trace->sctbl->syscalls.max_id) * sizeof… in trace__read_syscall_info()
1820 trace->syscalls.table = table; in trace__read_syscall_info()
1821 trace->sctbl->syscalls.max_id = id; in trace__read_syscall_info()
1824 sc = trace->syscalls.table + id; in trace__read_syscall_info()
1845 * Fails to read trace point format via sysfs node, so the trace point in trace__read_syscall_info()
1893 static int trace__validate_ev_qualifier(struct trace *trace) in trace__validate_ev_qualifier() argument
1898 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
1900 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
1901 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1903 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
1905 trace->output); in trace__validate_ev_qualifier()
1910 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
1912 int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; in trace__validate_ev_qualifier()
1915 id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1930 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1935 id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1942 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
1943 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1946 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
1949 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
1951 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1955 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
1956 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
1962 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
1963 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
1967 static __maybe_unused bool trace__syscall_enabled(struct trace *trace, int id) in trace__syscall_enabled() argument
1971 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
1974 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
1975 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
1978 return !trace->not_ev_qualifier; in trace__syscall_enabled()
1980 return trace->not_ev_qualifier; in trace__syscall_enabled()
2012 * in tools/perf/trace/beauty/mount_flags.c
2036 struct trace *trace, struct thread *thread) in syscall__scnprintf_args() argument
2049 .trace = trace, in syscall__scnprintf_args()
2051 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2084 !trace->show_zeros && in syscall__scnprintf_args()
2094 if (trace->show_arg_names) in syscall__scnprintf_args()
2123 typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel,
2127 static struct syscall *trace__syscall_info(struct trace *trace, argument
2146 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",
2155 if (id > trace->sctbl->syscalls.max_id) {
2157 if (id >= trace->sctbl->syscalls.max_id) {
2163 err = trace__read_syscall_info(trace, id);
2169 if ((trace->syscalls.table == NULL || trace->syscalls.table[id].name == NULL) &&
2170 (err = trace__read_syscall_info(trace, id)) != 0)
2173 if (trace->syscalls.table && trace->syscalls.table[id].nonexistent)
2176 return &trace->syscalls.table[id];
2181 …fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, str_error_r(-err, sbuf, s…
2182 if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name != NULL)
2183 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);
2184 fputs(" information\n", trace->output);
2249 static int trace__printf_interrupted_entry(struct trace *trace) argument
2255 if (trace->failure_only || trace->current == NULL)
2258 ttrace = thread__priv(trace->current);
2263 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o…
2264 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str);
2266 if (len < trace->args_alignment - 4)
2267 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " ");
2269 printed += fprintf(trace->output, " ...\n");
2272 ++trace->nr_events_printed;
2277 static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, argument
2282 if (trace->print_sample) {
2285 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n",
2328 static int trace__sys_enter(struct trace *trace, struct evsel *evsel, argument
2339 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2345 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2346 ttrace = thread__trace(thread, trace->output);
2350 trace__fprintf_sample(trace, evsel, sample, thread);
2360 if (!(trace->duration_filter || trace->summary_only || trace->min_stack))
2361 trace__printf_interrupted_entry(trace);
2372 if (evsel != trace->syscalls.events.sys_enter)
2373 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2379 args, augmented_args, augmented_args_size, trace, thread);
2382 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) {
2385 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output);
2386 printed = fprintf(trace->output, "%s)", ttrace->entry_str);
2387 if (trace->args_alignment > printed)
2388 alignment = trace->args_alignment - printed;
2389 fprintf(trace->output, "%*s= ?\n", alignment, " ");
2397 if (trace->current != thread) {
2398 thread__put(trace->current);
2399 trace->current = thread__get(thread);
2407 static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, argument
2413 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2421 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2422 ttrace = thread__trace(thread, trace->output);
2431 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2432 …syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, th…
2433 fprintf(trace->output, "%s", msg);
2440 static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, argument
2447 trace->max_stack;
2451 if (machine__resolve(trace->host, &al, sample) < 0)
2460 static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) argument
2467 …chain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output);
2477 static int trace__sys_exit(struct trace *trace, struct evsel *evsel, argument
2486 int alignment = trace->args_alignment;
2487 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2493 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2494 ttrace = thread__trace(thread, trace->output);
2498 trace__fprintf_sample(trace, evsel, sample, thread);
2502 if (trace->summary)
2503 thread__update_stats(thread, ttrace, id, sample, ret, trace->errno_summary);
2505 if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) {
2508 ++trace->stats.vfs_getname;
2513 if (trace__filter_duration(trace, duration))
2516 } else if (trace->duration_filter)
2522 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor);
2524 if (cursor->nr < trace->min_stack)
2530 if (trace->summary_only || (ret >= 0 && trace->failure_only))
2533 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-…
2536 printed = fprintf(trace->output, "%s", ttrace->entry_str);
2538 printed += fprintf(trace->output, " ... [");
2539 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued");
2541 printed += fprintf(trace->output, "]: %s()", sc->name);
2551 fprintf(trace->output, ")%*s= ", alignment, " ");
2557 fprintf(trace->output, "%ld", ret);
2564 fprintf(trace->output, "-1 %s (%s)", e, emsg);
2567 fprintf(trace->output, "0 (Timeout)");
2573 .trace = trace,
2577 fprintf(trace->output, "%s", bf);
2579 fprintf(trace->output, "%#lx", ret);
2581 struct thread *child = machine__find_thread(trace->host, ret, ret);
2584 fprintf(trace->output, "%ld", ret);
2586 fprintf(trace->output, " (%s)", thread__comm_str(child));
2592 fputc('\n', trace->output);
2598 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX)
2602 trace__fprintf_callchain(trace, sample);
2613 static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, argument
2617 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2674 static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, argument
2680 struct thread *thread = machine__findnew_thread(trace->host,
2683 struct thread_trace *ttrace = thread__trace(thread, trace->output);
2689 trace->runtime_ms += runtime_ms;
2695 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n",
2728 static void bpf_output__fprintf(struct trace *trace, argument
2732 bpf_output__printer, NULL, trace->output);
2733 ++trace->nr_events_printed;
2736 static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample… argument
2753 .trace = trace,
2755 .show_string_prefix = trace->show_string_prefix,
2790 !trace->show_zeros &&
2799 if (trace->show_arg_names)
2805 return printed + fprintf(trace->output, "%s", bf);
2808 static int trace__event_handler(struct trace *trace, struct evsel *evsel, argument
2823 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2828 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor);
2830 if (cursor->nr < trace->min_stack)
2836 trace__printf_interrupted_entry(trace);
2837 trace__fprintf_tstamp(trace, sample->time, trace->output);
2839 if (trace->trace_syscalls && trace->show_duration)
2840 fprintf(trace->output, "( ): ");
2843 trace__fprintf_comm_tid(trace, thread, trace->output);
2845 if (evsel == trace->syscalls.events.bpf_output) {
2847 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2850 fprintf(trace->output, "%s(", sc->name);
2851 trace__fprintf_sys_enter(trace, evsel, sample);
2852 fputc(')', trace->output);
2863 fprintf(trace->output, "%s(", evsel->name);
2866 bpf_output__fprintf(trace, sample);
2869 trace__fprintf_sys_enter(trace, evsel, sample)) {
2870 if (trace->libtraceevent_print) {
2873 trace->output);
2875 trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0);
2881 fprintf(trace->output, ")\n");
2884 trace__fprintf_callchain(trace, sample);
2888 ++trace->nr_events_printed;
2916 static int trace__pgfault(struct trace *trace, argument
2929 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2934 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor);
2936 if (cursor->nr < trace->min_stack)
2942 ttrace = thread__trace(thread, trace->output);
2951 if (trace->summary_only)
2956 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
2958 fprintf(trace->output, "%sfault [",
2962 print_location(trace->output, sample, &al, false, true);
2964 fprintf(trace->output, "] => ");
2977 print_location(trace->output, sample, &al, true, false);
2979 fprintf(trace->output, " (%c%c)\n", map_type, al.level);
2982 trace__fprintf_callchain(trace, sample);
2986 ++trace->nr_events_printed;
2995 static void trace__set_base_time(struct trace *trace, argument
3007 if (trace->base_time == 0 && !trace->full_time &&
3009 trace->base_time = sample->time;
3018 struct trace *trace = container_of(tool, struct trace, tool); local
3024 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
3028 trace__set_base_time(trace, evsel, sample);
3031 ++trace->nr_events;
3032 handler(trace, evsel, event, sample);
3039 static int trace__record(struct trace *trace, int argc, const char **argv) argument
3071 if (trace->trace_syscalls) {
3089 if (trace->trace_pgfaults & TRACE_PFMAJ)
3093 if (trace->trace_pgfaults & TRACE_PFMIN)
3107 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
3170 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… argument
3176 trace__process_event(trace, trace->host, event, sample);
3180 evsel = evlist__id2evsel(trace->evlist, sample->id);
3182 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id);
3186 if (evswitch__discard(&trace->evswitch, evsel))
3189 trace__set_base_time(trace, evsel, sample);
3193 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
3198 handler(trace, evsel, event, sample);
3201 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX)
3205 static int trace__add_syscall_newtp(struct trace *trace) argument
3208 struct evlist *evlist = trace->evlist;
3225 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param);
3226 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param);
3231 if (callchain_param.enabled && !trace->kernel_syscallchains) {
3240 trace->syscalls.events.sys_enter = sys_enter;
3241 trace->syscalls.events.sys_exit = sys_exit;
3254 static int trace__set_ev_qualifier_tp_filter(struct trace *trace) argument
3258 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier,
3259 trace->ev_qualifier_ids.nr,
3260 trace->ev_qualifier_ids.entries);
3265 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) {
3266 sys_exit = trace->syscalls.events.sys_exit;
3279 static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) argument
3284 if (trace->skel->obj == NULL)
3287 bpf_object__for_each_program(pos, trace->skel->obj) {
3298 static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc, argument
3306 prog = trace__find_bpf_program_by_title(trace, default_prog_name);
3311 prog = trace__find_bpf_program_by_title(trace, default_prog_name);
3318 prog = trace__find_bpf_program_by_title(trace, prog_name);
3328 return trace->skel->progs.syscall_unaugmented;
3331 static void trace__init_syscall_bpf_progs(struct trace *trace, int id) argument
3333 struct syscall *sc = trace__syscall_info(trace, NULL, id);
3338 …sc->bpf_prog.sys_enter = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3339 …sc->bpf_prog.sys_exit = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3342 static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id) argument
3344 struct syscall *sc = trace__syscall_info(trace, NULL, id);
3345 …return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->skel->progs.syscall_u…
3348 static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id) argument
3350 struct syscall *sc = trace__syscall_info(trace, NULL, id);
3351 …return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->skel->progs.syscall_un…
3354 static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *s… argument
3370 for (id = 0; id < trace->sctbl->syscalls.nr_entries; ++id) {
3371 struct syscall *pair = trace__syscall_info(trace, NULL, id);
3376 pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)
3441 …pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_ent…
3442 if (pair_prog == trace->skel->progs.syscall_unaugmented)
3455 static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace) argument
3457 int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter);
3458 int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit);
3461 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3464 if (!trace__syscall_enabled(trace, key))
3467 trace__init_syscall_bpf_progs(trace, key);
3470 prog_fd = trace__bpf_prog_sys_enter_fd(trace, key);
3474 prog_fd = trace__bpf_prog_sys_exit_fd(trace, key);
3508 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3509 struct syscall *sc = trace__syscall_info(trace, NULL, key);
3520 if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented)
3527 pair_prog = trace__find_usable_bpf_prog_entry(trace, sc);
3547 static int trace__set_ev_qualifier_filter(struct trace *trace) argument
3549 if (trace->syscalls.events.sys_enter)
3550 return trace__set_ev_qualifier_tp_filter(trace);
3572 static int trace__set_filter_loop_pids(struct trace *trace) argument
3578 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]);
3581 struct thread *parent = machine__find_thread(trace->host,
3596 err = evlist__append_tp_filter_pids(trace->evlist, nr, pids);
3597 if (!err && trace->filter_pids.map)
3598 err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids);
3603 static int trace__set_filter_pids(struct trace *trace) argument
3612 if (trace->filter_pids.nr > 0) {
3613 err = evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr,
3614 trace->filter_pids.entries);
3615 if (!err && trace->filter_pids.map) {
3616 err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
3617 trace->filter_pids.entries);
3619 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
3620 err = trace__set_filter_loop_pids(trace);
3626 static int __trace__deliver_event(struct trace *trace, union perf_event *event) argument
3628 struct evlist *evlist = trace->evlist;
3633 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err);
3635 trace__handle_event(trace, event, &sample);
3640 static int __trace__flush_events(struct trace *trace) argument
3642 u64 first = ordered_events__first_time(&trace->oe.data);
3643 u64 flush = trace->oe.last - NSEC_PER_SEC;
3647 return ordered_events__flush_time(&trace->oe.data, flush);
3652 static int trace__flush_events(struct trace *trace) argument
3654 return !trace->sort_events ? 0 : __trace__flush_events(trace);
3657 static int trace__deliver_event(struct trace *trace, union perf_event *event) argument
3661 if (!trace->sort_events)
3662 return __trace__deliver_event(trace, event);
3664 err = evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last);
3668 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0, NULL);
3672 return trace__flush_events(trace);
3678 struct trace *trace = container_of(oe, struct trace, oe.data); local
3680 return __trace__deliver_event(trace, event->event);
3698 static int trace__expand_filter(struct trace *trace __maybe_unused, struct evsel *evsel)
3796 static int trace__expand_filters(struct trace *trace, struct evsel **err_evsel) argument
3798 struct evlist *evlist = trace->evlist;
3805 if (trace__expand_filter(trace, evsel)) {
3814 static int trace__run(struct trace *trace, int argc, const char **argv) argument
3816 struct evlist *evlist = trace->evlist;
3823 trace->live = true;
3825 if (!trace->raw_augmented_syscalls) {
3826 if (trace->trace_syscalls && trace__add_syscall_newtp(trace))
3829 if (trace->trace_syscalls)
3830 trace->vfs_getname = evlist__add_vfs_getname(evlist);
3833 if ((trace->trace_pgfaults & TRACE_PFMAJ)) {
3837 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param);
3841 if ((trace->trace_pgfaults & TRACE_PFMIN)) {
3845 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param);
3850 trace->opts.ignore_missing_thread = trace->opts.target.uid != UINT_MAX || trace->opts.target.pid;
3852 if (trace->sched &&
3859 * trace -G A -e sched:*switch
3864 * trace -e sched:*switch -G A
3872 * trace -G A -e sched:*switch -G B
3880 if (trace->cgroup)
3881 evlist__set_default_cgroup(trace->evlist, trace->cgroup);
3883 err = evlist__create_maps(evlist, &trace->opts.target);
3885 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n");
3889 err = trace__symbols_init(trace, evlist);
3891 fprintf(trace->output, "Problems initializing symbol libraries!\n");
3895 evlist__config(evlist, &trace->opts, &callchain_param);
3898 err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL);
3900 fprintf(trace->output, "Couldn't run the workload!\n");
3910 if (trace->syscalls.events.bpf_output) {
3917 perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) {
3918 bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__,
3920 xyarray__entry(trace->syscalls.events.bpf_output->core.fd,
3926 err = trace__set_filter_pids(trace);
3931 if (trace->skel && trace->skel->progs.sys_enter)
3932 trace__init_syscalls_bpf_prog_array_maps(trace);
3935 if (trace->ev_qualifier_ids.nr > 0) {
3936 err = trace__set_ev_qualifier_filter(trace);
3940 if (trace->syscalls.events.sys_exit) {
3942 trace->syscalls.events.sys_exit->filter);
3957 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(trace->sctbl, "close"));
3959 err = trace__expand_filters(trace, &evsel);
3966 err = evlist__mmap(evlist, trace->opts.mmap_pages);
3970 if (!target__none(&trace->opts.target) && !trace->opts.target.initial_delay)
3976 if (trace->opts.target.initial_delay) {
3977 usleep(trace->opts.target.initial_delay * 1000);
3981 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
3994 evsel->core.attr.sample_max_stack = trace->max_stack;
3997 before = trace->nr_events;
4008 ++trace->nr_events;
4010 err = trace__deliver_event(trace, event);
4027 if (trace->nr_events == before) {
4036 if (trace__flush_events(trace))
4044 thread__zput(trace->current);
4048 if (trace->sort_events)
4049 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL);
4052 if (trace->summary)
4053 trace__fprintf_thread_summary(trace, trace->output);
4055 if (trace->show_tool_stats) {
4056 fprintf(trace->output, "Stats:\n "
4059 trace->stats.vfs_getname,
4060 trace->stats.proc_getname);
4065 trace__symbols__exit(trace);
4068 cgroup__put(trace->cgroup);
4069 trace->evlist = NULL;
4070 trace->live = false;
4091 fprintf(trace->output, "%s\n", errbuf);
4095 fprintf(trace->output,
4102 fprintf(trace->output, "Not enough memory to run!\n");
4106 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno));
4110 static int trace__replay(struct trace *trace) argument
4118 .force = trace->force,
4124 trace->tool.sample = trace__process_sample;
4125 trace->tool.mmap = perf_event__process_mmap;
4126 trace->tool.mmap2 = perf_event__process_mmap2;
4127 trace->tool.comm = perf_event__process_comm;
4128 trace->tool.exit = perf_event__process_exit;
4129 trace->tool.fork = perf_event__process_fork;
4130 trace->tool.attr = perf_event__process_attr;
4131 trace->tool.tracing_data = perf_event__process_tracing_data;
4132 trace->tool.build_id = perf_event__process_build_id;
4133 trace->tool.namespaces = perf_event__process_namespaces;
4135 trace->tool.ordered_events = true;
4136 trace->tool.ordering_requires_timestamps = true;
4139 trace->multiple_threads = true;
4141 session = perf_session__new(&data, &trace->tool);
4145 if (trace->opts.target.pid)
4146 symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
4148 if (trace->opts.target.tid)
4149 symbol_conf.tid_list_str = strdup(trace->opts.target.tid);
4154 trace->host = &session->machines.host;
4161 trace->syscalls.events.sys_enter = evsel;
4174 trace->syscalls.events.sys_exit = evsel;
4198 else if (trace->summary)
4199 trace__fprintf_thread_summary(trace, trace->output);
4231 struct trace *trace, FILE *fp) argument
4259 sc = &trace->syscalls.table[syscall_stats_entry->syscall];
4265 if (trace->errno_summary && stats->nr_failures) {
4270 …fprintf(fp, "\t\t\t\t%s: %d\n", perf_env__arch_strerrno(trace->host->env, e + 1), stats->errnos[e]…
4282 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) argument
4291 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0;
4300 if (trace->sched)
4305 printed += thread__dump_stats(ttrace, trace, fp);
4324 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) argument
4331 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i);
4339 printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
4349 struct trace *trace = opt->value; local
4351 trace->duration_filter = atof(str);
4360 struct trace *trace = opt->value; local
4370 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
4371 trace->filter_pids.entries = calloc(i, sizeof(pid_t));
4373 if (trace->filter_pids.entries == NULL)
4376 trace->filter_pids.entries[0] = getpid();
4378 for (i = 1; i < trace->filter_pids.nr; ++i)
4379 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
4387 static int trace__open_output(struct trace *trace, const char *filename) argument
4399 trace->output = fopen(filename, "w");
4401 return trace->output == NULL ? -errno : 0;
4489 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
4497 struct trace *trace = (struct trace *)opt->value; local
4510 trace->not_ev_qualifier = true;
4518 if (syscalltbl__id(trace->sctbl, s) >= 0 ||
4519 syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) {
4555 trace->ev_qualifier = strlist__new(lists[1], &slist_config);
4556 if (trace->ev_qualifier == NULL) {
4557 fputs("Not enough memory to parse event qualifier", trace->output);
4561 if (trace__validate_ev_qualifier(trace))
4563 trace->trace_syscalls = true;
4570 .evlistp = &trace->evlist,
4589 struct trace *trace = opt->value; local
4591 if (!list_empty(&trace->evlist->core.entries)) {
4593 .value = &trace->evlist,
4597 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
4604 struct trace *trace = arg; local
4607 if (!strcmp(var, "trace.add_events")) {
4608 trace->perfconfig_events = strdup(value);
4609 if (trace->perfconfig_events == NULL) {
4610 pr_err("Not enough memory for %s\n", "trace.add_events");
4613 } else if (!strcmp(var, "trace.show_timestamp")) {
4614 trace->show_tstamp = perf_config_bool(var, value);
4615 } else if (!strcmp(var, "trace.show_duration")) {
4616 trace->show_duration = perf_config_bool(var, value);
4617 } else if (!strcmp(var, "trace.show_arg_names")) {
4618 trace->show_arg_names = perf_config_bool(var, value);
4619 if (!trace->show_arg_names)
4620 trace->show_zeros = true;
4621 } else if (!strcmp(var, "trace.show_zeros")) {
4623 if (!trace->show_arg_names && !new_show_zeros) {
4624 pr_warning("trace.show_zeros has to be set when trace.show_arg_names=no\n");
4627 trace->show_zeros = new_show_zeros;
4628 } else if (!strcmp(var, "trace.show_prefix")) {
4629 trace->show_string_prefix = perf_config_bool(var, value);
4630 } else if (!strcmp(var, "trace.no_inherit")) {
4631 trace->opts.no_inherit = perf_config_bool(var, value);
4632 } else if (!strcmp(var, "trace.args_alignment")) {
4635 trace->args_alignment = args_alignment;
4636 } else if (!strcmp(var, "trace.tracepoint_beautifiers")) {
4638 trace->libtraceevent_print = true;
4640 trace->libtraceevent_print = false;
4646 static void trace__exit(struct trace *trace) argument
4650 strlist__delete(trace->ev_qualifier);
4651 zfree(&trace->ev_qualifier_ids.entries);
4652 if (trace->syscalls.table) {
4653 for (i = 0; i <= trace->sctbl->syscalls.max_id; i++)
4654 syscall__exit(&trace->syscalls.table[i]);
4655 zfree(&trace->syscalls.table);
4657 syscalltbl__delete(trace->sctbl);
4658 zfree(&trace->perfconfig_events);
4676 "perf trace [<options>] [<command>]",
4677 "perf trace [<options>] -- <command> [<options>]",
4678 "perf trace record [<options>] [<command>]",
4679 "perf trace record [<options>] -- <command> [<options>]",
4682 struct trace trace = { local
4706 OPT_CALLBACK('e', "event", &trace, "event",
4709 OPT_CALLBACK(0, "filter", &trace.evlist, "filter",
4711 OPT_BOOLEAN(0, "comm", &trace.show_comm,
4713 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"),
4714 OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace",
4718 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid",
4719 "trace events on existing process id"),
4720 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid",
4721 "trace events on existing thread id"),
4722 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids",
4724 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide,
4726 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu",
4728 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit,
4730 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages",
4732 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user",
4734 OPT_CALLBACK(0, "duration", &trace, "float",
4737 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
4739 OPT_BOOLEAN('T', "time", &trace.full_time,
4741 OPT_BOOLEAN(0, "failure", &trace.failure_only,
4743 OPT_BOOLEAN('s', "summary", &trace.summary_only,
4745 OPT_BOOLEAN('S', "with-summary", &trace.summary,
4747 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary,
4749 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min",
4750 "Trace pagefaults", parse_pagefaults, "maj"),
4751 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
4752 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
4753 OPT_CALLBACK(0, "call-graph", &trace.opts,
4756 OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print,
4758 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
4760 OPT_ULONG(0, "max-events", &trace.max_events,
4762 OPT_UINTEGER(0, "min-stack", &trace.min_stack,
4765 OPT_UINTEGER(0, "max-stack", &trace.max_stack,
4769 OPT_BOOLEAN(0, "sort-events", &trace.sort_events,
4771 OPT_BOOLEAN(0, "print-sample", &trace.print_sample,
4775 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only",
4777 OPT_INTEGER('D', "delay", &trace.opts.target.initial_delay,
4780 OPTS_EVSWITCH(&trace.evswitch),
4800 trace.evlist = evlist__new();
4801 trace.sctbl = syscalltbl__new();
4803 if (trace.evlist == NULL || trace.sctbl == NULL) {
4813 * global setting. If it fails we'll get something in 'perf trace -v'
4818 err = perf_config(trace__config, &trace);
4834 * .perfconfig trace.add_events, and filter those out.
4836 if (!trace.trace_syscalls && !trace.trace_pgfaults &&
4837 trace.evlist->core.nr_entries == 0 /* Was --events used? */) {
4838 trace.trace_syscalls = true;
4846 if (trace.perfconfig_events != NULL) {
4850 err = parse_events(trace.evlist, trace.perfconfig_events, &parse_err);
4852 parse_events_error__print(&parse_err, trace.perfconfig_events);
4858 if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) {
4864 if (!trace.trace_syscalls)
4867 trace.skel = augmented_raw_syscalls_bpf__open();
4868 if (!trace.skel) {
4877 bpf_object__for_each_program(prog, trace.skel->obj) {
4878 if (prog != trace.skel->progs.sys_enter && prog != trace.skel->progs.sys_exit)
4882 err = augmented_raw_syscalls_bpf__load(trace.skel);
4888 augmented_raw_syscalls_bpf__attach(trace.skel);
4889 trace__add_syscall_newtp(&trace);
4893 err = bpf__setup_bpf_output(trace.evlist);
4899 trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
4900 assert(!strcmp(evsel__name(trace.syscalls.events.bpf_output), "__augmented_syscalls__"));
4905 if (trace.trace_pgfaults) {
4906 trace.opts.sample_address = true;
4907 trace.opts.sample_time = true;
4910 if (trace.opts.mmap_pages == UINT_MAX)
4913 if (trace.max_stack == UINT_MAX) {
4914 trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack();
4919 if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) {
4920 record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false);
4926 trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4;
4931 if (trace.evlist->core.nr_entries > 0) {
4932 evlist__set_default_evsel_handler(trace.evlist, trace__event_handler);
4933 if (evlist__set_syscall_tp_fields(trace.evlist)) {
4939 if (trace.sort_events) {
4940 ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace);
4941 ordered_events__set_copy_on_queue(&trace.oe.data, true);
4955 if (trace.syscalls.events.bpf_output) {
4956 evlist__for_each_entry(trace.evlist, evsel) {
4960 trace.raw_augmented_syscalls = true;
4964 if (trace.syscalls.events.bpf_output->priv == NULL &&
4966 struct evsel *augmented = trace.syscalls.events.bpf_output;
5013 if (trace.raw_augmented_syscalls)
5014 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset;
5022 return trace__record(&trace, argc-1, &argv[1]);
5025 if (trace.errno_summary && !trace.summary && !trace.summary_only)
5026 trace.summary_only = true;
5029 if (trace.summary_only)
5030 trace.summary = trace.summary_only;
5033 err = trace__open_output(&trace, output_name);
5040 err = evswitch__init(&trace.evswitch, trace.evlist, stderr);
5044 err = target__validate(&trace.opts.target);
5046 target__strerror(&trace.opts.target, err, bf, sizeof(bf));
5047 fprintf(trace.output, "%s", bf);
5051 err = target__parse_uid(&trace.opts.target);
5053 target__strerror(&trace.opts.target, err, bf, sizeof(bf));
5054 fprintf(trace.output, "%s", bf);
5058 if (!argc && target__none(&trace.opts.target))
5059 trace.opts.target.system_wide = true;
5062 err = trace__replay(&trace);
5064 err = trace__run(&trace, argc, argv);
5068 fclose(trace.output);
5070 trace__exit(&trace);
5072 augmented_raw_syscalls_bpf__destroy(trace.skel);