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'")
59 #include "trace/beauty/beauty.h"
60 #include "trace-event.h"
150 struct trace { struct
153 /** Sorted sycall numbers used by the trace. */ argument
245 static void trace__load_vmlinux_btf(struct trace *trace __maybe_unused) in trace__load_vmlinux_btf() argument
248 if (trace->btf != NULL) in trace__load_vmlinux_btf()
251 trace->btf = btf__load_vmlinux_btf(); in trace__load_vmlinux_btf()
253 fprintf(trace->output, trace->btf ? "vmlinux BTF loaded\n" : in trace__load_vmlinux_btf()
346 * The evsel->priv as used by 'perf trace'
787 #include "trace/beauty/generated/fsconfig_arrays.c"
977 struct btf *btf = arg->trace->btf; in syscall_arg__strtoul_btf_enum()
999 trace__load_vmlinux_btf(arg->trace); in syscall_arg__strtoul_btf_type()
1001 btf = arg->trace->btf; in syscall_arg__strtoul_btf_type()
1066 dump_data_opts.skip_names = !arg->trace->show_arg_names; in btf_struct_scnprintf()
1085 static size_t trace__btf_scnprintf(struct trace *trace, struct syscall_arg *arg, char *bf, in trace__btf_scnprintf() argument
1090 if (trace->btf == NULL) in trace__btf_scnprintf()
1095 syscall_arg_fmt__cache_btf_enum(arg_fmt, trace->btf, type); in trace__btf_scnprintf()
1103 return btf_enum_scnprintf(arg_fmt->type, trace->btf, bf, size, val); in trace__btf_scnprintf()
1105 return btf_struct_scnprintf(arg_fmt->type, trace->btf, bf, size, arg); in trace__btf_scnprintf()
1111 static size_t trace__btf_scnprintf(struct trace *trace __maybe_unused, struct syscall_arg *arg __ma… in trace__btf_scnprintf()
1137 #include "trace/beauty/eventfd.c"
1138 #include "trace/beauty/futex_op.c"
1139 #include "trace/beauty/futex_val3.c"
1140 #include "trace/beauty/mmap.c"
1141 #include "trace/beauty/mode_t.c"
1142 #include "trace/beauty/msg_flags.c"
1143 #include "trace/beauty/open_flags.c"
1144 #include "trace/beauty/perf_event_open.c"
1145 #include "trace/beauty/pid.c"
1146 #include "trace/beauty/sched_policy.c"
1147 #include "trace/beauty/seccomp.c"
1148 #include "trace/beauty/signum.c"
1149 #include "trace/beauty/socket_type.c"
1150 #include "trace/beauty/waitid_options.c"
1589 static struct thread_trace *thread_trace__new(struct trace *trace) in thread_trace__new() argument
1595 if (trace->summary) { in thread_trace__new()
1621 static struct thread_trace *thread__trace(struct thread *thread, struct trace *trace) in thread__trace() argument
1629 thread__set_priv(thread, thread_trace__new(trace)); in thread__trace()
1639 color_fprintf(trace->output, PERF_COLOR_RED, in thread__trace()
1744 struct trace *trace) in thread__fd_path() argument
1748 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1755 if (!trace->live) in thread__fd_path()
1757 ++trace->stats.proc_getname; in thread__fd_path()
1769 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1777 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) in pid__scnprintf_fd() argument
1780 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1783 const char *path = thread__fd_path(thread, fd, trace); in pid__scnprintf_fd()
1840 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1873 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1875 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1878 static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in __trace__fprintf_tstamp() argument
1880 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1891 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1894 return __trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_tstamp()
1915 static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp) in trace__fprintf_comm_tid() argument
1919 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1920 if (trace->show_comm) in trace__fprintf_comm_tid()
1928 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1933 if (trace->show_tstamp) in trace__fprintf_entry_head()
1934 printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1935 if (trace->show_duration) in trace__fprintf_entry_head()
1937 return printed + trace__fprintf_comm_tid(trace, thread, fp); in trace__fprintf_entry_head()
1940 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1947 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1964 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1965 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1986 static int trace__symbols_init(struct trace *trace, struct evlist *evlist) in trace__symbols_init() argument
1993 trace->host = machine__new_host(); in trace__symbols_init()
1994 if (trace->host == NULL) in trace__symbols_init()
1999 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
2003 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
2013 static void trace__symbols__exit(struct trace *trace) in trace__symbols__exit() argument
2015 machine__exit(trace->host); in trace__symbols__exit()
2016 trace->host = NULL; in trace__symbols__exit()
2137 static int syscall__read_info(struct syscall *sc, struct trace *trace) in syscall__read_info() argument
2169 * Fails to read trace point format via sysfs node, so the trace point in syscall__read_info()
2204 trace__load_vmlinux_btf(trace); in syscall__read_info()
2232 static int trace__validate_ev_qualifier(struct trace *trace) in trace__validate_ev_qualifier() argument
2237 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
2239 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
2240 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
2242 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
2244 trace->output); in trace__validate_ev_qualifier()
2249 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
2273 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
2285 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
2286 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
2289 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
2292 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
2294 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
2298 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
2299 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
2305 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
2306 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
2310 static __maybe_unused bool trace__syscall_enabled(struct trace *trace, int id) in trace__syscall_enabled() argument
2314 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
2317 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
2318 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
2321 return !trace->not_ev_qualifier; in trace__syscall_enabled()
2323 return trace->not_ev_qualifier; in trace__syscall_enabled()
2355 * in tools/perf/trace/beauty/mount_flags.c
2379 struct trace *trace, struct thread *thread) in syscall__scnprintf_args() argument
2392 .trace = trace, in syscall__scnprintf_args()
2394 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2429 if (val == 0 && !trace->show_zeros && in syscall__scnprintf_args()
2436 if (trace->show_arg_names) in syscall__scnprintf_args()
2441 if (trace->force_btf || default_scnprintf == NULL || default_scnprintf == SCA_PTR) { in syscall__scnprintf_args()
2442 btf_printed = trace__btf_scnprintf(trace, &arg, bf + printed, in syscall__scnprintf_args()
2518 static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, int id) in trace__find_syscall() argument
2526 if (trace->syscalls.table) { in trace__find_syscall()
2527 struct syscall **sc_entry = bsearch(&key, trace->syscalls.table, in trace__find_syscall()
2528 trace->syscalls.table_size, in trace__find_syscall()
2529 sizeof(trace->syscalls.table[0]), in trace__find_syscall()
2540 tmp = reallocarray(trace->syscalls.table, trace->syscalls.table_size + 1, in trace__find_syscall()
2541 sizeof(trace->syscalls.table[0])); in trace__find_syscall()
2547 trace->syscalls.table = tmp; in trace__find_syscall()
2548 trace->syscalls.table[trace->syscalls.table_size++] = sc; in trace__find_syscall()
2549 qsort(trace->syscalls.table, trace->syscalls.table_size, sizeof(trace->syscalls.table[0]), in trace__find_syscall()
2554 typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel,
2558 static struct syscall *trace__syscall_info(struct trace *trace, struct evsel *evsel, in trace__syscall_info() argument
2578 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", in trace__syscall_info()
2586 sc = trace__find_syscall(trace, e_machine, id); in trace__syscall_info()
2588 err = syscall__read_info(sc, trace); in trace__syscall_info()
2593 fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, in trace__syscall_info()
2596 fprintf(trace->output, "(%s)", sc->name); in trace__syscall_info()
2597 fputs(" information\n", trace->output); in trace__syscall_info()
2611 struct trace *trace) in thread__update_stats() argument
2617 if (trace->summary_mode == SUMMARY__BY_TOTAL) in thread__update_stats()
2618 syscall_stats = trace->syscall_stats; in thread__update_stats()
2640 if (!trace->errno_summary) in thread__update_stats()
2664 static int trace__printf_interrupted_entry(struct trace *trace) in trace__printf_interrupted_entry() argument
2670 if (trace->failure_only || trace->current == NULL) in trace__printf_interrupted_entry()
2673 ttrace = thread__priv(trace->current); in trace__printf_interrupted_entry()
2678 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o… in trace__printf_interrupted_entry()
2679 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str); in trace__printf_interrupted_entry()
2681 if (len < trace->args_alignment - 4) in trace__printf_interrupted_entry()
2682 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " "); in trace__printf_interrupted_entry()
2684 printed += fprintf(trace->output, " ...\n"); in trace__printf_interrupted_entry()
2687 ++trace->nr_events_printed; in trace__printf_interrupted_entry()
2692 static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, in trace__fprintf_sample() argument
2697 if (trace->print_sample) { in trace__fprintf_sample()
2700 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", in trace__fprintf_sample()
2748 static int trace__sys_enter(struct trace *trace, struct evsel *evsel, in trace__sys_enter() argument
2762 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_enter()
2763 e_machine = thread__e_machine(thread, trace->host); in trace__sys_enter()
2764 sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__sys_enter()
2767 ttrace = thread__trace(thread, trace); in trace__sys_enter()
2771 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_enter()
2781 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) in trace__sys_enter()
2782 trace__printf_interrupted_entry(trace); in trace__sys_enter()
2793 if (evsel != trace->syscalls.events.sys_enter) in trace__sys_enter()
2794 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy… in trace__sys_enter()
2800 args, augmented_args, augmented_args_size, trace, thread); in trace__sys_enter()
2803 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { in trace__sys_enter()
2806 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output); in trace__sys_enter()
2807 printed = fprintf(trace->output, "%s)", ttrace->entry_str); in trace__sys_enter()
2808 if (trace->args_alignment > printed) in trace__sys_enter()
2809 alignment = trace->args_alignment - printed; in trace__sys_enter()
2810 fprintf(trace->output, "%*s= ?\n", alignment, " "); in trace__sys_enter()
2818 if (trace->current != thread) { in trace__sys_enter()
2819 thread__put(trace->current); in trace__sys_enter()
2820 trace->current = thread__get(thread); in trace__sys_enter()
2828 static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, in trace__fprintf_sys_enter() argument
2841 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__fprintf_sys_enter()
2842 e_machine = thread__e_machine(thread, trace->host); in trace__fprintf_sys_enter()
2843 sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__fprintf_sys_enter()
2846 ttrace = thread__trace(thread, trace); in trace__fprintf_sys_enter()
2855 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy… in trace__fprintf_sys_enter()
2856 …ll__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); in trace__fprintf_sys_enter()
2857 fprintf(trace->output, "%.*s", (int)printed, msg); in trace__fprintf_sys_enter()
2864 static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, in trace__resolve_callchain() argument
2871 trace->max_stack; in trace__resolve_callchain()
2875 if (machine__resolve(trace->host, &al, sample) < 0) in trace__resolve_callchain()
2884 static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) in trace__fprintf_callchain() argument
2891 …chain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); in trace__fprintf_callchain()
2901 static int trace__sys_exit(struct trace *trace, struct evsel *evsel, in trace__sys_exit() argument
2910 int alignment = trace->args_alignment, e_machine; in trace__sys_exit()
2914 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_exit()
2915 e_machine = thread__e_machine(thread, trace->host); in trace__sys_exit()
2916 sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__sys_exit()
2919 ttrace = thread__trace(thread, trace); in trace__sys_exit()
2923 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_exit()
2927 if (trace->summary) in trace__sys_exit()
2928 thread__update_stats(thread, ttrace, id, sample, ret, trace); in trace__sys_exit()
2930 if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) { in trace__sys_exit()
2933 ++trace->stats.vfs_getname; in trace__sys_exit()
2938 if (trace__filter_duration(trace, duration)) in trace__sys_exit()
2941 } else if (trace->duration_filter) in trace__sys_exit()
2947 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__sys_exit()
2949 if (cursor->nr < trace->min_stack) in trace__sys_exit()
2955 if (trace->summary_only || (ret >= 0 && trace->failure_only)) in trace__sys_exit()
2958 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-… in trace__sys_exit()
2961 printed = fprintf(trace->output, "%s", ttrace->entry_str); in trace__sys_exit()
2963 printed += fprintf(trace->output, " ... ["); in trace__sys_exit()
2964 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); in trace__sys_exit()
2966 printed += fprintf(trace->output, "]: %s()", sc->name); in trace__sys_exit()
2976 fprintf(trace->output, ")%*s= ", alignment, " "); in trace__sys_exit()
2982 fprintf(trace->output, "%ld", ret); in trace__sys_exit()
2989 fprintf(trace->output, "-1 %s (%s)", e, emsg); in trace__sys_exit()
2992 fprintf(trace->output, "0 (Timeout)"); in trace__sys_exit()
2998 .trace = trace, in trace__sys_exit()
3002 fprintf(trace->output, "%s", bf); in trace__sys_exit()
3004 fprintf(trace->output, "%#lx", ret); in trace__sys_exit()
3006 struct thread *child = machine__find_thread(trace->host, ret, ret); in trace__sys_exit()
3009 fprintf(trace->output, "%ld", ret); in trace__sys_exit()
3011 fprintf(trace->output, " (%s)", thread__comm_str(child)); in trace__sys_exit()
3017 fputc('\n', trace->output); in trace__sys_exit()
3023 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX) in trace__sys_exit()
3027 trace__fprintf_callchain(trace, sample); in trace__sys_exit()
3038 static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, in trace__vfs_getname() argument
3042 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__vfs_getname()
3099 static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, in trace__sched_stat_runtime() argument
3105 struct thread *thread = machine__findnew_thread(trace->host, in trace__sched_stat_runtime()
3108 struct thread_trace *ttrace = thread__trace(thread, trace); in trace__sched_stat_runtime()
3114 trace->runtime_ms += runtime_ms; in trace__sched_stat_runtime()
3120 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", in trace__sched_stat_runtime()
3153 static void bpf_output__fprintf(struct trace *trace, in bpf_output__fprintf() argument
3157 bpf_output__printer, NULL, trace->output); in bpf_output__fprintf()
3158 ++trace->nr_events_printed; in bpf_output__fprintf()
3161 static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample… in trace__fprintf_tp_fields() argument
3179 .trace = trace, in trace__fprintf_tp_fields()
3181 .show_string_prefix = trace->show_string_prefix, in trace__fprintf_tp_fields()
3211 if (val == 0 && !trace->show_zeros && !arg->show_zero && arg->strtoul != STUL_BTF_TYPE) in trace__fprintf_tp_fields()
3216 if (trace->show_arg_names) in trace__fprintf_tp_fields()
3219 …btf_printed = trace__btf_scnprintf(trace, &syscall_arg, bf + printed, size - printed, val, field->… in trace__fprintf_tp_fields()
3228 return fprintf(trace->output, "%.*s", (int)printed, bf); in trace__fprintf_tp_fields()
3231 static int trace__event_handler(struct trace *trace, struct evsel *evsel, in trace__event_handler() argument
3241 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__event_handler()
3246 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__event_handler()
3248 if (cursor->nr < trace->min_stack) in trace__event_handler()
3254 trace__printf_interrupted_entry(trace); in trace__event_handler()
3255 trace__fprintf_tstamp(trace, sample->time, trace->output); in trace__event_handler()
3257 if (trace->trace_syscalls && trace->show_duration) in trace__event_handler()
3258 fprintf(trace->output, "( ): "); in trace__event_handler()
3261 trace__fprintf_comm_tid(trace, thread, trace->output); in trace__event_handler()
3263 if (evsel == trace->syscalls.events.bpf_output) { in trace__event_handler()
3265 int e_machine = thread ? thread__e_machine(thread, trace->host) : EM_HOST; in trace__event_handler()
3266 struct syscall *sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__event_handler()
3269 fprintf(trace->output, "%s(", sc->name); in trace__event_handler()
3270 trace__fprintf_sys_enter(trace, evsel, sample); in trace__event_handler()
3271 fputc(')', trace->output); in trace__event_handler()
3282 fprintf(trace->output, "%s(", evsel->name); in trace__event_handler()
3285 bpf_output__fprintf(trace, sample); in trace__event_handler()
3290 trace__fprintf_sys_enter(trace, evsel, sample))) { in trace__event_handler()
3291 if (trace->libtraceevent_print) { in trace__event_handler()
3294 trace->output); in trace__event_handler()
3296 trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); in trace__event_handler()
3302 fprintf(trace->output, ")\n"); in trace__event_handler()
3305 trace__fprintf_callchain(trace, sample); in trace__event_handler()
3309 ++trace->nr_events_printed; in trace__event_handler()
3337 static int trace__pgfault(struct trace *trace, in trace__pgfault() argument
3350 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__pgfault()
3355 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__pgfault()
3357 if (cursor->nr < trace->min_stack) in trace__pgfault()
3363 ttrace = thread__trace(thread, trace); in trace__pgfault()
3369 trace->pfmaj++; in trace__pgfault()
3372 trace->pfmin++; in trace__pgfault()
3375 if (trace->summary_only) in trace__pgfault()
3380 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output); in trace__pgfault()
3382 fprintf(trace->output, "%sfault [", in trace__pgfault()
3386 print_location(trace->output, sample, &al, false, true); in trace__pgfault()
3388 fprintf(trace->output, "] => "); in trace__pgfault()
3401 print_location(trace->output, sample, &al, true, false); in trace__pgfault()
3403 fprintf(trace->output, " (%c%c)\n", map_type, al.level); in trace__pgfault()
3406 trace__fprintf_callchain(trace, sample); in trace__pgfault()
3410 ++trace->nr_events_printed; in trace__pgfault()
3419 static void trace__set_base_time(struct trace *trace, in trace__set_base_time() argument
3431 if (trace->base_time == 0 && !trace->full_time && in trace__set_base_time()
3433 trace->base_time = sample->time; in trace__set_base_time()
3442 struct trace *trace = container_of(tool, struct trace, tool); in trace__process_sample() local
3448 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__process_sample()
3452 trace__set_base_time(trace, evsel, sample); in trace__process_sample()
3455 ++trace->nr_events; in trace__process_sample()
3456 handler(trace, evsel, event, sample); in trace__process_sample()
3463 static int trace__record(struct trace *trace, int argc, const char **argv) in trace__record() argument
3495 if (trace->trace_syscalls) { in trace__record()
3513 if (trace->trace_pgfaults & TRACE_PFMAJ) in trace__record()
3517 if (trace->trace_pgfaults & TRACE_PFMIN) in trace__record()
3531 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
3532 static size_t trace__fprintf_total_summary(struct trace *trace, FILE *fp);
3595 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… in trace__handle_event() argument
3601 trace__process_event(trace, trace->host, event, sample); in trace__handle_event()
3605 evsel = evlist__id2evsel(trace->evlist, sample->id); in trace__handle_event()
3607 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); in trace__handle_event()
3611 if (evswitch__discard(&trace->evswitch, evsel)) in trace__handle_event()
3614 trace__set_base_time(trace, evsel, sample); in trace__handle_event()
3618 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", in trace__handle_event()
3623 handler(trace, evsel, event, sample); in trace__handle_event()
3626 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) in trace__handle_event()
3630 static int trace__add_syscall_newtp(struct trace *trace) in trace__add_syscall_newtp() argument
3633 struct evlist *evlist = trace->evlist; in trace__add_syscall_newtp()
3650 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
3651 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
3656 if (callchain_param.enabled && !trace->kernel_syscallchains) { in trace__add_syscall_newtp()
3665 trace->syscalls.events.sys_enter = sys_enter; in trace__add_syscall_newtp()
3666 trace->syscalls.events.sys_exit = sys_exit; in trace__add_syscall_newtp()
3679 static int trace__set_ev_qualifier_tp_filter(struct trace *trace) in trace__set_ev_qualifier_tp_filter() argument
3683 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, in trace__set_ev_qualifier_tp_filter()
3684 trace->ev_qualifier_ids.nr, in trace__set_ev_qualifier_tp_filter()
3685 trace->ev_qualifier_ids.entries); in trace__set_ev_qualifier_tp_filter()
3690 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) { in trace__set_ev_qualifier_tp_filter()
3691 sys_exit = trace->syscalls.events.sys_exit; in trace__set_ev_qualifier_tp_filter()
3721 static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) in trace__find_bpf_program_by_title() argument
3726 if (trace->skel->obj == NULL) in trace__find_bpf_program_by_title()
3729 bpf_object__for_each_program(pos, trace->skel->obj) { in trace__find_bpf_program_by_title()
3740 static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc, in trace__find_syscall_bpf_prog() argument
3748 prog = trace__find_bpf_program_by_title(trace, default_prog_name); in trace__find_syscall_bpf_prog()
3753 prog = trace__find_bpf_program_by_title(trace, default_prog_name); in trace__find_syscall_bpf_prog()
3760 prog = trace__find_bpf_program_by_title(trace, prog_name); in trace__find_syscall_bpf_prog()
3770 return trace->skel->progs.syscall_unaugmented; in trace__find_syscall_bpf_prog()
3773 static void trace__init_syscall_bpf_progs(struct trace *trace, int e_machine, int id) in trace__init_syscall_bpf_progs() argument
3775 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, id); in trace__init_syscall_bpf_progs()
3780 …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()
3781 …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()
3784 static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int e_machine, int id) in trace__bpf_prog_sys_enter_fd() argument
3786 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, id); in trace__bpf_prog_sys_enter_fd()
3787 …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()
3790 static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int e_machine, int id) in trace__bpf_prog_sys_exit_fd() argument
3792 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, id); in trace__bpf_prog_sys_exit_fd()
3793 …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()
3796 static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int e_machine, int key, unsigned in… in trace__bpf_sys_enter_beauty_map() argument
3799 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, key); in trace__bpf_sys_enter_beauty_map()
3808 trace__load_vmlinux_btf(trace); in trace__bpf_sys_enter_beauty_map()
3809 if (trace->btf == NULL) in trace__bpf_sys_enter_beauty_map()
3834 if (syscall_arg_fmt__cache_btf_struct(&sc->arg_fmt[i], trace->btf, name)) in trace__bpf_sys_enter_beauty_map()
3881 static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, in trace__find_usable_bpf_prog_entry() argument
3898 struct syscall *pair = trace__syscall_info(trace, NULL, sc->e_machine, id); in trace__find_usable_bpf_prog_entry()
3903 pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented) in trace__find_usable_bpf_prog_entry()
3968 …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()
3969 if (pair_prog == trace->skel->progs.syscall_unaugmented) in trace__find_usable_bpf_prog_entry()
3983 static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_machine) in trace__init_syscalls_bpf_prog_array_maps() argument
3985 int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter); in trace__init_syscalls_bpf_prog_array_maps()
3986 int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit); in trace__init_syscalls_bpf_prog_array_maps()
3987 int beauty_map_fd = bpf_map__fd(trace->skel->maps.beauty_map_enter); in trace__init_syscalls_bpf_prog_array_maps()
3994 if (!trace__syscall_enabled(trace, key)) in trace__init_syscalls_bpf_prog_array_maps()
3997 trace__init_syscall_bpf_progs(trace, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
4000 prog_fd = trace__bpf_prog_sys_enter_fd(trace, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
4004 prog_fd = trace__bpf_prog_sys_exit_fd(trace, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
4011 err = trace__bpf_sys_enter_beauty_map(trace, e_machine, key, (unsigned int *)beauty_array); in trace__init_syscalls_bpf_prog_array_maps()
4049 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
4060 if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented) in trace__init_syscalls_bpf_prog_array_maps()
4067 pair_prog = trace__find_usable_bpf_prog_entry(trace, sc); in trace__init_syscalls_bpf_prog_array_maps()
4087 static int trace__set_ev_qualifier_filter(struct trace *trace) in trace__set_ev_qualifier_filter() argument
4089 if (trace->syscalls.events.sys_enter) in trace__set_ev_qualifier_filter()
4090 return trace__set_ev_qualifier_tp_filter(trace); in trace__set_ev_qualifier_filter()
4112 static int trace__set_filter_loop_pids(struct trace *trace) in trace__set_filter_loop_pids() argument
4118 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]); in trace__set_filter_loop_pids()
4121 struct thread *parent = machine__find_thread(trace->host, in trace__set_filter_loop_pids()
4136 err = evlist__append_tp_filter_pids(trace->evlist, nr, pids); in trace__set_filter_loop_pids()
4137 if (!err && trace->filter_pids.map) in trace__set_filter_loop_pids()
4138 err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids); in trace__set_filter_loop_pids()
4143 static int trace__set_filter_pids(struct trace *trace) in trace__set_filter_pids() argument
4152 if (trace->filter_pids.nr > 0) { in trace__set_filter_pids()
4153 err = evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr, in trace__set_filter_pids()
4154 trace->filter_pids.entries); in trace__set_filter_pids()
4155 if (!err && trace->filter_pids.map) { in trace__set_filter_pids()
4156 err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr, in trace__set_filter_pids()
4157 trace->filter_pids.entries); in trace__set_filter_pids()
4159 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) { in trace__set_filter_pids()
4160 err = trace__set_filter_loop_pids(trace); in trace__set_filter_pids()
4166 static int __trace__deliver_event(struct trace *trace, union perf_event *event) in __trace__deliver_event() argument
4168 struct evlist *evlist = trace->evlist; in __trace__deliver_event()
4175 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); in __trace__deliver_event()
4177 trace__handle_event(trace, event, &sample); in __trace__deliver_event()
4183 static int __trace__flush_events(struct trace *trace) in __trace__flush_events() argument
4185 u64 first = ordered_events__first_time(&trace->oe.data); in __trace__flush_events()
4186 u64 flush = trace->oe.last - NSEC_PER_SEC; in __trace__flush_events()
4190 return ordered_events__flush_time(&trace->oe.data, flush); in __trace__flush_events()
4195 static int trace__flush_events(struct trace *trace) in trace__flush_events() argument
4197 return !trace->sort_events ? 0 : __trace__flush_events(trace); in trace__flush_events()
4200 static int trace__deliver_event(struct trace *trace, union perf_event *event) in trace__deliver_event() argument
4204 if (!trace->sort_events) in trace__deliver_event()
4205 return __trace__deliver_event(trace, event); in trace__deliver_event()
4207 err = evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last); in trace__deliver_event()
4211 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0, NULL); in trace__deliver_event()
4215 return trace__flush_events(trace); in trace__deliver_event()
4221 struct trace *trace = container_of(oe, struct trace, oe.data); in ordered_events__deliver_event() local
4223 return __trace__deliver_event(trace, event->event); in ordered_events__deliver_event()
4250 static int trace__expand_filter(struct trace *trace, struct evsel *evsel) in trace__expand_filter() argument
4303 .trace = trace, in trace__expand_filter()
4351 static int trace__expand_filters(struct trace *trace, struct evsel **err_evsel) in trace__expand_filters() argument
4353 struct evlist *evlist = trace->evlist; in trace__expand_filters()
4360 if (trace__expand_filter(trace, evsel)) { in trace__expand_filters()
4369 static int trace__run(struct trace *trace, int argc, const char **argv) in trace__run() argument
4371 struct evlist *evlist = trace->evlist; in trace__run()
4378 trace->live = true; in trace__run()
4380 if (!trace->raw_augmented_syscalls) { in trace__run()
4381 if (trace->trace_syscalls && trace__add_syscall_newtp(trace)) in trace__run()
4384 if (trace->trace_syscalls) in trace__run()
4385 trace->vfs_getname = evlist__add_vfs_getname(evlist); in trace__run()
4388 if ((trace->trace_pgfaults & TRACE_PFMAJ)) { in trace__run()
4392 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param); in trace__run()
4396 if ((trace->trace_pgfaults & TRACE_PFMIN)) { in trace__run()
4400 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param); in trace__run()
4405 trace->opts.ignore_missing_thread = trace->opts.target.uid != UINT_MAX || trace->opts.target.pid; in trace__run()
4407 if (trace->sched && in trace__run()
4414 * trace -G A -e sched:*switch in trace__run()
4419 * trace -e sched:*switch -G A in trace__run()
4427 * trace -G A -e sched:*switch -G B in trace__run()
4435 if (trace->cgroup) in trace__run()
4436 evlist__set_default_cgroup(trace->evlist, trace->cgroup); in trace__run()
4438 err = evlist__create_maps(evlist, &trace->opts.target); in trace__run()
4440 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); in trace__run()
4444 err = trace__symbols_init(trace, evlist); in trace__run()
4446 fprintf(trace->output, "Problems initializing symbol libraries!\n"); in trace__run()
4450 if (trace->summary_mode == SUMMARY__BY_TOTAL) { in trace__run()
4451 trace->syscall_stats = alloc_syscall_stats(); in trace__run()
4452 if (trace->syscall_stats == NULL) in trace__run()
4456 evlist__config(evlist, &trace->opts, &callchain_param); in trace__run()
4459 err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL); in trace__run()
4461 fprintf(trace->output, "Couldn't run the workload!\n"); in trace__run()
4471 if (trace->syscalls.events.bpf_output) { in trace__run()
4478 perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) { in trace__run()
4481 bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__, in trace__run()
4483 xyarray__entry(trace->syscalls.events.bpf_output->core.fd, in trace__run()
4489 if (trace->skel) in trace__run()
4490 trace->filter_pids.map = trace->skel->maps.pids_filtered; in trace__run()
4492 err = trace__set_filter_pids(trace); in trace__run()
4497 if (trace->skel && trace->skel->progs.sys_enter) { in trace__run()
4502 trace__init_syscalls_bpf_prog_array_maps(trace, EM_HOST); in trace__run()
4506 if (trace->ev_qualifier_ids.nr > 0) { in trace__run()
4507 err = trace__set_ev_qualifier_filter(trace); in trace__run()
4511 if (trace->syscalls.events.sys_exit) { in trace__run()
4513 trace->syscalls.events.sys_exit->filter); in trace__run()
4529 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(EM_HOST, "close")); in trace__run()
4531 err = trace__expand_filters(trace, &evsel); in trace__run()
4534 err = evlist__apply_filters(evlist, &evsel, &trace->opts.target); in trace__run()
4538 err = evlist__mmap(evlist, trace->opts.mmap_pages); in trace__run()
4542 if (!target__none(&trace->opts.target) && !trace->opts.target.initial_delay) in trace__run()
4548 if (trace->opts.target.initial_delay) { in trace__run()
4549 usleep(trace->opts.target.initial_delay * 1000); in trace__run()
4553 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 || in trace__run()
4566 evsel->core.attr.sample_max_stack = trace->max_stack; in trace__run()
4569 before = trace->nr_events; in trace__run()
4580 ++trace->nr_events; in trace__run()
4582 err = trace__deliver_event(trace, event); in trace__run()
4599 if (trace->nr_events == before) { in trace__run()
4608 if (trace__flush_events(trace)) in trace__run()
4616 thread__zput(trace->current); in trace__run()
4620 if (trace->sort_events) in trace__run()
4621 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL); in trace__run()
4624 if (trace->summary) { in trace__run()
4625 if (trace->summary_mode == SUMMARY__BY_TOTAL) in trace__run()
4626 trace__fprintf_total_summary(trace, trace->output); in trace__run()
4628 trace__fprintf_thread_summary(trace, trace->output); in trace__run()
4631 if (trace->show_tool_stats) { in trace__run()
4632 fprintf(trace->output, "Stats:\n " in trace__run()
4635 trace->stats.vfs_getname, in trace__run()
4636 trace->stats.proc_getname); in trace__run()
4641 delete_syscall_stats(trace->syscall_stats); in trace__run()
4642 trace__symbols__exit(trace); in trace__run()
4645 cgroup__put(trace->cgroup); in trace__run()
4646 trace->evlist = NULL; in trace__run()
4647 trace->live = false; in trace__run()
4668 fprintf(trace->output, "%s\n", errbuf); in trace__run()
4672 fprintf(trace->output, in trace__run()
4679 fprintf(trace->output, "Not enough memory to run!\n"); in trace__run()
4683 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno)); in trace__run()
4687 static int trace__replay(struct trace *trace) in trace__replay() argument
4695 .force = trace->force, in trace__replay()
4701 perf_tool__init(&trace->tool, /*ordered_events=*/true); in trace__replay()
4702 trace->tool.sample = trace__process_sample; in trace__replay()
4703 trace->tool.mmap = perf_event__process_mmap; in trace__replay()
4704 trace->tool.mmap2 = perf_event__process_mmap2; in trace__replay()
4705 trace->tool.comm = perf_event__process_comm; in trace__replay()
4706 trace->tool.exit = perf_event__process_exit; in trace__replay()
4707 trace->tool.fork = perf_event__process_fork; in trace__replay()
4708 trace->tool.attr = perf_event__process_attr; in trace__replay()
4709 trace->tool.tracing_data = perf_event__process_tracing_data; in trace__replay()
4710 trace->tool.build_id = perf_event__process_build_id; in trace__replay()
4711 trace->tool.namespaces = perf_event__process_namespaces; in trace__replay()
4713 trace->tool.ordered_events = true; in trace__replay()
4714 trace->tool.ordering_requires_timestamps = true; in trace__replay()
4717 trace->multiple_threads = true; in trace__replay()
4719 session = perf_session__new(&data, &trace->tool); in trace__replay()
4723 if (trace->opts.target.pid) in trace__replay()
4724 symbol_conf.pid_list_str = strdup(trace->opts.target.pid); in trace__replay()
4726 if (trace->opts.target.tid) in trace__replay()
4727 symbol_conf.tid_list_str = strdup(trace->opts.target.tid); in trace__replay()
4732 trace->host = &session->machines.host; in trace__replay()
4739 trace->syscalls.events.sys_enter = evsel; in trace__replay()
4752 trace->syscalls.events.sys_exit = evsel; in trace__replay()
4770 if (trace->summary_mode == SUMMARY__BY_TOTAL) { in trace__replay()
4771 trace->syscall_stats = alloc_syscall_stats(); in trace__replay()
4772 if (trace->syscall_stats == NULL) in trace__replay()
4782 else if (trace->summary) in trace__replay()
4783 trace__fprintf_thread_summary(trace, trace->output); in trace__replay()
4786 delete_syscall_stats(trace->syscall_stats); in trace__replay()
4842 static size_t syscall__dump_stats(struct trace *trace, int e_machine, FILE *fp, in syscall__dump_stats() argument
4873 sc = trace__syscall_info(trace, /*evsel=*/NULL, e_machine, entry->syscall); in syscall__dump_stats()
4882 if (trace->errno_summary && stats->nr_failures) { in syscall__dump_stats()
4887 …fprintf(fp, "\t\t\t\t%s: %d\n", perf_env__arch_strerrno(trace->host->env, e + 1), stats->errnos[e]… in syscall__dump_stats()
4900 struct trace *trace, int e_machine, FILE *fp) in thread__dump_stats() argument
4902 return syscall__dump_stats(trace, e_machine, fp, ttrace->syscall_stats); in thread__dump_stats()
4905 static size_t system__dump_stats(struct trace *trace, int e_machine, FILE *fp) in system__dump_stats() argument
4907 return syscall__dump_stats(trace, e_machine, fp, trace->syscall_stats); in system__dump_stats()
4910 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) in trace__fprintf_thread() argument
4914 int e_machine = thread__e_machine(thread, trace->host); in trace__fprintf_thread()
4920 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; in trace__fprintf_thread()
4929 if (trace->sched) in trace__fprintf_thread()
4934 printed += thread__dump_stats(ttrace, trace, e_machine, fp); in trace__fprintf_thread()
4962 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) in trace__fprintf_thread_summary() argument
4967 if (machine__thread_list(trace->host, &threads) == 0) { in trace__fprintf_thread_summary()
4973 printed += trace__fprintf_thread(fp, pos->thread, trace); in trace__fprintf_thread_summary()
4979 static size_t trace__fprintf_total_summary(struct trace *trace, FILE *fp) in trace__fprintf_total_summary() argument
4984 printed += fprintf(fp, "%lu events", trace->nr_events); in trace__fprintf_total_summary()
4986 if (trace->pfmaj) in trace__fprintf_total_summary()
4987 printed += fprintf(fp, ", %lu majfaults", trace->pfmaj); in trace__fprintf_total_summary()
4988 if (trace->pfmin) in trace__fprintf_total_summary()
4989 printed += fprintf(fp, ", %lu minfaults", trace->pfmin); in trace__fprintf_total_summary()
4990 if (trace->sched) in trace__fprintf_total_summary()
4991 printed += fprintf(fp, ", %.3f msec\n", trace->runtime_ms); in trace__fprintf_total_summary()
4996 printed += system__dump_stats(trace, EM_HOST, fp); in trace__fprintf_total_summary()
5004 struct trace *trace = opt->value; in trace__set_duration() local
5006 trace->duration_filter = atof(str); in trace__set_duration()
5015 struct trace *trace = opt->value; in trace__set_filter_pids_from_option() local
5025 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; in trace__set_filter_pids_from_option()
5026 trace->filter_pids.entries = calloc(i, sizeof(pid_t)); in trace__set_filter_pids_from_option()
5028 if (trace->filter_pids.entries == NULL) in trace__set_filter_pids_from_option()
5031 trace->filter_pids.entries[0] = getpid(); in trace__set_filter_pids_from_option()
5033 for (i = 1; i < trace->filter_pids.nr; ++i) in trace__set_filter_pids_from_option()
5034 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; in trace__set_filter_pids_from_option()
5042 static int trace__open_output(struct trace *trace, const char *filename) in trace__open_output() argument
5054 trace->output = fopen(filename, "w"); in trace__open_output()
5056 return trace->output == NULL ? -errno : 0; in trace__open_output()
5159 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
5167 struct trace *trace = (struct trace *)opt->value; in trace__parse_events_option() local
5180 trace->not_ev_qualifier = true; in trace__parse_events_option()
5226 trace->ev_qualifier = strlist__new(lists[1], &slist_config); in trace__parse_events_option()
5227 if (trace->ev_qualifier == NULL) { in trace__parse_events_option()
5228 fputs("Not enough memory to parse event qualifier", trace->output); in trace__parse_events_option()
5232 if (trace__validate_ev_qualifier(trace)) in trace__parse_events_option()
5234 trace->trace_syscalls = true; in trace__parse_events_option()
5241 .evlistp = &trace->evlist, in trace__parse_events_option()
5260 struct trace *trace = opt->value; in trace__parse_cgroups() local
5262 if (!list_empty(&trace->evlist->core.entries)) { in trace__parse_cgroups()
5264 .value = &trace->evlist, in trace__parse_cgroups()
5268 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str); in trace__parse_cgroups()
5276 struct trace *trace = opt->value; in trace__parse_summary_mode() local
5279 trace->summary_mode = SUMMARY__BY_THREAD; in trace__parse_summary_mode()
5281 trace->summary_mode = SUMMARY__BY_TOTAL; in trace__parse_summary_mode()
5292 struct trace *trace = arg; in trace__config() local
5295 if (!strcmp(var, "trace.add_events")) { in trace__config()
5296 trace->perfconfig_events = strdup(value); in trace__config()
5297 if (trace->perfconfig_events == NULL) { in trace__config()
5298 pr_err("Not enough memory for %s\n", "trace.add_events"); in trace__config()
5301 } else if (!strcmp(var, "trace.show_timestamp")) { in trace__config()
5302 trace->show_tstamp = perf_config_bool(var, value); in trace__config()
5303 } else if (!strcmp(var, "trace.show_duration")) { in trace__config()
5304 trace->show_duration = perf_config_bool(var, value); in trace__config()
5305 } else if (!strcmp(var, "trace.show_arg_names")) { in trace__config()
5306 trace->show_arg_names = perf_config_bool(var, value); in trace__config()
5307 if (!trace->show_arg_names) in trace__config()
5308 trace->show_zeros = true; in trace__config()
5309 } else if (!strcmp(var, "trace.show_zeros")) { in trace__config()
5311 if (!trace->show_arg_names && !new_show_zeros) { in trace__config()
5312 pr_warning("trace.show_zeros has to be set when trace.show_arg_names=no\n"); in trace__config()
5315 trace->show_zeros = new_show_zeros; in trace__config()
5316 } else if (!strcmp(var, "trace.show_prefix")) { in trace__config()
5317 trace->show_string_prefix = perf_config_bool(var, value); in trace__config()
5318 } else if (!strcmp(var, "trace.no_inherit")) { in trace__config()
5319 trace->opts.no_inherit = perf_config_bool(var, value); in trace__config()
5320 } else if (!strcmp(var, "trace.args_alignment")) { in trace__config()
5323 trace->args_alignment = args_alignment; in trace__config()
5324 } else if (!strcmp(var, "trace.tracepoint_beautifiers")) { in trace__config()
5326 trace->libtraceevent_print = true; in trace__config()
5328 trace->libtraceevent_print = false; in trace__config()
5334 static void trace__exit(struct trace *trace) in trace__exit() argument
5336 strlist__delete(trace->ev_qualifier); in trace__exit()
5337 zfree(&trace->ev_qualifier_ids.entries); in trace__exit()
5338 if (trace->syscalls.table) { in trace__exit()
5339 for (size_t i = 0; i < trace->syscalls.table_size; i++) in trace__exit()
5340 syscall__delete(trace->syscalls.table[i]); in trace__exit()
5341 zfree(&trace->syscalls.table); in trace__exit()
5343 zfree(&trace->perfconfig_events); in trace__exit()
5344 evlist__delete(trace->evlist); in trace__exit()
5345 trace->evlist = NULL; in trace__exit()
5347 btf__free(trace->btf); in trace__exit()
5348 trace->btf = NULL; in trace__exit()
5367 "perf trace [<options>] [<command>]", in cmd_trace()
5368 "perf trace [<options>] -- <command> [<options>]", in cmd_trace()
5369 "perf trace record [<options>] [<command>]", in cmd_trace()
5370 "perf trace record [<options>] -- <command> [<options>]", in cmd_trace()
5373 struct trace trace = { in cmd_trace() local
5397 OPT_CALLBACK('e', "event", &trace, "event", in cmd_trace()
5400 OPT_CALLBACK(0, "filter", &trace.evlist, "filter", in cmd_trace()
5402 OPT_BOOLEAN(0, "comm", &trace.show_comm, in cmd_trace()
5404 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), in cmd_trace()
5405 OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace", in cmd_trace()
5409 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", in cmd_trace()
5410 "trace events on existing process id"), in cmd_trace()
5411 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", in cmd_trace()
5412 "trace events on existing thread id"), in cmd_trace()
5413 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids", in cmd_trace()
5415 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, in cmd_trace()
5417 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", in cmd_trace()
5419 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, in cmd_trace()
5421 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", in cmd_trace()
5423 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", in cmd_trace()
5425 OPT_CALLBACK(0, "duration", &trace, "float", in cmd_trace()
5428 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), in cmd_trace()
5430 OPT_BOOLEAN('T', "time", &trace.full_time, in cmd_trace()
5432 OPT_BOOLEAN(0, "failure", &trace.failure_only, in cmd_trace()
5434 OPT_BOOLEAN('s', "summary", &trace.summary_only, in cmd_trace()
5436 OPT_BOOLEAN('S', "with-summary", &trace.summary, in cmd_trace()
5438 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary, in cmd_trace()
5440 OPT_CALLBACK(0, "summary-mode", &trace, "mode", in cmd_trace()
5443 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", in cmd_trace()
5444 "Trace pagefaults", parse_pagefaults, "maj"), in cmd_trace()
5445 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), in cmd_trace()
5446 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), in cmd_trace()
5447 OPT_CALLBACK(0, "call-graph", &trace.opts, in cmd_trace()
5450 OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print, in cmd_trace()
5452 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, in cmd_trace()
5454 OPT_ULONG(0, "max-events", &trace.max_events, in cmd_trace()
5456 OPT_UINTEGER(0, "min-stack", &trace.min_stack, in cmd_trace()
5459 OPT_UINTEGER(0, "max-stack", &trace.max_stack, in cmd_trace()
5463 OPT_BOOLEAN(0, "sort-events", &trace.sort_events, in cmd_trace()
5465 OPT_BOOLEAN(0, "print-sample", &trace.print_sample, in cmd_trace()
5469 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only", in cmd_trace()
5471 OPT_INTEGER('D', "delay", &trace.opts.target.initial_delay, in cmd_trace()
5474 OPT_BOOLEAN(0, "force-btf", &trace.force_btf, "Prefer btf_dump general pretty printer" in cmd_trace()
5476 OPTS_EVSWITCH(&trace.evswitch), in cmd_trace()
5496 trace.evlist = evlist__new(); in cmd_trace()
5498 if (trace.evlist == NULL) { in cmd_trace()
5508 * global setting. If it fails we'll get something in 'perf trace -v' in cmd_trace()
5513 err = perf_config(trace__config, &trace); in cmd_trace()
5529 * .perfconfig trace.add_events, and filter those out. in cmd_trace()
5531 if (!trace.trace_syscalls && !trace.trace_pgfaults && in cmd_trace()
5532 trace.evlist->core.nr_entries == 0 /* Was --events used? */) { in cmd_trace()
5533 trace.trace_syscalls = true; in cmd_trace()
5541 if (trace.perfconfig_events != NULL) { in cmd_trace()
5545 err = parse_events(trace.evlist, trace.perfconfig_events, &parse_err); in cmd_trace()
5547 parse_events_error__print(&parse_err, trace.perfconfig_events); in cmd_trace()
5553 if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) { in cmd_trace()
5559 if (!trace.trace_syscalls) in cmd_trace()
5567 trace.skel = augmented_raw_syscalls_bpf__open(); in cmd_trace()
5568 if (!trace.skel) { in cmd_trace()
5577 bpf_object__for_each_program(prog, trace.skel->obj) { in cmd_trace()
5578 if (prog != trace.skel->progs.sys_enter && prog != trace.skel->progs.sys_exit) in cmd_trace()
5582 err = augmented_raw_syscalls_bpf__load(trace.skel); in cmd_trace()
5588 augmented_raw_syscalls_bpf__attach(trace.skel); in cmd_trace()
5589 trace__add_syscall_newtp(&trace); in cmd_trace()
5593 err = bpf__setup_bpf_output(trace.evlist); in cmd_trace()
5599 trace.syscalls.events.bpf_output = evlist__last(trace.evlist); in cmd_trace()
5600 assert(evsel__name_is(trace.syscalls.events.bpf_output, "__augmented_syscalls__")); in cmd_trace()
5605 if (trace.trace_pgfaults) { in cmd_trace()
5606 trace.opts.sample_address = true; in cmd_trace()
5607 trace.opts.sample_time = true; in cmd_trace()
5610 if (trace.opts.mmap_pages == UINT_MAX) in cmd_trace()
5613 if (trace.max_stack == UINT_MAX) { in cmd_trace()
5614 trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack(); in cmd_trace()
5619 if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) { in cmd_trace()
5620 record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false); in cmd_trace()
5626 trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4; in cmd_trace()
5631 if (trace.evlist->core.nr_entries > 0) { in cmd_trace()
5634 evlist__set_default_evsel_handler(trace.evlist, trace__event_handler); in cmd_trace()
5635 if (evlist__set_syscall_tp_fields(trace.evlist, &use_btf)) { in cmd_trace()
5641 trace__load_vmlinux_btf(&trace); in cmd_trace()
5644 if (trace.sort_events) { in cmd_trace()
5645 ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace); in cmd_trace()
5646 ordered_events__set_copy_on_queue(&trace.oe.data, true); in cmd_trace()
5660 if (trace.syscalls.events.bpf_output) { in cmd_trace()
5661 evlist__for_each_entry(trace.evlist, evsel) { in cmd_trace()
5665 trace.raw_augmented_syscalls = true; in cmd_trace()
5669 if (trace.syscalls.events.bpf_output->priv == NULL && in cmd_trace()
5671 struct evsel *augmented = trace.syscalls.events.bpf_output; in cmd_trace()
5718 if (trace.raw_augmented_syscalls) in cmd_trace()
5719 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset; in cmd_trace()
5727 err = trace__record(&trace, argc-1, &argv[1]); in cmd_trace()
5732 if (trace.errno_summary && !trace.summary && !trace.summary_only) in cmd_trace()
5733 trace.summary_only = true; in cmd_trace()
5736 if (trace.summary_only) in cmd_trace()
5737 trace.summary = trace.summary_only; in cmd_trace()
5740 if (trace.summary) { in cmd_trace()
5742 if (trace.summary_mode == SUMMARY__NONE) in cmd_trace()
5743 trace.summary_mode = SUMMARY__BY_THREAD; in cmd_trace()
5747 err = trace__open_output(&trace, output_name); in cmd_trace()
5754 err = evswitch__init(&trace.evswitch, trace.evlist, stderr); in cmd_trace()
5758 err = target__validate(&trace.opts.target); in cmd_trace()
5760 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
5761 fprintf(trace.output, "%s", bf); in cmd_trace()
5765 err = target__parse_uid(&trace.opts.target); in cmd_trace()
5767 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
5768 fprintf(trace.output, "%s", bf); in cmd_trace()
5772 if (!argc && target__none(&trace.opts.target)) in cmd_trace()
5773 trace.opts.target.system_wide = true; in cmd_trace()
5776 err = trace__replay(&trace); in cmd_trace()
5778 err = trace__run(&trace, argc, argv); in cmd_trace()
5782 fclose(trace.output); in cmd_trace()
5784 trace__exit(&trace); in cmd_trace()
5786 augmented_raw_syscalls_bpf__destroy(trace.skel); in cmd_trace()