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'")
58 #include "trace/beauty/beauty.h"
59 #include "trace-event.h"
142 struct trace { struct
224 static void trace__load_vmlinux_btf(struct trace *trace __maybe_unused) in trace__load_vmlinux_btf() argument
227 if (trace->btf != NULL) in trace__load_vmlinux_btf()
230 trace->btf = btf__load_vmlinux_btf(); in trace__load_vmlinux_btf()
232 fprintf(trace->output, trace->btf ? "vmlinux BTF loaded\n" : in trace__load_vmlinux_btf()
325 * The evsel->priv as used by 'perf trace'
766 #include "trace/beauty/generated/fsconfig_arrays.c"
956 struct btf *btf = arg->trace->btf; in syscall_arg__strtoul_btf_enum()
978 trace__load_vmlinux_btf(arg->trace); in syscall_arg__strtoul_btf_type()
980 btf = arg->trace->btf; in syscall_arg__strtoul_btf_type()
1045 dump_data_opts.skip_names = !arg->trace->show_arg_names; in btf_struct_scnprintf()
1064 static size_t trace__btf_scnprintf(struct trace *trace, struct syscall_arg *arg, char *bf, in trace__btf_scnprintf() argument
1069 if (trace->btf == NULL) in trace__btf_scnprintf()
1074 syscall_arg_fmt__cache_btf_enum(arg_fmt, trace->btf, type); in trace__btf_scnprintf()
1082 return btf_enum_scnprintf(arg_fmt->type, trace->btf, bf, size, val); in trace__btf_scnprintf()
1084 return btf_struct_scnprintf(arg_fmt->type, trace->btf, bf, size, arg); in trace__btf_scnprintf()
1090 static size_t trace__btf_scnprintf(struct trace *trace __maybe_unused, struct syscall_arg *arg __ma… in trace__btf_scnprintf()
1116 #include "trace/beauty/eventfd.c"
1117 #include "trace/beauty/futex_op.c"
1118 #include "trace/beauty/futex_val3.c"
1119 #include "trace/beauty/mmap.c"
1120 #include "trace/beauty/mode_t.c"
1121 #include "trace/beauty/msg_flags.c"
1122 #include "trace/beauty/open_flags.c"
1123 #include "trace/beauty/perf_event_open.c"
1124 #include "trace/beauty/pid.c"
1125 #include "trace/beauty/sched_policy.c"
1126 #include "trace/beauty/seccomp.c"
1127 #include "trace/beauty/signum.c"
1128 #include "trace/beauty/socket_type.c"
1129 #include "trace/beauty/waitid_options.c"
1676 struct trace *trace) in thread__fd_path() argument
1680 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1687 if (!trace->live) in thread__fd_path()
1689 ++trace->stats.proc_getname; in thread__fd_path()
1701 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1709 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) in pid__scnprintf_fd() argument
1712 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1715 const char *path = thread__fd_path(thread, fd, trace); in pid__scnprintf_fd()
1772 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1805 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1807 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1810 static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in __trace__fprintf_tstamp() argument
1812 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1823 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1826 return __trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_tstamp()
1847 static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp) in trace__fprintf_comm_tid() argument
1851 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1852 if (trace->show_comm) in trace__fprintf_comm_tid()
1860 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1865 if (trace->show_tstamp) in trace__fprintf_entry_head()
1866 printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1867 if (trace->show_duration) in trace__fprintf_entry_head()
1869 return printed + trace__fprintf_comm_tid(trace, thread, fp); in trace__fprintf_entry_head()
1872 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1879 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1896 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1897 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1918 static int trace__symbols_init(struct trace *trace, struct evlist *evlist) in trace__symbols_init() argument
1925 trace->host = machine__new_host(); in trace__symbols_init()
1926 if (trace->host == NULL) in trace__symbols_init()
1931 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
1935 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1945 static void trace__symbols__exit(struct trace *trace) in trace__symbols__exit() argument
1947 machine__exit(trace->host); in trace__symbols__exit()
1948 trace->host = NULL; in trace__symbols__exit()
2069 static int trace__read_syscall_info(struct trace *trace, int id) in trace__read_syscall_info() argument
2073 const char *name = syscalltbl__name(trace->sctbl, id); in trace__read_syscall_info()
2076 if (trace->syscalls.table == NULL) { in trace__read_syscall_info()
2077 trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); in trace__read_syscall_info()
2078 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
2081 sc = trace->syscalls.table + id; in trace__read_syscall_info()
2102 * Fails to read trace point format via sysfs node, so the trace point in trace__read_syscall_info()
2136 trace__load_vmlinux_btf(trace); in trace__read_syscall_info()
2164 static int trace__validate_ev_qualifier(struct trace *trace) in trace__validate_ev_qualifier() argument
2169 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
2171 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
2172 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
2174 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
2176 trace->output); in trace__validate_ev_qualifier()
2181 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
2183 int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; in trace__validate_ev_qualifier()
2186 id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
2201 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
2206 id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
2213 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
2214 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
2217 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
2220 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
2222 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
2226 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
2227 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
2233 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
2234 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
2238 static __maybe_unused bool trace__syscall_enabled(struct trace *trace, int id) in trace__syscall_enabled() argument
2242 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
2245 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
2246 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
2249 return !trace->not_ev_qualifier; in trace__syscall_enabled()
2251 return trace->not_ev_qualifier; in trace__syscall_enabled()
2283 * in tools/perf/trace/beauty/mount_flags.c
2307 struct trace *trace, struct thread *thread) in syscall__scnprintf_args() argument
2320 .trace = trace, in syscall__scnprintf_args()
2322 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2357 if (val == 0 && !trace->show_zeros && in syscall__scnprintf_args()
2364 if (trace->show_arg_names) in syscall__scnprintf_args()
2369 if (trace->force_btf || default_scnprintf == NULL || default_scnprintf == SCA_PTR) { in syscall__scnprintf_args()
2370 btf_printed = trace__btf_scnprintf(trace, &arg, bf + printed, in syscall__scnprintf_args()
2404 typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel,
2408 static struct syscall *trace__syscall_info(struct trace *trace, in trace__syscall_info() argument
2427 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", in trace__syscall_info()
2435 if (id > trace->sctbl->syscalls.max_id) { in trace__syscall_info()
2439 if ((trace->syscalls.table == NULL || trace->syscalls.table[id].name == NULL) && in trace__syscall_info()
2440 (err = trace__read_syscall_info(trace, id)) != 0) in trace__syscall_info()
2443 if (trace->syscalls.table && trace->syscalls.table[id].nonexistent) in trace__syscall_info()
2446 return &trace->syscalls.table[id]; in trace__syscall_info()
2451 …fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, str_error_r(-err, sbuf, s… in trace__syscall_info()
2452 if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name != NULL) in trace__syscall_info()
2453 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); in trace__syscall_info()
2454 fputs(" information\n", trace->output); in trace__syscall_info()
2519 static int trace__printf_interrupted_entry(struct trace *trace) in trace__printf_interrupted_entry() argument
2525 if (trace->failure_only || trace->current == NULL) in trace__printf_interrupted_entry()
2528 ttrace = thread__priv(trace->current); in trace__printf_interrupted_entry()
2533 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o… in trace__printf_interrupted_entry()
2534 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str); in trace__printf_interrupted_entry()
2536 if (len < trace->args_alignment - 4) in trace__printf_interrupted_entry()
2537 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " "); in trace__printf_interrupted_entry()
2539 printed += fprintf(trace->output, " ...\n"); in trace__printf_interrupted_entry()
2542 ++trace->nr_events_printed; in trace__printf_interrupted_entry()
2547 static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, in trace__fprintf_sample() argument
2552 if (trace->print_sample) { in trace__fprintf_sample()
2555 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", in trace__fprintf_sample()
2611 static int trace__sys_enter(struct trace *trace, struct evsel *evsel, in trace__sys_enter() argument
2622 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__sys_enter()
2628 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_enter()
2629 ttrace = thread__trace(thread, trace->output); in trace__sys_enter()
2633 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_enter()
2643 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) in trace__sys_enter()
2644 trace__printf_interrupted_entry(trace); in trace__sys_enter()
2655 if (evsel != trace->syscalls.events.sys_enter) in trace__sys_enter()
2656 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy… in trace__sys_enter()
2662 args, augmented_args, augmented_args_size, trace, thread); in trace__sys_enter()
2665 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { in trace__sys_enter()
2668 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output); in trace__sys_enter()
2669 printed = fprintf(trace->output, "%s)", ttrace->entry_str); in trace__sys_enter()
2670 if (trace->args_alignment > printed) in trace__sys_enter()
2671 alignment = trace->args_alignment - printed; in trace__sys_enter()
2672 fprintf(trace->output, "%*s= ?\n", alignment, " "); in trace__sys_enter()
2680 if (trace->current != thread) { in trace__sys_enter()
2681 thread__put(trace->current); in trace__sys_enter()
2682 trace->current = thread__get(thread); in trace__sys_enter()
2690 static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, in trace__fprintf_sys_enter() argument
2696 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__fprintf_sys_enter()
2705 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__fprintf_sys_enter()
2706 ttrace = thread__trace(thread, trace->output); in trace__fprintf_sys_enter()
2715 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy… in trace__fprintf_sys_enter()
2716 …ll__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); in trace__fprintf_sys_enter()
2717 fprintf(trace->output, "%.*s", (int)printed, msg); in trace__fprintf_sys_enter()
2724 static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, in trace__resolve_callchain() argument
2731 trace->max_stack; in trace__resolve_callchain()
2735 if (machine__resolve(trace->host, &al, sample) < 0) in trace__resolve_callchain()
2744 static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) in trace__fprintf_callchain() argument
2751 …chain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); in trace__fprintf_callchain()
2761 static int trace__sys_exit(struct trace *trace, struct evsel *evsel, in trace__sys_exit() argument
2770 int alignment = trace->args_alignment; in trace__sys_exit()
2771 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__sys_exit()
2777 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_exit()
2778 ttrace = thread__trace(thread, trace->output); in trace__sys_exit()
2782 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_exit()
2786 if (trace->summary) in trace__sys_exit()
2787 thread__update_stats(thread, ttrace, id, sample, ret, trace->errno_summary); in trace__sys_exit()
2789 if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) { in trace__sys_exit()
2792 ++trace->stats.vfs_getname; in trace__sys_exit()
2797 if (trace__filter_duration(trace, duration)) in trace__sys_exit()
2800 } else if (trace->duration_filter) in trace__sys_exit()
2806 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__sys_exit()
2808 if (cursor->nr < trace->min_stack) in trace__sys_exit()
2814 if (trace->summary_only || (ret >= 0 && trace->failure_only)) in trace__sys_exit()
2817 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-… in trace__sys_exit()
2820 printed = fprintf(trace->output, "%s", ttrace->entry_str); in trace__sys_exit()
2822 printed += fprintf(trace->output, " ... ["); in trace__sys_exit()
2823 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); in trace__sys_exit()
2825 printed += fprintf(trace->output, "]: %s()", sc->name); in trace__sys_exit()
2835 fprintf(trace->output, ")%*s= ", alignment, " "); in trace__sys_exit()
2841 fprintf(trace->output, "%ld", ret); in trace__sys_exit()
2848 fprintf(trace->output, "-1 %s (%s)", e, emsg); in trace__sys_exit()
2851 fprintf(trace->output, "0 (Timeout)"); in trace__sys_exit()
2857 .trace = trace, in trace__sys_exit()
2861 fprintf(trace->output, "%s", bf); in trace__sys_exit()
2863 fprintf(trace->output, "%#lx", ret); in trace__sys_exit()
2865 struct thread *child = machine__find_thread(trace->host, ret, ret); in trace__sys_exit()
2868 fprintf(trace->output, "%ld", ret); in trace__sys_exit()
2870 fprintf(trace->output, " (%s)", thread__comm_str(child)); in trace__sys_exit()
2876 fputc('\n', trace->output); in trace__sys_exit()
2882 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX) in trace__sys_exit()
2886 trace__fprintf_callchain(trace, sample); in trace__sys_exit()
2897 static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, in trace__vfs_getname() argument
2901 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__vfs_getname()
2958 static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, in trace__sched_stat_runtime() argument
2964 struct thread *thread = machine__findnew_thread(trace->host, in trace__sched_stat_runtime()
2967 struct thread_trace *ttrace = thread__trace(thread, trace->output); in trace__sched_stat_runtime()
2973 trace->runtime_ms += runtime_ms; in trace__sched_stat_runtime()
2979 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", in trace__sched_stat_runtime()
3012 static void bpf_output__fprintf(struct trace *trace, in bpf_output__fprintf() argument
3016 bpf_output__printer, NULL, trace->output); in bpf_output__fprintf()
3017 ++trace->nr_events_printed; in bpf_output__fprintf()
3020 static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample… in trace__fprintf_tp_fields() argument
3038 .trace = trace, in trace__fprintf_tp_fields()
3040 .show_string_prefix = trace->show_string_prefix, in trace__fprintf_tp_fields()
3070 if (val == 0 && !trace->show_zeros && !arg->show_zero && arg->strtoul != STUL_BTF_TYPE) in trace__fprintf_tp_fields()
3075 if (trace->show_arg_names) in trace__fprintf_tp_fields()
3078 …btf_printed = trace__btf_scnprintf(trace, &syscall_arg, bf + printed, size - printed, val, field->… in trace__fprintf_tp_fields()
3087 return printed + fprintf(trace->output, "%.*s", (int)printed, bf); in trace__fprintf_tp_fields()
3090 static int trace__event_handler(struct trace *trace, struct evsel *evsel, in trace__event_handler() argument
3100 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__event_handler()
3105 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__event_handler()
3107 if (cursor->nr < trace->min_stack) in trace__event_handler()
3113 trace__printf_interrupted_entry(trace); in trace__event_handler()
3114 trace__fprintf_tstamp(trace, sample->time, trace->output); in trace__event_handler()
3116 if (trace->trace_syscalls && trace->show_duration) in trace__event_handler()
3117 fprintf(trace->output, "( ): "); in trace__event_handler()
3120 trace__fprintf_comm_tid(trace, thread, trace->output); in trace__event_handler()
3122 if (evsel == trace->syscalls.events.bpf_output) { in trace__event_handler()
3124 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__event_handler()
3127 fprintf(trace->output, "%s(", sc->name); in trace__event_handler()
3128 trace__fprintf_sys_enter(trace, evsel, sample); in trace__event_handler()
3129 fputc(')', trace->output); in trace__event_handler()
3140 fprintf(trace->output, "%s(", evsel->name); in trace__event_handler()
3143 bpf_output__fprintf(trace, sample); in trace__event_handler()
3148 trace__fprintf_sys_enter(trace, evsel, sample))) { in trace__event_handler()
3149 if (trace->libtraceevent_print) { in trace__event_handler()
3152 trace->output); in trace__event_handler()
3154 trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); in trace__event_handler()
3160 fprintf(trace->output, ")\n"); in trace__event_handler()
3163 trace__fprintf_callchain(trace, sample); in trace__event_handler()
3167 ++trace->nr_events_printed; in trace__event_handler()
3195 static int trace__pgfault(struct trace *trace, in trace__pgfault() argument
3208 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__pgfault()
3213 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__pgfault()
3215 if (cursor->nr < trace->min_stack) in trace__pgfault()
3221 ttrace = thread__trace(thread, trace->output); in trace__pgfault()
3230 if (trace->summary_only) in trace__pgfault()
3235 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output); in trace__pgfault()
3237 fprintf(trace->output, "%sfault [", in trace__pgfault()
3241 print_location(trace->output, sample, &al, false, true); in trace__pgfault()
3243 fprintf(trace->output, "] => "); in trace__pgfault()
3256 print_location(trace->output, sample, &al, true, false); in trace__pgfault()
3258 fprintf(trace->output, " (%c%c)\n", map_type, al.level); in trace__pgfault()
3261 trace__fprintf_callchain(trace, sample); in trace__pgfault()
3265 ++trace->nr_events_printed; in trace__pgfault()
3274 static void trace__set_base_time(struct trace *trace, in trace__set_base_time() argument
3286 if (trace->base_time == 0 && !trace->full_time && in trace__set_base_time()
3288 trace->base_time = sample->time; in trace__set_base_time()
3297 struct trace *trace = container_of(tool, struct trace, tool); in trace__process_sample() local
3303 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__process_sample()
3307 trace__set_base_time(trace, evsel, sample); in trace__process_sample()
3310 ++trace->nr_events; in trace__process_sample()
3311 handler(trace, evsel, event, sample); in trace__process_sample()
3318 static int trace__record(struct trace *trace, int argc, const char **argv) in trace__record() argument
3350 if (trace->trace_syscalls) { in trace__record()
3368 if (trace->trace_pgfaults & TRACE_PFMAJ) in trace__record()
3372 if (trace->trace_pgfaults & TRACE_PFMIN) in trace__record()
3386 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
3449 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… in trace__handle_event() argument
3455 trace__process_event(trace, trace->host, event, sample); in trace__handle_event()
3459 evsel = evlist__id2evsel(trace->evlist, sample->id); in trace__handle_event()
3461 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); in trace__handle_event()
3465 if (evswitch__discard(&trace->evswitch, evsel)) in trace__handle_event()
3468 trace__set_base_time(trace, evsel, sample); in trace__handle_event()
3472 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", in trace__handle_event()
3477 handler(trace, evsel, event, sample); in trace__handle_event()
3480 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) in trace__handle_event()
3484 static int trace__add_syscall_newtp(struct trace *trace) in trace__add_syscall_newtp() argument
3487 struct evlist *evlist = trace->evlist; in trace__add_syscall_newtp()
3504 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
3505 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
3510 if (callchain_param.enabled && !trace->kernel_syscallchains) { in trace__add_syscall_newtp()
3519 trace->syscalls.events.sys_enter = sys_enter; in trace__add_syscall_newtp()
3520 trace->syscalls.events.sys_exit = sys_exit; in trace__add_syscall_newtp()
3533 static int trace__set_ev_qualifier_tp_filter(struct trace *trace) in trace__set_ev_qualifier_tp_filter() argument
3537 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, in trace__set_ev_qualifier_tp_filter()
3538 trace->ev_qualifier_ids.nr, in trace__set_ev_qualifier_tp_filter()
3539 trace->ev_qualifier_ids.entries); in trace__set_ev_qualifier_tp_filter()
3544 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) { in trace__set_ev_qualifier_tp_filter()
3545 sys_exit = trace->syscalls.events.sys_exit; in trace__set_ev_qualifier_tp_filter()
3575 static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) in trace__find_bpf_program_by_title() argument
3580 if (trace->skel->obj == NULL) in trace__find_bpf_program_by_title()
3583 bpf_object__for_each_program(pos, trace->skel->obj) { in trace__find_bpf_program_by_title()
3594 static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc, in trace__find_syscall_bpf_prog() argument
3602 prog = trace__find_bpf_program_by_title(trace, default_prog_name); in trace__find_syscall_bpf_prog()
3607 prog = trace__find_bpf_program_by_title(trace, default_prog_name); in trace__find_syscall_bpf_prog()
3614 prog = trace__find_bpf_program_by_title(trace, prog_name); in trace__find_syscall_bpf_prog()
3624 return trace->skel->progs.syscall_unaugmented; in trace__find_syscall_bpf_prog()
3627 static void trace__init_syscall_bpf_progs(struct trace *trace, int id) in trace__init_syscall_bpf_progs() argument
3629 struct syscall *sc = trace__syscall_info(trace, NULL, id); in trace__init_syscall_bpf_progs()
3634 …sc->bpf_prog.sys_enter = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.… in trace__init_syscall_bpf_progs()
3635 …sc->bpf_prog.sys_exit = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.… in trace__init_syscall_bpf_progs()
3638 static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id) in trace__bpf_prog_sys_enter_fd() argument
3640 struct syscall *sc = trace__syscall_info(trace, NULL, id); in trace__bpf_prog_sys_enter_fd()
3641 …return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->skel->progs.syscall_u… in trace__bpf_prog_sys_enter_fd()
3644 static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id) in trace__bpf_prog_sys_exit_fd() argument
3646 struct syscall *sc = trace__syscall_info(trace, NULL, id); in trace__bpf_prog_sys_exit_fd()
3647 …return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->skel->progs.syscall_un… in trace__bpf_prog_sys_exit_fd()
3650 static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int key, unsigned int *beauty_array) in trace__bpf_sys_enter_beauty_map() argument
3653 struct syscall *sc = trace__syscall_info(trace, NULL, key); in trace__bpf_sys_enter_beauty_map()
3662 trace__load_vmlinux_btf(trace); in trace__bpf_sys_enter_beauty_map()
3663 if (trace->btf == NULL) in trace__bpf_sys_enter_beauty_map()
3688 if (syscall_arg_fmt__cache_btf_struct(&sc->arg_fmt[i], trace->btf, name)) in trace__bpf_sys_enter_beauty_map()
3735 static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *s… in trace__find_usable_bpf_prog_entry() argument
3749 for (int i = 0; i < trace->sctbl->syscalls.nr_entries; ++i) { in trace__find_usable_bpf_prog_entry()
3750 int id = syscalltbl__id_at_idx(trace->sctbl, i); in trace__find_usable_bpf_prog_entry()
3751 struct syscall *pair = trace__syscall_info(trace, NULL, id); in trace__find_usable_bpf_prog_entry()
3756 pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented) in trace__find_usable_bpf_prog_entry()
3821 …pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_ent… in trace__find_usable_bpf_prog_entry()
3822 if (pair_prog == trace->skel->progs.syscall_unaugmented) in trace__find_usable_bpf_prog_entry()
3835 static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace) in trace__init_syscalls_bpf_prog_array_maps() argument
3837 int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter); in trace__init_syscalls_bpf_prog_array_maps()
3838 int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit); in trace__init_syscalls_bpf_prog_array_maps()
3839 int beauty_map_fd = bpf_map__fd(trace->skel->maps.beauty_map_enter); in trace__init_syscalls_bpf_prog_array_maps()
3843 for (int i = 0; i < trace->sctbl->syscalls.nr_entries; ++i) { in trace__init_syscalls_bpf_prog_array_maps()
3844 int prog_fd, key = syscalltbl__id_at_idx(trace->sctbl, i); in trace__init_syscalls_bpf_prog_array_maps()
3846 if (!trace__syscall_enabled(trace, key)) in trace__init_syscalls_bpf_prog_array_maps()
3849 trace__init_syscall_bpf_progs(trace, key); in trace__init_syscalls_bpf_prog_array_maps()
3852 prog_fd = trace__bpf_prog_sys_enter_fd(trace, key); in trace__init_syscalls_bpf_prog_array_maps()
3856 prog_fd = trace__bpf_prog_sys_exit_fd(trace, key); in trace__init_syscalls_bpf_prog_array_maps()
3863 err = trace__bpf_sys_enter_beauty_map(trace, key, (unsigned int *)beauty_array); in trace__init_syscalls_bpf_prog_array_maps()
3899 for (int i = 0; i < trace->sctbl->syscalls.nr_entries; ++i) { in trace__init_syscalls_bpf_prog_array_maps()
3900 int key = syscalltbl__id_at_idx(trace->sctbl, i); in trace__init_syscalls_bpf_prog_array_maps()
3901 struct syscall *sc = trace__syscall_info(trace, NULL, key); in trace__init_syscalls_bpf_prog_array_maps()
3912 if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented) in trace__init_syscalls_bpf_prog_array_maps()
3919 pair_prog = trace__find_usable_bpf_prog_entry(trace, sc); in trace__init_syscalls_bpf_prog_array_maps()
3939 static int trace__set_ev_qualifier_filter(struct trace *trace) in trace__set_ev_qualifier_filter() argument
3941 if (trace->syscalls.events.sys_enter) in trace__set_ev_qualifier_filter()
3942 return trace__set_ev_qualifier_tp_filter(trace); in trace__set_ev_qualifier_filter()
3964 static int trace__set_filter_loop_pids(struct trace *trace) in trace__set_filter_loop_pids() argument
3970 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]); in trace__set_filter_loop_pids()
3973 struct thread *parent = machine__find_thread(trace->host, in trace__set_filter_loop_pids()
3988 err = evlist__append_tp_filter_pids(trace->evlist, nr, pids); in trace__set_filter_loop_pids()
3989 if (!err && trace->filter_pids.map) in trace__set_filter_loop_pids()
3990 err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids); in trace__set_filter_loop_pids()
3995 static int trace__set_filter_pids(struct trace *trace) in trace__set_filter_pids() argument
4004 if (trace->filter_pids.nr > 0) { in trace__set_filter_pids()
4005 err = evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr, in trace__set_filter_pids()
4006 trace->filter_pids.entries); in trace__set_filter_pids()
4007 if (!err && trace->filter_pids.map) { in trace__set_filter_pids()
4008 err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr, in trace__set_filter_pids()
4009 trace->filter_pids.entries); in trace__set_filter_pids()
4011 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) { in trace__set_filter_pids()
4012 err = trace__set_filter_loop_pids(trace); in trace__set_filter_pids()
4018 static int __trace__deliver_event(struct trace *trace, union perf_event *event) in __trace__deliver_event() argument
4020 struct evlist *evlist = trace->evlist; in __trace__deliver_event()
4025 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); in __trace__deliver_event()
4027 trace__handle_event(trace, event, &sample); in __trace__deliver_event()
4032 static int __trace__flush_events(struct trace *trace) in __trace__flush_events() argument
4034 u64 first = ordered_events__first_time(&trace->oe.data); in __trace__flush_events()
4035 u64 flush = trace->oe.last - NSEC_PER_SEC; in __trace__flush_events()
4039 return ordered_events__flush_time(&trace->oe.data, flush); in __trace__flush_events()
4044 static int trace__flush_events(struct trace *trace) in trace__flush_events() argument
4046 return !trace->sort_events ? 0 : __trace__flush_events(trace); in trace__flush_events()
4049 static int trace__deliver_event(struct trace *trace, union perf_event *event) in trace__deliver_event() argument
4053 if (!trace->sort_events) in trace__deliver_event()
4054 return __trace__deliver_event(trace, event); in trace__deliver_event()
4056 err = evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last); in trace__deliver_event()
4060 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0, NULL); in trace__deliver_event()
4064 return trace__flush_events(trace); in trace__deliver_event()
4070 struct trace *trace = container_of(oe, struct trace, oe.data); in ordered_events__deliver_event() local
4072 return __trace__deliver_event(trace, event->event); in ordered_events__deliver_event()
4099 static int trace__expand_filter(struct trace *trace, struct evsel *evsel) in trace__expand_filter() argument
4152 .trace = trace, in trace__expand_filter()
4200 static int trace__expand_filters(struct trace *trace, struct evsel **err_evsel) in trace__expand_filters() argument
4202 struct evlist *evlist = trace->evlist; in trace__expand_filters()
4209 if (trace__expand_filter(trace, evsel)) { in trace__expand_filters()
4218 static int trace__run(struct trace *trace, int argc, const char **argv) in trace__run() argument
4220 struct evlist *evlist = trace->evlist; in trace__run()
4227 trace->live = true; in trace__run()
4229 if (!trace->raw_augmented_syscalls) { in trace__run()
4230 if (trace->trace_syscalls && trace__add_syscall_newtp(trace)) in trace__run()
4233 if (trace->trace_syscalls) in trace__run()
4234 trace->vfs_getname = evlist__add_vfs_getname(evlist); in trace__run()
4237 if ((trace->trace_pgfaults & TRACE_PFMAJ)) { in trace__run()
4241 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param); in trace__run()
4245 if ((trace->trace_pgfaults & TRACE_PFMIN)) { in trace__run()
4249 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param); in trace__run()
4254 trace->opts.ignore_missing_thread = trace->opts.target.uid != UINT_MAX || trace->opts.target.pid; in trace__run()
4256 if (trace->sched && in trace__run()
4263 * trace -G A -e sched:*switch in trace__run()
4268 * trace -e sched:*switch -G A in trace__run()
4276 * trace -G A -e sched:*switch -G B in trace__run()
4284 if (trace->cgroup) in trace__run()
4285 evlist__set_default_cgroup(trace->evlist, trace->cgroup); in trace__run()
4287 err = evlist__create_maps(evlist, &trace->opts.target); in trace__run()
4289 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); in trace__run()
4293 err = trace__symbols_init(trace, evlist); in trace__run()
4295 fprintf(trace->output, "Problems initializing symbol libraries!\n"); in trace__run()
4299 evlist__config(evlist, &trace->opts, &callchain_param); in trace__run()
4302 err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL); in trace__run()
4304 fprintf(trace->output, "Couldn't run the workload!\n"); in trace__run()
4314 if (trace->syscalls.events.bpf_output) { in trace__run()
4321 perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) { in trace__run()
4322 bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__, in trace__run()
4324 xyarray__entry(trace->syscalls.events.bpf_output->core.fd, in trace__run()
4330 if (trace->skel) in trace__run()
4331 trace->filter_pids.map = trace->skel->maps.pids_filtered; in trace__run()
4333 err = trace__set_filter_pids(trace); in trace__run()
4338 if (trace->skel && trace->skel->progs.sys_enter) in trace__run()
4339 trace__init_syscalls_bpf_prog_array_maps(trace); in trace__run()
4342 if (trace->ev_qualifier_ids.nr > 0) { in trace__run()
4343 err = trace__set_ev_qualifier_filter(trace); in trace__run()
4347 if (trace->syscalls.events.sys_exit) { in trace__run()
4349 trace->syscalls.events.sys_exit->filter); in trace__run()
4364 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(trace->sctbl, "close")); in trace__run()
4366 err = trace__expand_filters(trace, &evsel); in trace__run()
4369 err = evlist__apply_filters(evlist, &evsel, &trace->opts.target); in trace__run()
4373 err = evlist__mmap(evlist, trace->opts.mmap_pages); in trace__run()
4377 if (!target__none(&trace->opts.target) && !trace->opts.target.initial_delay) in trace__run()
4383 if (trace->opts.target.initial_delay) { in trace__run()
4384 usleep(trace->opts.target.initial_delay * 1000); in trace__run()
4388 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 || in trace__run()
4401 evsel->core.attr.sample_max_stack = trace->max_stack; in trace__run()
4404 before = trace->nr_events; in trace__run()
4415 ++trace->nr_events; in trace__run()
4417 err = trace__deliver_event(trace, event); in trace__run()
4434 if (trace->nr_events == before) { in trace__run()
4443 if (trace__flush_events(trace)) in trace__run()
4451 thread__zput(trace->current); in trace__run()
4455 if (trace->sort_events) in trace__run()
4456 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL); in trace__run()
4459 if (trace->summary) in trace__run()
4460 trace__fprintf_thread_summary(trace, trace->output); in trace__run()
4462 if (trace->show_tool_stats) { in trace__run()
4463 fprintf(trace->output, "Stats:\n " in trace__run()
4466 trace->stats.vfs_getname, in trace__run()
4467 trace->stats.proc_getname); in trace__run()
4472 trace__symbols__exit(trace); in trace__run()
4475 cgroup__put(trace->cgroup); in trace__run()
4476 trace->evlist = NULL; in trace__run()
4477 trace->live = false; in trace__run()
4498 fprintf(trace->output, "%s\n", errbuf); in trace__run()
4502 fprintf(trace->output, in trace__run()
4509 fprintf(trace->output, "Not enough memory to run!\n"); in trace__run()
4513 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno)); in trace__run()
4517 static int trace__replay(struct trace *trace) in trace__replay() argument
4525 .force = trace->force, in trace__replay()
4531 trace->tool.sample = trace__process_sample; in trace__replay()
4532 trace->tool.mmap = perf_event__process_mmap; in trace__replay()
4533 trace->tool.mmap2 = perf_event__process_mmap2; in trace__replay()
4534 trace->tool.comm = perf_event__process_comm; in trace__replay()
4535 trace->tool.exit = perf_event__process_exit; in trace__replay()
4536 trace->tool.fork = perf_event__process_fork; in trace__replay()
4537 trace->tool.attr = perf_event__process_attr; in trace__replay()
4538 trace->tool.tracing_data = perf_event__process_tracing_data; in trace__replay()
4539 trace->tool.build_id = perf_event__process_build_id; in trace__replay()
4540 trace->tool.namespaces = perf_event__process_namespaces; in trace__replay()
4542 trace->tool.ordered_events = true; in trace__replay()
4543 trace->tool.ordering_requires_timestamps = true; in trace__replay()
4546 trace->multiple_threads = true; in trace__replay()
4548 session = perf_session__new(&data, &trace->tool); in trace__replay()
4552 if (trace->opts.target.pid) in trace__replay()
4553 symbol_conf.pid_list_str = strdup(trace->opts.target.pid); in trace__replay()
4555 if (trace->opts.target.tid) in trace__replay()
4556 symbol_conf.tid_list_str = strdup(trace->opts.target.tid); in trace__replay()
4561 trace->host = &session->machines.host; in trace__replay()
4568 trace->syscalls.events.sys_enter = evsel; in trace__replay()
4581 trace->syscalls.events.sys_exit = evsel; in trace__replay()
4605 else if (trace->summary) in trace__replay()
4606 trace__fprintf_thread_summary(trace, trace->output); in trace__replay()
4638 struct trace *trace, FILE *fp) in thread__dump_stats() argument
4666 sc = &trace->syscalls.table[syscall_stats_entry->syscall]; in thread__dump_stats()
4672 if (trace->errno_summary && stats->nr_failures) { in thread__dump_stats()
4677 …fprintf(fp, "\t\t\t\t%s: %d\n", perf_env__arch_strerrno(trace->host->env, e + 1), stats->errnos[e]… in thread__dump_stats()
4689 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) in trace__fprintf_thread() argument
4698 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; in trace__fprintf_thread()
4707 if (trace->sched) in trace__fprintf_thread()
4712 printed += thread__dump_stats(ttrace, trace, fp); in trace__fprintf_thread()
4740 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) in trace__fprintf_thread_summary() argument
4745 if (machine__thread_list(trace->host, &threads) == 0) { in trace__fprintf_thread_summary()
4751 printed += trace__fprintf_thread(fp, pos->thread, trace); in trace__fprintf_thread_summary()
4760 struct trace *trace = opt->value; in trace__set_duration() local
4762 trace->duration_filter = atof(str); in trace__set_duration()
4771 struct trace *trace = opt->value; in trace__set_filter_pids_from_option() local
4781 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; in trace__set_filter_pids_from_option()
4782 trace->filter_pids.entries = calloc(i, sizeof(pid_t)); in trace__set_filter_pids_from_option()
4784 if (trace->filter_pids.entries == NULL) in trace__set_filter_pids_from_option()
4787 trace->filter_pids.entries[0] = getpid(); in trace__set_filter_pids_from_option()
4789 for (i = 1; i < trace->filter_pids.nr; ++i) in trace__set_filter_pids_from_option()
4790 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; in trace__set_filter_pids_from_option()
4798 static int trace__open_output(struct trace *trace, const char *filename) in trace__open_output() argument
4810 trace->output = fopen(filename, "w"); in trace__open_output()
4812 return trace->output == NULL ? -errno : 0; in trace__open_output()
4915 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
4923 struct trace *trace = (struct trace *)opt->value; in trace__parse_events_option() local
4936 trace->not_ev_qualifier = true; in trace__parse_events_option()
4944 if (syscalltbl__id(trace->sctbl, s) >= 0 || in trace__parse_events_option()
4945 syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) { in trace__parse_events_option()
4981 trace->ev_qualifier = strlist__new(lists[1], &slist_config); in trace__parse_events_option()
4982 if (trace->ev_qualifier == NULL) { in trace__parse_events_option()
4983 fputs("Not enough memory to parse event qualifier", trace->output); in trace__parse_events_option()
4987 if (trace__validate_ev_qualifier(trace)) in trace__parse_events_option()
4989 trace->trace_syscalls = true; in trace__parse_events_option()
4996 .evlistp = &trace->evlist, in trace__parse_events_option()
5015 struct trace *trace = opt->value; in trace__parse_cgroups() local
5017 if (!list_empty(&trace->evlist->core.entries)) { in trace__parse_cgroups()
5019 .value = &trace->evlist, in trace__parse_cgroups()
5023 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str); in trace__parse_cgroups()
5030 struct trace *trace = arg; in trace__config() local
5033 if (!strcmp(var, "trace.add_events")) { in trace__config()
5034 trace->perfconfig_events = strdup(value); in trace__config()
5035 if (trace->perfconfig_events == NULL) { in trace__config()
5036 pr_err("Not enough memory for %s\n", "trace.add_events"); in trace__config()
5039 } else if (!strcmp(var, "trace.show_timestamp")) { in trace__config()
5040 trace->show_tstamp = perf_config_bool(var, value); in trace__config()
5041 } else if (!strcmp(var, "trace.show_duration")) { in trace__config()
5042 trace->show_duration = perf_config_bool(var, value); in trace__config()
5043 } else if (!strcmp(var, "trace.show_arg_names")) { in trace__config()
5044 trace->show_arg_names = perf_config_bool(var, value); in trace__config()
5045 if (!trace->show_arg_names) in trace__config()
5046 trace->show_zeros = true; in trace__config()
5047 } else if (!strcmp(var, "trace.show_zeros")) { in trace__config()
5049 if (!trace->show_arg_names && !new_show_zeros) { in trace__config()
5050 pr_warning("trace.show_zeros has to be set when trace.show_arg_names=no\n"); in trace__config()
5053 trace->show_zeros = new_show_zeros; in trace__config()
5054 } else if (!strcmp(var, "trace.show_prefix")) { in trace__config()
5055 trace->show_string_prefix = perf_config_bool(var, value); in trace__config()
5056 } else if (!strcmp(var, "trace.no_inherit")) { in trace__config()
5057 trace->opts.no_inherit = perf_config_bool(var, value); in trace__config()
5058 } else if (!strcmp(var, "trace.args_alignment")) { in trace__config()
5061 trace->args_alignment = args_alignment; in trace__config()
5062 } else if (!strcmp(var, "trace.tracepoint_beautifiers")) { in trace__config()
5064 trace->libtraceevent_print = true; in trace__config()
5066 trace->libtraceevent_print = false; in trace__config()
5072 static void trace__exit(struct trace *trace) in trace__exit() argument
5076 strlist__delete(trace->ev_qualifier); in trace__exit()
5077 zfree(&trace->ev_qualifier_ids.entries); in trace__exit()
5078 if (trace->syscalls.table) { in trace__exit()
5079 for (i = 0; i <= trace->sctbl->syscalls.max_id; i++) in trace__exit()
5080 syscall__exit(&trace->syscalls.table[i]); in trace__exit()
5081 zfree(&trace->syscalls.table); in trace__exit()
5083 syscalltbl__delete(trace->sctbl); in trace__exit()
5084 zfree(&trace->perfconfig_events); in trace__exit()
5102 "perf trace [<options>] [<command>]", in cmd_trace()
5103 "perf trace [<options>] -- <command> [<options>]", in cmd_trace()
5104 "perf trace record [<options>] [<command>]", in cmd_trace()
5105 "perf trace record [<options>] -- <command> [<options>]", in cmd_trace()
5108 struct trace trace = { in cmd_trace() local
5132 OPT_CALLBACK('e', "event", &trace, "event", in cmd_trace()
5135 OPT_CALLBACK(0, "filter", &trace.evlist, "filter", in cmd_trace()
5137 OPT_BOOLEAN(0, "comm", &trace.show_comm, in cmd_trace()
5139 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), in cmd_trace()
5140 OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace", in cmd_trace()
5144 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", in cmd_trace()
5145 "trace events on existing process id"), in cmd_trace()
5146 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", in cmd_trace()
5147 "trace events on existing thread id"), in cmd_trace()
5148 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids", in cmd_trace()
5150 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, in cmd_trace()
5152 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", in cmd_trace()
5154 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, in cmd_trace()
5156 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", in cmd_trace()
5158 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", in cmd_trace()
5160 OPT_CALLBACK(0, "duration", &trace, "float", in cmd_trace()
5163 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), in cmd_trace()
5165 OPT_BOOLEAN('T', "time", &trace.full_time, in cmd_trace()
5167 OPT_BOOLEAN(0, "failure", &trace.failure_only, in cmd_trace()
5169 OPT_BOOLEAN('s', "summary", &trace.summary_only, in cmd_trace()
5171 OPT_BOOLEAN('S', "with-summary", &trace.summary, in cmd_trace()
5173 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary, in cmd_trace()
5175 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", in cmd_trace()
5176 "Trace pagefaults", parse_pagefaults, "maj"), in cmd_trace()
5177 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), in cmd_trace()
5178 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), in cmd_trace()
5179 OPT_CALLBACK(0, "call-graph", &trace.opts, in cmd_trace()
5182 OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print, in cmd_trace()
5184 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, in cmd_trace()
5186 OPT_ULONG(0, "max-events", &trace.max_events, in cmd_trace()
5188 OPT_UINTEGER(0, "min-stack", &trace.min_stack, in cmd_trace()
5191 OPT_UINTEGER(0, "max-stack", &trace.max_stack, in cmd_trace()
5195 OPT_BOOLEAN(0, "sort-events", &trace.sort_events, in cmd_trace()
5197 OPT_BOOLEAN(0, "print-sample", &trace.print_sample, in cmd_trace()
5201 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only", in cmd_trace()
5203 OPT_INTEGER('D', "delay", &trace.opts.target.initial_delay, in cmd_trace()
5206 OPT_BOOLEAN(0, "force-btf", &trace.force_btf, "Prefer btf_dump general pretty printer" in cmd_trace()
5208 OPTS_EVSWITCH(&trace.evswitch), in cmd_trace()
5228 trace.evlist = evlist__new(); in cmd_trace()
5229 trace.sctbl = syscalltbl__new(); in cmd_trace()
5231 if (trace.evlist == NULL || trace.sctbl == NULL) { in cmd_trace()
5241 * global setting. If it fails we'll get something in 'perf trace -v' in cmd_trace()
5246 err = perf_config(trace__config, &trace); in cmd_trace()
5262 * .perfconfig trace.add_events, and filter those out. in cmd_trace()
5264 if (!trace.trace_syscalls && !trace.trace_pgfaults && in cmd_trace()
5265 trace.evlist->core.nr_entries == 0 /* Was --events used? */) { in cmd_trace()
5266 trace.trace_syscalls = true; in cmd_trace()
5274 if (trace.perfconfig_events != NULL) { in cmd_trace()
5278 err = parse_events(trace.evlist, trace.perfconfig_events, &parse_err); in cmd_trace()
5280 parse_events_error__print(&parse_err, trace.perfconfig_events); in cmd_trace()
5286 if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) { in cmd_trace()
5292 if (!trace.trace_syscalls) in cmd_trace()
5300 trace.skel = augmented_raw_syscalls_bpf__open(); in cmd_trace()
5301 if (!trace.skel) { in cmd_trace()
5310 bpf_object__for_each_program(prog, trace.skel->obj) { in cmd_trace()
5311 if (prog != trace.skel->progs.sys_enter && prog != trace.skel->progs.sys_exit) in cmd_trace()
5315 err = augmented_raw_syscalls_bpf__load(trace.skel); in cmd_trace()
5321 augmented_raw_syscalls_bpf__attach(trace.skel); in cmd_trace()
5322 trace__add_syscall_newtp(&trace); in cmd_trace()
5326 err = bpf__setup_bpf_output(trace.evlist); in cmd_trace()
5332 trace.syscalls.events.bpf_output = evlist__last(trace.evlist); in cmd_trace()
5333 assert(evsel__name_is(trace.syscalls.events.bpf_output, "__augmented_syscalls__")); in cmd_trace()
5338 if (trace.trace_pgfaults) { in cmd_trace()
5339 trace.opts.sample_address = true; in cmd_trace()
5340 trace.opts.sample_time = true; in cmd_trace()
5343 if (trace.opts.mmap_pages == UINT_MAX) in cmd_trace()
5346 if (trace.max_stack == UINT_MAX) { in cmd_trace()
5347 trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack(); in cmd_trace()
5352 if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) { in cmd_trace()
5353 record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false); in cmd_trace()
5359 trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4; in cmd_trace()
5364 if (trace.evlist->core.nr_entries > 0) { in cmd_trace()
5367 evlist__set_default_evsel_handler(trace.evlist, trace__event_handler); in cmd_trace()
5368 if (evlist__set_syscall_tp_fields(trace.evlist, &use_btf)) { in cmd_trace()
5374 trace__load_vmlinux_btf(&trace); in cmd_trace()
5377 if (trace.sort_events) { in cmd_trace()
5378 ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace); in cmd_trace()
5379 ordered_events__set_copy_on_queue(&trace.oe.data, true); in cmd_trace()
5393 if (trace.syscalls.events.bpf_output) { in cmd_trace()
5394 evlist__for_each_entry(trace.evlist, evsel) { in cmd_trace()
5398 trace.raw_augmented_syscalls = true; in cmd_trace()
5402 if (trace.syscalls.events.bpf_output->priv == NULL && in cmd_trace()
5404 struct evsel *augmented = trace.syscalls.events.bpf_output; in cmd_trace()
5451 if (trace.raw_augmented_syscalls) in cmd_trace()
5452 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset; in cmd_trace()
5460 return trace__record(&trace, argc-1, &argv[1]); in cmd_trace()
5463 if (trace.errno_summary && !trace.summary && !trace.summary_only) in cmd_trace()
5464 trace.summary_only = true; in cmd_trace()
5467 if (trace.summary_only) in cmd_trace()
5468 trace.summary = trace.summary_only; in cmd_trace()
5471 if (trace.summary) in cmd_trace()
5475 err = trace__open_output(&trace, output_name); in cmd_trace()
5482 err = evswitch__init(&trace.evswitch, trace.evlist, stderr); in cmd_trace()
5486 err = target__validate(&trace.opts.target); in cmd_trace()
5488 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
5489 fprintf(trace.output, "%s", bf); in cmd_trace()
5493 err = target__parse_uid(&trace.opts.target); in cmd_trace()
5495 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
5496 fprintf(trace.output, "%s", bf); in cmd_trace()
5500 if (!argc && target__none(&trace.opts.target)) in cmd_trace()
5501 trace.opts.target.system_wide = true; in cmd_trace()
5504 err = trace__replay(&trace); in cmd_trace()
5506 err = trace__run(&trace, argc, argv); in cmd_trace()
5510 fclose(trace.output); in cmd_trace()
5512 trace__exit(&trace); in cmd_trace()
5514 augmented_raw_syscalls_bpf__destroy(trace.skel); in cmd_trace()