Lines Matching refs:trace

142 struct trace {  struct
237 static void trace__load_vmlinux_btf(struct trace *trace __maybe_unused) in trace__load_vmlinux_btf() argument
240 if (trace->btf != NULL) in trace__load_vmlinux_btf()
243 trace->btf = btf__load_vmlinux_btf(); in trace__load_vmlinux_btf()
245 fprintf(trace->output, trace->btf ? "vmlinux BTF loaded\n" : in trace__load_vmlinux_btf()
969 struct btf *btf = arg->trace->btf; in syscall_arg__strtoul_btf_enum()
991 trace__load_vmlinux_btf(arg->trace); in syscall_arg__strtoul_btf_type()
993 btf = arg->trace->btf; in syscall_arg__strtoul_btf_type()
1058 dump_data_opts.skip_names = !arg->trace->show_arg_names; in btf_struct_scnprintf()
1077 static size_t trace__btf_scnprintf(struct trace *trace, struct syscall_arg *arg, char *bf, in trace__btf_scnprintf() argument
1082 if (trace->btf == NULL) in trace__btf_scnprintf()
1087 syscall_arg_fmt__cache_btf_enum(arg_fmt, trace->btf, type); in trace__btf_scnprintf()
1095 return btf_enum_scnprintf(arg_fmt->type, trace->btf, bf, size, val); in trace__btf_scnprintf()
1097 return btf_struct_scnprintf(arg_fmt->type, trace->btf, bf, size, arg); in trace__btf_scnprintf()
1103 static size_t trace__btf_scnprintf(struct trace *trace __maybe_unused, struct syscall_arg *arg __ma… in trace__btf_scnprintf()
1583 static struct thread_trace *thread_trace__new(struct trace *trace) in thread_trace__new() argument
1589 if (trace->summary) { in thread_trace__new()
1615 static struct thread_trace *thread__trace(struct thread *thread, struct trace *trace) in thread__trace() argument
1623 thread__set_priv(thread, thread_trace__new(trace)); in thread__trace()
1633 color_fprintf(trace->output, PERF_COLOR_RED, in thread__trace()
1739 struct trace *trace) in thread__fd_path() argument
1743 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1750 if (!trace->live) in thread__fd_path()
1752 ++trace->stats.proc_getname; in thread__fd_path()
1764 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1772 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) in pid__scnprintf_fd() argument
1775 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1778 const char *path = thread__fd_path(thread, fd, trace); in pid__scnprintf_fd()
1835 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1868 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1870 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1873 static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in __trace__fprintf_tstamp() argument
1875 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1886 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1889 return __trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_tstamp()
1910 static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp) in trace__fprintf_comm_tid() argument
1914 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1915 if (trace->show_comm) in trace__fprintf_comm_tid()
1923 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1928 if (trace->show_tstamp) in trace__fprintf_entry_head()
1929 printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1930 if (trace->show_duration) in trace__fprintf_entry_head()
1932 return printed + trace__fprintf_comm_tid(trace, thread, fp); in trace__fprintf_entry_head()
1935 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1942 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1959 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1960 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1981 static int trace__symbols_init(struct trace *trace, int argc, const char **argv, in trace__symbols_init() argument
1989 perf_env__init(&trace->host_env); in trace__symbols_init()
1990 err = perf_env__set_cmdline(&trace->host_env, argc, argv); in trace__symbols_init()
1994 trace->host = machine__new_host(&trace->host_env); in trace__symbols_init()
1995 if (trace->host == NULL) { in trace__symbols_init()
2001 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
2005 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
2010 perf_env__exit(&trace->host_env); in trace__symbols_init()
2016 static void trace__symbols__exit(struct trace *trace) in trace__symbols__exit() argument
2018 machine__exit(trace->host); in trace__symbols__exit()
2019 trace->host = NULL; in trace__symbols__exit()
2021 perf_env__exit(&trace->host_env); in trace__symbols__exit()
2141 static int syscall__read_info(struct syscall *sc, struct trace *trace) in syscall__read_info() argument
2208 trace__load_vmlinux_btf(trace); in syscall__read_info()
2236 static int trace__validate_ev_qualifier(struct trace *trace) in trace__validate_ev_qualifier() argument
2241 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
2243 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
2244 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
2246 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
2248 trace->output); in trace__validate_ev_qualifier()
2253 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
2277 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
2289 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
2290 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
2293 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
2296 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
2298 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
2302 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
2303 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
2309 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
2310 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
2314 static __maybe_unused bool trace__syscall_enabled(struct trace *trace, int id) in trace__syscall_enabled() argument
2318 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
2321 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
2322 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
2325 return !trace->not_ev_qualifier; in trace__syscall_enabled()
2327 return trace->not_ev_qualifier; in trace__syscall_enabled()
2383 struct trace *trace, struct thread *thread) in syscall__scnprintf_args() argument
2396 .trace = trace, in syscall__scnprintf_args()
2398 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2433 if (val == 0 && !trace->show_zeros && in syscall__scnprintf_args()
2440 if (trace->show_arg_names) in syscall__scnprintf_args()
2445 if (trace->force_btf || default_scnprintf == NULL || default_scnprintf == SCA_PTR) { in syscall__scnprintf_args()
2446 btf_printed = trace__btf_scnprintf(trace, &arg, bf + printed, in syscall__scnprintf_args()
2522 static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, int id) in trace__find_syscall() argument
2530 if (trace->syscalls.table) { in trace__find_syscall()
2531 struct syscall **sc_entry = bsearch(&key, trace->syscalls.table, in trace__find_syscall()
2532 trace->syscalls.table_size, in trace__find_syscall()
2533 sizeof(trace->syscalls.table[0]), in trace__find_syscall()
2544 tmp = reallocarray(trace->syscalls.table, trace->syscalls.table_size + 1, in trace__find_syscall()
2545 sizeof(trace->syscalls.table[0])); in trace__find_syscall()
2551 trace->syscalls.table = tmp; in trace__find_syscall()
2552 trace->syscalls.table[trace->syscalls.table_size++] = sc; in trace__find_syscall()
2553 qsort(trace->syscalls.table, trace->syscalls.table_size, sizeof(trace->syscalls.table[0]), in trace__find_syscall()
2558 typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel,
2562 static struct syscall *trace__syscall_info(struct trace *trace, struct evsel *evsel, in trace__syscall_info() argument
2582 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", in trace__syscall_info()
2590 sc = trace__find_syscall(trace, e_machine, id); in trace__syscall_info()
2592 err = syscall__read_info(sc, trace); in trace__syscall_info()
2597 fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, in trace__syscall_info()
2600 fprintf(trace->output, "(%s)", sc->name); in trace__syscall_info()
2601 fputs(" information\n", trace->output); in trace__syscall_info()
2615 struct trace *trace) in thread__update_stats() argument
2621 if (trace->summary_bpf) in thread__update_stats()
2624 if (trace->summary_mode == SUMMARY__BY_TOTAL) in thread__update_stats()
2625 syscall_stats = trace->syscall_stats; in thread__update_stats()
2647 if (!trace->errno_summary) in thread__update_stats()
2671 static int trace__printf_interrupted_entry(struct trace *trace) in trace__printf_interrupted_entry() argument
2677 if (trace->failure_only || trace->current == NULL) in trace__printf_interrupted_entry()
2680 ttrace = thread__priv(trace->current); in trace__printf_interrupted_entry()
2685 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o… in trace__printf_interrupted_entry()
2686 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str); in trace__printf_interrupted_entry()
2688 if (len < trace->args_alignment - 4) in trace__printf_interrupted_entry()
2689 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " "); in trace__printf_interrupted_entry()
2691 printed += fprintf(trace->output, " ...\n"); in trace__printf_interrupted_entry()
2694 ++trace->nr_events_printed; in trace__printf_interrupted_entry()
2699 static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, in trace__fprintf_sample() argument
2704 if (trace->print_sample) { in trace__fprintf_sample()
2707 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", in trace__fprintf_sample()
2755 static int trace__sys_enter(struct trace *trace, struct evsel *evsel, in trace__sys_enter() argument
2769 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_enter()
2770 e_machine = thread__e_machine(thread, trace->host); in trace__sys_enter()
2771 sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__sys_enter()
2774 ttrace = thread__trace(thread, trace); in trace__sys_enter()
2778 trace__fprintf_sample(trace, evsel, sample, thread); in trace__sys_enter()
2788 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) in trace__sys_enter()
2789 trace__printf_interrupted_entry(trace); in trace__sys_enter()
2800 if (evsel != trace->syscalls.events.sys_enter) in trace__sys_enter()
2801 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy… in trace__sys_enter()
2807 args, augmented_args, augmented_args_size, trace, thread); in trace__sys_enter()
2810 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { in trace__sys_enter()
2813 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output); in trace__sys_enter()
2814 printed = fprintf(trace->output, "%s)", ttrace->entry_str); in trace__sys_enter()
2815 if (trace->args_alignment > printed) in trace__sys_enter()
2816 alignment = trace->args_alignment - printed; in trace__sys_enter()
2817 fprintf(trace->output, "%*s= ?\n", alignment, " "); in trace__sys_enter()
2825 if (trace->current != thread) { in trace__sys_enter()
2826 thread__put(trace->current); in trace__sys_enter()
2827 trace->current = thread__get(thread); in trace__sys_enter()
2835 static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, in trace__fprintf_sys_enter() argument
2848 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__fprintf_sys_enter()
2849 e_machine = thread__e_machine(thread, trace->host); in trace__fprintf_sys_enter()
2850 sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__fprintf_sys_enter()
2853 ttrace = thread__trace(thread, trace); in trace__fprintf_sys_enter()
2862 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy… in trace__fprintf_sys_enter()
2863 …ll__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); in trace__fprintf_sys_enter()
2864 fprintf(trace->output, "%.*s", (int)printed, msg); in trace__fprintf_sys_enter()
2871 static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, in trace__resolve_callchain() argument
2878 trace->max_stack; in trace__resolve_callchain()
2882 if (machine__resolve(trace->host, &al, sample) < 0) in trace__resolve_callchain()
2891 static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) in trace__fprintf_callchain() argument
2898 …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()
2986 struct perf_env *env = evsel__env(evsel) ?: &trace->host_env; in trace__sys_exit()
2990 fprintf(trace->output, "-1 %s (%s)", e, emsg); in trace__sys_exit()
2993 fprintf(trace->output, "0 (Timeout)"); in trace__sys_exit()
2999 .trace = trace, in trace__sys_exit()
3003 fprintf(trace->output, "%s", bf); in trace__sys_exit()
3005 fprintf(trace->output, "%#lx", ret); in trace__sys_exit()
3007 struct thread *child = machine__find_thread(trace->host, ret, ret); in trace__sys_exit()
3009 fprintf(trace->output, "%ld", ret); in trace__sys_exit()
3012 fprintf(trace->output, " (%s)", thread__comm_str(child)); in trace__sys_exit()
3018 fputc('\n', trace->output); in trace__sys_exit()
3024 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX) in trace__sys_exit()
3028 trace__fprintf_callchain(trace, sample); in trace__sys_exit()
3039 static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, in trace__vfs_getname() argument
3043 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__vfs_getname()
3100 static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, in trace__sched_stat_runtime() argument
3106 struct thread *thread = machine__findnew_thread(trace->host, in trace__sched_stat_runtime()
3109 struct thread_trace *ttrace = thread__trace(thread, trace); in trace__sched_stat_runtime()
3115 trace->runtime_ms += runtime_ms; in trace__sched_stat_runtime()
3121 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", in trace__sched_stat_runtime()
3154 static void bpf_output__fprintf(struct trace *trace, in bpf_output__fprintf() argument
3158 bpf_output__printer, NULL, trace->output); in bpf_output__fprintf()
3159 ++trace->nr_events_printed; in bpf_output__fprintf()
3162 static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample… in trace__fprintf_tp_fields() argument
3180 .trace = trace, in trace__fprintf_tp_fields()
3182 .show_string_prefix = trace->show_string_prefix, in trace__fprintf_tp_fields()
3212 if (val == 0 && !trace->show_zeros && !arg->show_zero && arg->strtoul != STUL_BTF_TYPE) in trace__fprintf_tp_fields()
3217 if (trace->show_arg_names) in trace__fprintf_tp_fields()
3220 …btf_printed = trace__btf_scnprintf(trace, &syscall_arg, bf + printed, size - printed, val, field->… in trace__fprintf_tp_fields()
3229 return fprintf(trace->output, "%.*s", (int)printed, bf); in trace__fprintf_tp_fields()
3232 static int trace__event_handler(struct trace *trace, struct evsel *evsel, in trace__event_handler() argument
3242 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__event_handler()
3247 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__event_handler()
3249 if (cursor->nr < trace->min_stack) in trace__event_handler()
3255 trace__printf_interrupted_entry(trace); in trace__event_handler()
3256 trace__fprintf_tstamp(trace, sample->time, trace->output); in trace__event_handler()
3258 if (trace->trace_syscalls && trace->show_duration) in trace__event_handler()
3259 fprintf(trace->output, "( ): "); in trace__event_handler()
3262 trace__fprintf_comm_tid(trace, thread, trace->output); in trace__event_handler()
3264 if (evsel == trace->syscalls.events.bpf_output) { in trace__event_handler()
3266 int e_machine = thread ? thread__e_machine(thread, trace->host) : EM_HOST; in trace__event_handler()
3267 struct syscall *sc = trace__syscall_info(trace, evsel, e_machine, id); in trace__event_handler()
3270 fprintf(trace->output, "%s(", sc->name); in trace__event_handler()
3271 trace__fprintf_sys_enter(trace, evsel, sample); in trace__event_handler()
3272 fputc(')', trace->output); in trace__event_handler()
3283 fprintf(trace->output, "%s(", evsel->name); in trace__event_handler()
3286 bpf_output__fprintf(trace, sample); in trace__event_handler()
3291 trace__fprintf_sys_enter(trace, evsel, sample))) { in trace__event_handler()
3292 if (trace->libtraceevent_print) { in trace__event_handler()
3295 trace->output); in trace__event_handler()
3297 trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); in trace__event_handler()
3303 fprintf(trace->output, ")\n"); in trace__event_handler()
3306 trace__fprintf_callchain(trace, sample); in trace__event_handler()
3310 ++trace->nr_events_printed; in trace__event_handler()
3338 static int trace__pgfault(struct trace *trace, in trace__pgfault() argument
3351 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__pgfault()
3356 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); in trace__pgfault()
3358 if (cursor->nr < trace->min_stack) in trace__pgfault()
3364 ttrace = thread__trace(thread, trace); in trace__pgfault()
3370 trace->pfmaj++; in trace__pgfault()
3373 trace->pfmin++; in trace__pgfault()
3376 if (trace->summary_only) in trace__pgfault()
3381 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output); in trace__pgfault()
3383 fprintf(trace->output, "%sfault [", in trace__pgfault()
3387 print_location(trace->output, sample, &al, false, true); in trace__pgfault()
3389 fprintf(trace->output, "] => "); in trace__pgfault()
3402 print_location(trace->output, sample, &al, true, false); in trace__pgfault()
3404 fprintf(trace->output, " (%c%c)\n", map_type, al.level); in trace__pgfault()
3407 trace__fprintf_callchain(trace, sample); in trace__pgfault()
3411 ++trace->nr_events_printed; in trace__pgfault()
3420 static void trace__set_base_time(struct trace *trace, in trace__set_base_time() argument
3432 if (trace->base_time == 0 && !trace->full_time && in trace__set_base_time()
3434 trace->base_time = sample->time; in trace__set_base_time()
3443 struct trace *trace = container_of(tool, struct trace, tool); in trace__process_sample() local
3449 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__process_sample()
3453 trace__set_base_time(trace, evsel, sample); in trace__process_sample()
3456 ++trace->nr_events; in trace__process_sample()
3457 handler(trace, evsel, event, sample); in trace__process_sample()
3464 static int trace__record(struct trace *trace, int argc, const char **argv) in trace__record() argument
3496 if (trace->trace_syscalls) { in trace__record()
3514 if (trace->trace_pgfaults & TRACE_PFMAJ) in trace__record()
3518 if (trace->trace_pgfaults & TRACE_PFMIN) in trace__record()
3532 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
3533 static size_t trace__fprintf_total_summary(struct trace *trace, FILE *fp);
3596 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… in trace__handle_event() argument
3602 trace__process_event(trace, trace->host, event, sample); in trace__handle_event()
3606 evsel = evlist__id2evsel(trace->evlist, sample->id); in trace__handle_event()
3608 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); in trace__handle_event()
3612 if (evswitch__discard(&trace->evswitch, evsel)) in trace__handle_event()
3615 trace__set_base_time(trace, evsel, sample); in trace__handle_event()
3619 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", in trace__handle_event()
3624 handler(trace, evsel, event, sample); in trace__handle_event()
3627 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) in trace__handle_event()
3631 static int trace__add_syscall_newtp(struct trace *trace) in trace__add_syscall_newtp() argument
3634 struct evlist *evlist = trace->evlist; in trace__add_syscall_newtp()
3651 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
3652 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param); in trace__add_syscall_newtp()
3657 if (callchain_param.enabled && !trace->kernel_syscallchains) { in trace__add_syscall_newtp()
3666 trace->syscalls.events.sys_enter = sys_enter; in trace__add_syscall_newtp()
3667 trace->syscalls.events.sys_exit = sys_exit; in trace__add_syscall_newtp()
3680 static int trace__set_ev_qualifier_tp_filter(struct trace *trace) in trace__set_ev_qualifier_tp_filter() argument
3684 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, in trace__set_ev_qualifier_tp_filter()
3685 trace->ev_qualifier_ids.nr, in trace__set_ev_qualifier_tp_filter()
3686 trace->ev_qualifier_ids.entries); in trace__set_ev_qualifier_tp_filter()
3691 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) { in trace__set_ev_qualifier_tp_filter()
3692 sys_exit = trace->syscalls.events.sys_exit; in trace__set_ev_qualifier_tp_filter()
3725 static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace __maybe_unused, in trace__find_syscall_bpf_prog()
3759 static void trace__init_syscall_bpf_progs(struct trace *trace, int e_machine, int id) in trace__init_syscall_bpf_progs() argument
3761 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, id); in trace__init_syscall_bpf_progs()
3766 …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()
3767 …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()
3770 static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int e_machine, int id) in trace__bpf_prog_sys_enter_fd() argument
3772 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, id); in trace__bpf_prog_sys_enter_fd()
3776 static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int e_machine, int id) in trace__bpf_prog_sys_exit_fd() argument
3778 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, id); in trace__bpf_prog_sys_exit_fd()
3782 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
3785 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, key); in trace__bpf_sys_enter_beauty_map()
3794 trace__load_vmlinux_btf(trace); in trace__bpf_sys_enter_beauty_map()
3795 if (trace->btf == NULL) in trace__bpf_sys_enter_beauty_map()
3820 if (syscall_arg_fmt__cache_btf_struct(&sc->arg_fmt[i], trace->btf, name)) in trace__bpf_sys_enter_beauty_map()
3867 static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, in trace__find_usable_bpf_prog_entry() argument
3884 struct syscall *pair = trace__syscall_info(trace, NULL, sc->e_machine, id); in trace__find_usable_bpf_prog_entry()
3954 …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 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 if (!trace__syscall_enabled(trace, key)) in trace__init_syscalls_bpf_prog_array_maps()
3988 trace__init_syscall_bpf_progs(trace, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
3991 prog_fd = trace__bpf_prog_sys_enter_fd(trace, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
3995 prog_fd = trace__bpf_prog_sys_exit_fd(trace, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
4002 err = trace__bpf_sys_enter_beauty_map(trace, e_machine, key, (unsigned int *)beauty_array); in trace__init_syscalls_bpf_prog_array_maps()
4040 struct syscall *sc = trace__syscall_info(trace, NULL, e_machine, key); in trace__init_syscalls_bpf_prog_array_maps()
4058 pair_prog = trace__find_usable_bpf_prog_entry(trace, sc); in trace__init_syscalls_bpf_prog_array_maps()
4077 static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace __maybe_unused, in trace__init_syscalls_bpf_prog_array_maps()
4084 static int trace__set_ev_qualifier_filter(struct trace *trace) in trace__set_ev_qualifier_filter() argument
4086 if (trace->syscalls.events.sys_enter) in trace__set_ev_qualifier_filter()
4087 return trace__set_ev_qualifier_tp_filter(trace); in trace__set_ev_qualifier_filter()
4091 static int trace__set_filter_loop_pids(struct trace *trace) in trace__set_filter_loop_pids() argument
4097 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]); in trace__set_filter_loop_pids()
4100 struct thread *parent = machine__find_thread(trace->host, in trace__set_filter_loop_pids()
4118 err = evlist__append_tp_filter_pids(trace->evlist, nr, pids); in trace__set_filter_loop_pids()
4125 static int trace__set_filter_pids(struct trace *trace) in trace__set_filter_pids() argument
4134 if (trace->filter_pids.nr > 0) { in trace__set_filter_pids()
4135 err = evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr, in trace__set_filter_pids()
4136 trace->filter_pids.entries); in trace__set_filter_pids()
4138 err = augmented_syscalls__set_filter_pids(trace->filter_pids.nr, in trace__set_filter_pids()
4139 trace->filter_pids.entries); in trace__set_filter_pids()
4141 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) { in trace__set_filter_pids()
4142 err = trace__set_filter_loop_pids(trace); in trace__set_filter_pids()
4148 static int __trace__deliver_event(struct trace *trace, union perf_event *event) in __trace__deliver_event() argument
4150 struct evlist *evlist = trace->evlist; in __trace__deliver_event()
4157 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); in __trace__deliver_event()
4159 trace__handle_event(trace, event, &sample); in __trace__deliver_event()
4165 static int __trace__flush_events(struct trace *trace) in __trace__flush_events() argument
4167 u64 first = ordered_events__first_time(&trace->oe.data); in __trace__flush_events()
4168 u64 flush = trace->oe.last - NSEC_PER_SEC; in __trace__flush_events()
4172 return ordered_events__flush_time(&trace->oe.data, flush); in __trace__flush_events()
4177 static int trace__flush_events(struct trace *trace) in trace__flush_events() argument
4179 return !trace->sort_events ? 0 : __trace__flush_events(trace); in trace__flush_events()
4182 static int trace__deliver_event(struct trace *trace, union perf_event *event) in trace__deliver_event() argument
4186 if (!trace->sort_events) in trace__deliver_event()
4187 return __trace__deliver_event(trace, event); in trace__deliver_event()
4189 err = evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last); in trace__deliver_event()
4193 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0, NULL); in trace__deliver_event()
4197 return trace__flush_events(trace); in trace__deliver_event()
4203 struct trace *trace = container_of(oe, struct trace, oe.data); in ordered_events__deliver_event() local
4205 return __trace__deliver_event(trace, event->event); in ordered_events__deliver_event()
4232 static int trace__expand_filter(struct trace *trace, struct evsel *evsel) in trace__expand_filter() argument
4285 .trace = trace, in trace__expand_filter()
4333 static int trace__expand_filters(struct trace *trace, struct evsel **err_evsel) in trace__expand_filters() argument
4335 struct evlist *evlist = trace->evlist; in trace__expand_filters()
4342 if (trace__expand_filter(trace, evsel)) { in trace__expand_filters()
4351 static int trace__run(struct trace *trace, int argc, const char **argv) in trace__run() argument
4353 struct evlist *evlist = trace->evlist; in trace__run()
4360 trace->live = true; in trace__run()
4362 if (trace->summary_bpf) { in trace__run()
4363 if (trace_prepare_bpf_summary(trace->summary_mode) < 0) in trace__run()
4366 if (trace->summary_only) in trace__run()
4370 if (!trace->raw_augmented_syscalls) { in trace__run()
4371 if (trace->trace_syscalls && trace__add_syscall_newtp(trace)) in trace__run()
4374 if (trace->trace_syscalls) in trace__run()
4375 trace->vfs_getname = evlist__add_vfs_getname(evlist); in trace__run()
4378 if ((trace->trace_pgfaults & TRACE_PFMAJ)) { in trace__run()
4382 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param); in trace__run()
4386 if ((trace->trace_pgfaults & TRACE_PFMIN)) { in trace__run()
4390 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param); in trace__run()
4395 trace->opts.ignore_missing_thread = trace->opts.target.pid; in trace__run()
4397 if (trace->sched && in trace__run()
4425 if (trace->cgroup) in trace__run()
4426 evlist__set_default_cgroup(trace->evlist, trace->cgroup); in trace__run()
4429 err = evlist__create_maps(evlist, &trace->opts.target); in trace__run()
4431 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); in trace__run()
4435 err = trace__symbols_init(trace, argc, argv, evlist); in trace__run()
4437 fprintf(trace->output, "Problems initializing symbol libraries!\n"); in trace__run()
4441 if (trace->summary_mode == SUMMARY__BY_TOTAL && !trace->summary_bpf) { in trace__run()
4442 trace->syscall_stats = alloc_syscall_stats(); in trace__run()
4443 if (trace->syscall_stats == NULL) in trace__run()
4447 evlist__config(evlist, &trace->opts, &callchain_param); in trace__run()
4450 err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL); in trace__run()
4452 fprintf(trace->output, "Couldn't run the workload!\n"); in trace__run()
4464 err = trace__set_filter_pids(trace); in trace__run()
4472 trace__init_syscalls_bpf_prog_array_maps(trace, EM_HOST); in trace__run()
4474 if (trace->ev_qualifier_ids.nr > 0) { in trace__run()
4475 err = trace__set_ev_qualifier_filter(trace); in trace__run()
4479 if (trace->syscalls.events.sys_exit) { in trace__run()
4481 trace->syscalls.events.sys_exit->filter); in trace__run()
4497 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(EM_HOST, "close")); in trace__run()
4499 err = trace__expand_filters(trace, &evsel); in trace__run()
4502 err = evlist__apply_filters(evlist, &evsel, &trace->opts.target); in trace__run()
4506 if (!trace->summary_only || !trace->summary_bpf) { in trace__run()
4507 err = evlist__mmap(evlist, trace->opts.mmap_pages); in trace__run()
4512 if (!target__none(&trace->opts.target) && !trace->opts.target.initial_delay) in trace__run()
4518 if (trace->opts.target.initial_delay) { in trace__run()
4519 usleep(trace->opts.target.initial_delay * 1000); in trace__run()
4523 if (trace->summary_bpf) in trace__run()
4526 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 || in trace__run()
4539 evsel->core.attr.sample_max_stack = trace->max_stack; in trace__run()
4542 before = trace->nr_events; in trace__run()
4553 ++trace->nr_events; in trace__run()
4555 err = trace__deliver_event(trace, event); in trace__run()
4572 if (trace->nr_events == before) { in trace__run()
4581 if (trace__flush_events(trace)) in trace__run()
4589 thread__zput(trace->current); in trace__run()
4593 if (trace->summary_bpf) in trace__run()
4596 if (trace->sort_events) in trace__run()
4597 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL); in trace__run()
4600 if (trace->summary) { in trace__run()
4601 if (trace->summary_bpf) in trace__run()
4602 trace_print_bpf_summary(trace->output); in trace__run()
4603 else if (trace->summary_mode == SUMMARY__BY_TOTAL) in trace__run()
4604 trace__fprintf_total_summary(trace, trace->output); in trace__run()
4606 trace__fprintf_thread_summary(trace, trace->output); in trace__run()
4609 if (trace->show_tool_stats) { in trace__run()
4610 fprintf(trace->output, "Stats:\n " in trace__run()
4613 trace->stats.vfs_getname, in trace__run()
4614 trace->stats.proc_getname); in trace__run()
4620 delete_syscall_stats(trace->syscall_stats); in trace__run()
4621 trace__symbols__exit(trace); in trace__run()
4624 cgroup__put(trace->cgroup); in trace__run()
4625 trace->evlist = NULL; in trace__run()
4626 trace->live = false; in trace__run()
4647 fprintf(trace->output, "%s\n", errbuf); in trace__run()
4651 fprintf(trace->output, in trace__run()
4658 fprintf(trace->output, "Not enough memory to run!\n"); in trace__run()
4662 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno)); in trace__run()
4666 static int trace__replay(struct trace *trace) in trace__replay() argument
4674 .force = trace->force, in trace__replay()
4680 perf_tool__init(&trace->tool, /*ordered_events=*/true); in trace__replay()
4681 trace->tool.sample = trace__process_sample; in trace__replay()
4682 trace->tool.mmap = perf_event__process_mmap; in trace__replay()
4683 trace->tool.mmap2 = perf_event__process_mmap2; in trace__replay()
4684 trace->tool.comm = perf_event__process_comm; in trace__replay()
4685 trace->tool.exit = perf_event__process_exit; in trace__replay()
4686 trace->tool.fork = perf_event__process_fork; in trace__replay()
4687 trace->tool.attr = perf_event__process_attr; in trace__replay()
4688 trace->tool.tracing_data = perf_event__process_tracing_data; in trace__replay()
4689 trace->tool.build_id = perf_event__process_build_id; in trace__replay()
4690 trace->tool.namespaces = perf_event__process_namespaces; in trace__replay()
4692 trace->tool.ordered_events = true; in trace__replay()
4693 trace->tool.ordering_requires_timestamps = true; in trace__replay()
4696 trace->multiple_threads = true; in trace__replay()
4698 session = perf_session__new(&data, &trace->tool); in trace__replay()
4702 if (trace->opts.target.pid) in trace__replay()
4703 symbol_conf.pid_list_str = strdup(trace->opts.target.pid); in trace__replay()
4705 if (trace->opts.target.tid) in trace__replay()
4706 symbol_conf.tid_list_str = strdup(trace->opts.target.tid); in trace__replay()
4711 trace->host = &session->machines.host; in trace__replay()
4718 trace->syscalls.events.sys_enter = evsel; in trace__replay()
4731 trace->syscalls.events.sys_exit = evsel; in trace__replay()
4749 if (trace->summary_mode == SUMMARY__BY_TOTAL) { in trace__replay()
4750 trace->syscall_stats = alloc_syscall_stats(); in trace__replay()
4751 if (trace->syscall_stats == NULL) in trace__replay()
4761 else if (trace->summary) in trace__replay()
4762 trace__fprintf_thread_summary(trace, trace->output); in trace__replay()
4765 delete_syscall_stats(trace->syscall_stats); in trace__replay()
4821 static size_t syscall__dump_stats(struct trace *trace, int e_machine, FILE *fp, in syscall__dump_stats() argument
4852 sc = trace__syscall_info(trace, /*evsel=*/NULL, e_machine, entry->syscall); in syscall__dump_stats()
4861 if (trace->errno_summary && stats->nr_failures) { in syscall__dump_stats()
4866 …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()
4879 struct trace *trace, int e_machine, FILE *fp) in thread__dump_stats() argument
4881 return syscall__dump_stats(trace, e_machine, fp, ttrace->syscall_stats); in thread__dump_stats()
4884 static size_t system__dump_stats(struct trace *trace, int e_machine, FILE *fp) in system__dump_stats() argument
4886 return syscall__dump_stats(trace, e_machine, fp, trace->syscall_stats); in system__dump_stats()
4889 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) in trace__fprintf_thread() argument
4893 int e_machine = thread__e_machine(thread, trace->host); in trace__fprintf_thread()
4899 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; in trace__fprintf_thread()
4908 if (trace->sched) in trace__fprintf_thread()
4913 printed += thread__dump_stats(ttrace, trace, e_machine, fp); in trace__fprintf_thread()
4941 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) in trace__fprintf_thread_summary() argument
4946 if (machine__thread_list(trace->host, &threads) == 0) { in trace__fprintf_thread_summary()
4952 printed += trace__fprintf_thread(fp, pos->thread, trace); in trace__fprintf_thread_summary()
4958 static size_t trace__fprintf_total_summary(struct trace *trace, FILE *fp) in trace__fprintf_total_summary() argument
4963 printed += fprintf(fp, "%lu events", trace->nr_events); in trace__fprintf_total_summary()
4965 if (trace->pfmaj) in trace__fprintf_total_summary()
4966 printed += fprintf(fp, ", %lu majfaults", trace->pfmaj); in trace__fprintf_total_summary()
4967 if (trace->pfmin) in trace__fprintf_total_summary()
4968 printed += fprintf(fp, ", %lu minfaults", trace->pfmin); in trace__fprintf_total_summary()
4969 if (trace->sched) in trace__fprintf_total_summary()
4970 printed += fprintf(fp, ", %.3f msec\n", trace->runtime_ms); in trace__fprintf_total_summary()
4975 printed += system__dump_stats(trace, EM_HOST, fp); in trace__fprintf_total_summary()
4983 struct trace *trace = opt->value; in trace__set_duration() local
4985 trace->duration_filter = atof(str); in trace__set_duration()
4994 struct trace *trace = opt->value; in trace__set_filter_pids_from_option() local
5004 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; in trace__set_filter_pids_from_option()
5005 trace->filter_pids.entries = calloc(i, sizeof(pid_t)); in trace__set_filter_pids_from_option()
5007 if (trace->filter_pids.entries == NULL) in trace__set_filter_pids_from_option()
5010 trace->filter_pids.entries[0] = getpid(); in trace__set_filter_pids_from_option()
5012 for (i = 1; i < trace->filter_pids.nr; ++i) in trace__set_filter_pids_from_option()
5013 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; in trace__set_filter_pids_from_option()
5021 static int trace__open_output(struct trace *trace, const char *filename) in trace__open_output() argument
5033 trace->output = fopen(filename, "w"); in trace__open_output()
5035 return trace->output == NULL ? -errno : 0; in trace__open_output()
5146 struct trace *trace = (struct trace *)opt->value; in trace__parse_events_option() local
5159 trace->not_ev_qualifier = true; in trace__parse_events_option()
5205 trace->ev_qualifier = strlist__new(lists[1], &slist_config); in trace__parse_events_option()
5206 if (trace->ev_qualifier == NULL) { in trace__parse_events_option()
5207 fputs("Not enough memory to parse event qualifier", trace->output); in trace__parse_events_option()
5211 if (trace__validate_ev_qualifier(trace)) in trace__parse_events_option()
5213 trace->trace_syscalls = true; in trace__parse_events_option()
5220 .evlistp = &trace->evlist, in trace__parse_events_option()
5239 struct trace *trace = opt->value; in trace__parse_cgroups() local
5241 if (!list_empty(&trace->evlist->core.entries)) { in trace__parse_cgroups()
5243 .value = &trace->evlist, in trace__parse_cgroups()
5247 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str); in trace__parse_cgroups()
5255 struct trace *trace = opt->value; in trace__parse_summary_mode() local
5258 trace->summary_mode = SUMMARY__BY_THREAD; in trace__parse_summary_mode()
5260 trace->summary_mode = SUMMARY__BY_TOTAL; in trace__parse_summary_mode()
5262 trace->summary_mode = SUMMARY__BY_CGROUP; in trace__parse_summary_mode()
5273 struct trace *trace = arg; in trace__config() local
5277 trace->perfconfig_events = strdup(value); in trace__config()
5278 if (trace->perfconfig_events == NULL) { in trace__config()
5283 trace->show_tstamp = perf_config_bool(var, value); in trace__config()
5285 trace->show_duration = perf_config_bool(var, value); in trace__config()
5287 trace->show_arg_names = perf_config_bool(var, value); in trace__config()
5288 if (!trace->show_arg_names) in trace__config()
5289 trace->show_zeros = true; in trace__config()
5292 if (!trace->show_arg_names && !new_show_zeros) { in trace__config()
5296 trace->show_zeros = new_show_zeros; in trace__config()
5298 trace->show_string_prefix = perf_config_bool(var, value); in trace__config()
5300 trace->opts.no_inherit = perf_config_bool(var, value); in trace__config()
5304 trace->args_alignment = args_alignment; in trace__config()
5307 trace->libtraceevent_print = true; in trace__config()
5309 trace->libtraceevent_print = false; in trace__config()
5315 static void trace__exit(struct trace *trace) in trace__exit() argument
5317 thread__zput(trace->current); in trace__exit()
5318 strlist__delete(trace->ev_qualifier); in trace__exit()
5319 zfree(&trace->ev_qualifier_ids.entries); in trace__exit()
5320 if (trace->syscalls.table) { in trace__exit()
5321 for (size_t i = 0; i < trace->syscalls.table_size; i++) in trace__exit()
5322 syscall__delete(trace->syscalls.table[i]); in trace__exit()
5323 zfree(&trace->syscalls.table); in trace__exit()
5325 zfree(&trace->perfconfig_events); in trace__exit()
5326 evlist__delete(trace->evlist); in trace__exit()
5327 trace->evlist = NULL; in trace__exit()
5328 ordered_events__free(&trace->oe.data); in trace__exit()
5330 btf__free(trace->btf); in trace__exit()
5331 trace->btf = NULL; in trace__exit()
5344 struct trace trace = { in cmd_trace() local
5367 OPT_CALLBACK('e', "event", &trace, "event", in cmd_trace()
5370 OPT_CALLBACK(0, "filter", &trace.evlist, "filter", in cmd_trace()
5372 OPT_BOOLEAN(0, "comm", &trace.show_comm, in cmd_trace()
5374 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), in cmd_trace()
5375 OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace", in cmd_trace()
5379 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", in cmd_trace()
5381 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", in cmd_trace()
5383 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids", in cmd_trace()
5385 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, in cmd_trace()
5387 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", in cmd_trace()
5389 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, in cmd_trace()
5391 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", in cmd_trace()
5393 OPT_STRING('u', "uid", &trace.uid_str, "user", "user to profile"), in cmd_trace()
5394 OPT_CALLBACK(0, "duration", &trace, "float", in cmd_trace()
5397 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), in cmd_trace()
5399 OPT_BOOLEAN('T', "time", &trace.full_time, in cmd_trace()
5401 OPT_BOOLEAN(0, "failure", &trace.failure_only, in cmd_trace()
5403 OPT_BOOLEAN('s', "summary", &trace.summary_only, in cmd_trace()
5405 OPT_BOOLEAN('S', "with-summary", &trace.summary, in cmd_trace()
5407 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary, in cmd_trace()
5409 OPT_CALLBACK(0, "summary-mode", &trace, "mode", in cmd_trace()
5412 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", in cmd_trace()
5414 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), in cmd_trace()
5415 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), in cmd_trace()
5416 OPT_CALLBACK(0, "call-graph", &trace.opts, in cmd_trace()
5419 OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print, in cmd_trace()
5421 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, in cmd_trace()
5423 OPT_ULONG(0, "max-events", &trace.max_events, in cmd_trace()
5425 OPT_UINTEGER(0, "min-stack", &trace.min_stack, in cmd_trace()
5428 OPT_UINTEGER(0, "max-stack", &trace.max_stack, in cmd_trace()
5432 OPT_BOOLEAN(0, "sort-events", &trace.sort_events, in cmd_trace()
5434 OPT_BOOLEAN(0, "print-sample", &trace.print_sample, in cmd_trace()
5438 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only", in cmd_trace()
5440 OPT_INTEGER('D', "delay", &trace.opts.target.initial_delay, in cmd_trace()
5443 OPT_BOOLEAN(0, "force-btf", &trace.force_btf, "Prefer btf_dump general pretty printer" in cmd_trace()
5445 OPT_BOOLEAN(0, "bpf-summary", &trace.summary_bpf, "Summary syscall stats in BPF"), in cmd_trace()
5446 OPTS_EVSWITCH(&trace.evswitch), in cmd_trace()
5466 ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace); in cmd_trace()
5467 ordered_events__set_copy_on_queue(&trace.oe.data, true); in cmd_trace()
5469 trace.evlist = evlist__new(); in cmd_trace()
5471 if (trace.evlist == NULL) { in cmd_trace()
5486 err = perf_config(trace__config, &trace); in cmd_trace()
5504 if (!trace.trace_syscalls && !trace.trace_pgfaults && in cmd_trace()
5505 trace.evlist->core.nr_entries == 0 /* Was --events used? */) { in cmd_trace()
5506 trace.trace_syscalls = true; in cmd_trace()
5514 if (trace.perfconfig_events != NULL) { in cmd_trace()
5518 err = parse_events(trace.evlist, trace.perfconfig_events, &parse_err); in cmd_trace()
5520 parse_events_error__print(&parse_err, trace.perfconfig_events); in cmd_trace()
5526 if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) { in cmd_trace()
5531 if (!trace.trace_syscalls) in cmd_trace()
5539 if (trace.summary_bpf) { in cmd_trace()
5540 if (!trace.opts.target.system_wide) { in cmd_trace()
5545 if (trace.summary_only) in cmd_trace()
5553 trace__add_syscall_newtp(&trace); in cmd_trace()
5555 err = augmented_syscalls__create_bpf_output(trace.evlist); in cmd_trace()
5557 trace.syscalls.events.bpf_output = evlist__last(trace.evlist); in cmd_trace()
5562 if (trace.trace_pgfaults) { in cmd_trace()
5563 trace.opts.sample_address = true; in cmd_trace()
5564 trace.opts.sample_time = true; in cmd_trace()
5567 if (trace.opts.mmap_pages == UINT_MAX) in cmd_trace()
5570 if (trace.max_stack == UINT_MAX) { in cmd_trace()
5571 trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack(); in cmd_trace()
5576 if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) { in cmd_trace()
5577 record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false); in cmd_trace()
5583 trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4; in cmd_trace()
5588 if (trace.evlist->core.nr_entries > 0) { in cmd_trace()
5591 evlist__set_default_evsel_handler(trace.evlist, trace__event_handler); in cmd_trace()
5592 if (evlist__set_syscall_tp_fields(trace.evlist, &use_btf)) { in cmd_trace()
5598 trace__load_vmlinux_btf(&trace); in cmd_trace()
5612 if (trace.syscalls.events.bpf_output) { in cmd_trace()
5613 evlist__for_each_entry(trace.evlist, evsel) { in cmd_trace()
5617 trace.raw_augmented_syscalls = true; in cmd_trace()
5621 if (trace.syscalls.events.bpf_output->priv == NULL && in cmd_trace()
5623 struct evsel *augmented = trace.syscalls.events.bpf_output; in cmd_trace()
5670 if (trace.raw_augmented_syscalls) in cmd_trace()
5671 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset; in cmd_trace()
5679 err = trace__record(&trace, argc-1, &argv[1]); in cmd_trace()
5684 if (trace.errno_summary && !trace.summary && !trace.summary_only) in cmd_trace()
5685 trace.summary_only = true; in cmd_trace()
5688 if (trace.summary_only) in cmd_trace()
5689 trace.summary = trace.summary_only; in cmd_trace()
5692 if (trace.summary) { in cmd_trace()
5694 if (trace.summary_mode == SUMMARY__NONE) in cmd_trace()
5695 trace.summary_mode = SUMMARY__BY_THREAD; in cmd_trace()
5697 if (!trace.summary_bpf && trace.summary_mode == SUMMARY__BY_CGROUP) { in cmd_trace()
5705 err = trace__open_output(&trace, output_name); in cmd_trace()
5712 err = evswitch__init(&trace.evswitch, trace.evlist, stderr); in cmd_trace()
5716 err = target__validate(&trace.opts.target); in cmd_trace()
5718 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
5719 fprintf(trace.output, "%s", bf); in cmd_trace()
5723 if (trace.uid_str) { in cmd_trace()
5724 uid_t uid = parse_uid(trace.uid_str); in cmd_trace()
5727 ui__error("Invalid User: %s", trace.uid_str); in cmd_trace()
5731 err = parse_uid_filter(trace.evlist, uid); in cmd_trace()
5735 trace.opts.target.system_wide = true; in cmd_trace()
5738 if (!argc && target__none(&trace.opts.target)) in cmd_trace()
5739 trace.opts.target.system_wide = true; in cmd_trace()
5742 err = trace__replay(&trace); in cmd_trace()
5744 err = trace__run(&trace, argc, argv); in cmd_trace()
5748 fclose(trace.output); in cmd_trace()
5750 trace__exit(&trace); in cmd_trace()