Lines Matching full:trace

2  * builtin-trace.c
4 * Builtin 'trace' command:
6 * Display a continuously updated trace of any workload, CPU, specific PID,
12 * Initially based on the 'trace' prototype by Thomas Gleixner:
14 * http://lwn.net/Articles/415728/ ("Announcing a new utility: 'trace'")
57 #include "trace/beauty/beauty.h"
58 #include "trace-event.h"
128 struct trace { struct
293 * The evsel->priv as used by 'perf trace'
729 #include "trace/beauty/generated/fsconfig_arrays.c"
899 #include "trace/beauty/arch_errno_names.c"
900 #include "trace/beauty/eventfd.c"
901 #include "trace/beauty/futex_op.c"
902 #include "trace/beauty/futex_val3.c"
903 #include "trace/beauty/mmap.c"
904 #include "trace/beauty/mode_t.c"
905 #include "trace/beauty/msg_flags.c"
906 #include "trace/beauty/open_flags.c"
907 #include "trace/beauty/perf_event_open.c"
908 #include "trace/beauty/pid.c"
909 #include "trace/beauty/sched_policy.c"
910 #include "trace/beauty/seccomp.c"
911 #include "trace/beauty/signum.c"
912 #include "trace/beauty/socket_type.c"
913 #include "trace/beauty/waitid_options.c"
1436 struct trace *trace) in thread__fd_path() argument
1440 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1447 if (!trace->live) in thread__fd_path()
1449 ++trace->stats.proc_getname; in thread__fd_path()
1461 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1469 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) in pid__scnprintf_fd() argument
1472 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1475 const char *path = thread__fd_path(thread, fd, trace); in pid__scnprintf_fd()
1532 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1539 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1541 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1544 static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in __trace__fprintf_tstamp() argument
1546 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1557 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1560 return __trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_tstamp()
1581 static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp) in trace__fprintf_comm_tid() argument
1585 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1586 if (trace->show_comm) in trace__fprintf_comm_tid()
1594 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1599 if (trace->show_tstamp) in trace__fprintf_entry_head()
1600 printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1601 if (trace->show_duration) in trace__fprintf_entry_head()
1603 return printed + trace__fprintf_comm_tid(trace, thread, fp); in trace__fprintf_entry_head()
1606 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1613 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1630 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1631 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1652 static int trace__symbols_init(struct trace *trace, struct evlist *evlist) in trace__symbols_init() argument
1659 trace->host = machine__new_host(); in trace__symbols_init()
1660 if (trace->host == NULL) in trace__symbols_init()
1665 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
1669 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1679 static void trace__symbols__exit(struct trace *trace) in trace__symbols__exit() argument
1681 machine__exit(trace->host); in trace__symbols__exit()
1682 trace->host = NULL; in trace__symbols__exit()
1794 static int trace__read_syscall_info(struct trace *trace, int id) in trace__read_syscall_info() argument
1798 const char *name = syscalltbl__name(trace->sctbl, id); in trace__read_syscall_info()
1801 if (trace->syscalls.table == NULL) { in trace__read_syscall_info()
1802 trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); in trace__read_syscall_info()
1803 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1807 if (id > trace->sctbl->syscalls.max_id || (id == 0 && trace->syscalls.table == NULL)) { in trace__read_syscall_info()
1809 struct syscall *table = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); in trace__read_syscall_info()
1815 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1818 …memset(table + trace->sctbl->syscalls.max_id + 1, 0, (id - trace->sctbl->syscalls.max_id) * sizeof… in trace__read_syscall_info()
1820 trace->syscalls.table = table; in trace__read_syscall_info()
1821 trace->sctbl->syscalls.max_id = id; in trace__read_syscall_info()
1824 sc = trace->syscalls.table + id; in trace__read_syscall_info()
1845 * Fails to read trace point format via sysfs node, so the trace point in trace__read_syscall_info()
1897 static int trace__validate_ev_qualifier(struct trace *trace) in trace__validate_ev_qualifier() argument
1902 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
1904 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
1905 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1907 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
1909 trace->output); in trace__validate_ev_qualifier()
1914 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
1916 int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; in trace__validate_ev_qualifier()
1919 id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1934 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1939 id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1946 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
1947 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1950 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
1953 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
1955 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1959 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
1960 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
1966 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
1967 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
1971 static __maybe_unused bool trace__syscall_enabled(struct trace *trace, int id) in trace__syscall_enabled() argument
1975 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
1978 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
1979 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
1982 return !trace->not_ev_qualifier; in trace__syscall_enabled()
1984 return trace->not_ev_qualifier; in trace__syscall_enabled()
2016 * in tools/perf/trace/beauty/mount_flags.c
2040 struct trace *trace, struct thread *thread) in syscall__scnprintf_args() argument
2053 .trace = trace, in syscall__scnprintf_args()
2055 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2088 !trace->show_zeros && in syscall__scnprintf_args()
2098 if (trace->show_arg_names) in syscall__scnprintf_args()
2127 typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel,
2131 static struct syscall *trace__syscall_info(struct trace *trace, argument
2150 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",
2159 if (id > trace->sctbl->syscalls.max_id) {
2161 if (id >= trace->sctbl->syscalls.max_id) {
2167 err = trace__read_syscall_info(trace, id);
2173 if ((trace->syscalls.table == NULL || trace->syscalls.table[id].name == NULL) &&
2174 (err = trace__read_syscall_info(trace, id)) != 0)
2177 if (trace->syscalls.table && trace->syscalls.table[id].nonexistent)
2180 return &trace->syscalls.table[id];
2185 …fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, str_error_r(-err, sbuf, s…
2186 if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name != NULL)
2187 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);
2188 fputs(" information\n", trace->output);
2253 static int trace__printf_interrupted_entry(struct trace *trace) argument
2259 if (trace->failure_only || trace->current == NULL)
2262 ttrace = thread__priv(trace->current);
2267 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o…
2268 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str);
2270 if (len < trace->args_alignment - 4)
2271 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " ");
2273 printed += fprintf(trace->output, " ...\n");
2276 ++trace->nr_events_printed;
2281 static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, argument
2286 if (trace->print_sample) {
2289 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n",
2332 static int trace__sys_enter(struct trace *trace, struct evsel *evsel, argument
2343 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2349 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2350 ttrace = thread__trace(thread, trace->output);
2354 trace__fprintf_sample(trace, evsel, sample, thread);
2364 if (!(trace->duration_filter || trace->summary_only || trace->min_stack))
2365 trace__printf_interrupted_entry(trace);
2376 if (evsel != trace->syscalls.events.sys_enter)
2377 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2383 args, augmented_args, augmented_args_size, trace, thread);
2386 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) {
2389 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output);
2390 printed = fprintf(trace->output, "%s)", ttrace->entry_str);
2391 if (trace->args_alignment > printed)
2392 alignment = trace->args_alignment - printed;
2393 fprintf(trace->output, "%*s= ?\n", alignment, " ");
2401 if (trace->current != thread) {
2402 thread__put(trace->current);
2403 trace->current = thread__get(thread);
2411 static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, argument
2417 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2426 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2427 ttrace = thread__trace(thread, trace->output);
2436 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2437 …ll__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread);
2438 fprintf(trace->output, "%.*s", (int)printed, msg);
2445 static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, argument
2452 trace->max_stack;
2456 if (machine__resolve(trace->host, &al, sample) < 0)
2465 static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) argument
2472 …chain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output);
2483 static int trace__sys_exit(struct trace *trace, struct evsel *evsel, argument
2492 int alignment = trace->args_alignment;
2493 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2499 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2500 ttrace = thread__trace(thread, trace->output);
2504 trace__fprintf_sample(trace, evsel, sample, thread);
2508 if (trace->summary)
2509 thread__update_stats(thread, ttrace, id, sample, ret, trace->errno_summary);
2511 if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) {
2514 ++trace->stats.vfs_getname;
2519 if (trace__filter_duration(trace, duration))
2522 } else if (trace->duration_filter)
2528 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor);
2530 if (cursor->nr < trace->min_stack)
2536 if (trace->summary_only || (ret >= 0 && trace->failure_only))
2539 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-…
2542 printed = fprintf(trace->output, "%s", ttrace->entry_str);
2544 printed += fprintf(trace->output, " ... [");
2545 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued");
2547 printed += fprintf(trace->output, "]: %s()", sc->name);
2557 fprintf(trace->output, ")%*s= ", alignment, " ");
2563 fprintf(trace->output, "%ld", ret);
2570 fprintf(trace->output, "-1 %s (%s)", e, emsg);
2573 fprintf(trace->output, "0 (Timeout)");
2579 .trace = trace,
2583 fprintf(trace->output, "%s", bf);
2585 fprintf(trace->output, "%#lx", ret);
2587 struct thread *child = machine__find_thread(trace->host, ret, ret);
2590 fprintf(trace->output, "%ld", ret);
2592 fprintf(trace->output, " (%s)", thread__comm_str(child));
2598 fputc('\n', trace->output);
2604 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX)
2608 trace__fprintf_callchain(trace, sample);
2619 static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, argument
2623 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2680 static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, argument
2686 struct thread *thread = machine__findnew_thread(trace->host,
2689 struct thread_trace *ttrace = thread__trace(thread, trace->output);
2695 trace->runtime_ms += runtime_ms;
2701 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n",
2734 static void bpf_output__fprintf(struct trace *trace, argument
2738 bpf_output__printer, NULL, trace->output);
2739 ++trace->nr_events_printed;
2742 static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample… argument
2759 .trace = trace,
2761 .show_string_prefix = trace->show_string_prefix,
2796 !trace->show_zeros &&
2805 if (trace->show_arg_names)
2811 return printed + fprintf(trace->output, "%.*s", (int)printed, bf);
2814 static int trace__event_handler(struct trace *trace, struct evsel *evsel, argument
2824 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2829 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor);
2831 if (cursor->nr < trace->min_stack)
2837 trace__printf_interrupted_entry(trace);
2838 trace__fprintf_tstamp(trace, sample->time, trace->output);
2840 if (trace->trace_syscalls && trace->show_duration)
2841 fprintf(trace->output, "( ): ");
2844 trace__fprintf_comm_tid(trace, thread, trace->output);
2846 if (evsel == trace->syscalls.events.bpf_output) {
2848 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2851 fprintf(trace->output, "%s(", sc->name);
2852 trace__fprintf_sys_enter(trace, evsel, sample);
2853 fputc(')', trace->output);
2864 fprintf(trace->output, "%s(", evsel->name);
2867 bpf_output__fprintf(trace, sample);
2870 trace__fprintf_sys_enter(trace, evsel, sample)) {
2871 if (trace->libtraceevent_print) {
2874 trace->output);
2876 trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0);
2882 fprintf(trace->output, ")\n");
2885 trace__fprintf_callchain(trace, sample);
2889 ++trace->nr_events_printed;
2917 static int trace__pgfault(struct trace *trace, argument
2930 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2935 callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor);
2937 if (cursor->nr < trace->min_stack)
2943 ttrace = thread__trace(thread, trace->output);
2952 if (trace->summary_only)
2957 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
2959 fprintf(trace->output, "%sfault [",
2963 print_location(trace->output, sample, &al, false, true);
2965 fprintf(trace->output, "] => ");
2978 print_location(trace->output, sample, &al, true, false);
2980 fprintf(trace->output, " (%c%c)\n", map_type, al.level);
2983 trace__fprintf_callchain(trace, sample);
2987 ++trace->nr_events_printed;
2996 static void trace__set_base_time(struct trace *trace, argument
3008 if (trace->base_time == 0 && !trace->full_time &&
3010 trace->base_time = sample->time;
3019 struct trace *trace = container_of(tool, struct trace, tool); local
3025 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
3029 trace__set_base_time(trace, evsel, sample);
3032 ++trace->nr_events;
3033 handler(trace, evsel, event, sample);
3040 static int trace__record(struct trace *trace, int argc, const char **argv) argument
3072 if (trace->trace_syscalls) {
3090 if (trace->trace_pgfaults & TRACE_PFMAJ)
3094 if (trace->trace_pgfaults & TRACE_PFMIN)
3108 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
3171 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… argument
3177 trace__process_event(trace, trace->host, event, sample);
3181 evsel = evlist__id2evsel(trace->evlist, sample->id);
3183 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id);
3187 if (evswitch__discard(&trace->evswitch, evsel))
3190 trace__set_base_time(trace, evsel, sample);
3194 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
3199 handler(trace, evsel, event, sample);
3202 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX)
3206 static int trace__add_syscall_newtp(struct trace *trace) argument
3209 struct evlist *evlist = trace->evlist;
3226 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param);
3227 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param);
3232 if (callchain_param.enabled && !trace->kernel_syscallchains) {
3241 trace->syscalls.events.sys_enter = sys_enter;
3242 trace->syscalls.events.sys_exit = sys_exit;
3255 static int trace__set_ev_qualifier_tp_filter(struct trace *trace) argument
3259 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier,
3260 trace->ev_qualifier_ids.nr,
3261 trace->ev_qualifier_ids.entries);
3266 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) {
3267 sys_exit = trace->syscalls.events.sys_exit;
3280 static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) argument
3285 if (trace->skel->obj == NULL)
3288 bpf_object__for_each_program(pos, trace->skel->obj) {
3299 static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc, argument
3307 prog = trace__find_bpf_program_by_title(trace, default_prog_name);
3312 prog = trace__find_bpf_program_by_title(trace, default_prog_name);
3319 prog = trace__find_bpf_program_by_title(trace, prog_name);
3329 return trace->skel->progs.syscall_unaugmented;
3332 static void trace__init_syscall_bpf_progs(struct trace *trace, int id) argument
3334 struct syscall *sc = trace__syscall_info(trace, NULL, id);
3339 …sc->bpf_prog.sys_enter = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3340 …sc->bpf_prog.sys_exit = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3343 static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id) argument
3345 struct syscall *sc = trace__syscall_info(trace, NULL, id);
3346 …return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->skel->progs.syscall_u…
3349 static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id) argument
3351 struct syscall *sc = trace__syscall_info(trace, NULL, id);
3352 …return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->skel->progs.syscall_un…
3355 static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *s… argument
3371 for (id = 0; id < trace->sctbl->syscalls.nr_entries; ++id) {
3372 struct syscall *pair = trace__syscall_info(trace, NULL, id);
3377 pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)
3442 …pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_ent…
3443 if (pair_prog == trace->skel->progs.syscall_unaugmented)
3456 static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace) argument
3458 int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter);
3459 int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit);
3462 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3465 if (!trace__syscall_enabled(trace, key))
3468 trace__init_syscall_bpf_progs(trace, key);
3471 prog_fd = trace__bpf_prog_sys_enter_fd(trace, key);
3475 prog_fd = trace__bpf_prog_sys_exit_fd(trace, key);
3509 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3510 struct syscall *sc = trace__syscall_info(trace, NULL, key);
3521 if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented)
3528 pair_prog = trace__find_usable_bpf_prog_entry(trace, sc);
3548 static int trace__set_ev_qualifier_filter(struct trace *trace) argument
3550 if (trace->syscalls.events.sys_enter)
3551 return trace__set_ev_qualifier_tp_filter(trace);
3573 static int trace__set_filter_loop_pids(struct trace *trace) argument
3579 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]);
3582 struct thread *parent = machine__find_thread(trace->host,
3597 err = evlist__append_tp_filter_pids(trace->evlist, nr, pids);
3598 if (!err && trace->filter_pids.map)
3599 err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids);
3604 static int trace__set_filter_pids(struct trace *trace) argument
3613 if (trace->filter_pids.nr > 0) {
3614 err = evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr,
3615 trace->filter_pids.entries);
3616 if (!err && trace->filter_pids.map) {
3617 err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
3618 trace->filter_pids.entries);
3620 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
3621 err = trace__set_filter_loop_pids(trace);
3627 static int __trace__deliver_event(struct trace *trace, union perf_event *event) argument
3629 struct evlist *evlist = trace->evlist;
3634 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err);
3636 trace__handle_event(trace, event, &sample);
3641 static int __trace__flush_events(struct trace *trace) argument
3643 u64 first = ordered_events__first_time(&trace->oe.data);
3644 u64 flush = trace->oe.last - NSEC_PER_SEC;
3648 return ordered_events__flush_time(&trace->oe.data, flush);
3653 static int trace__flush_events(struct trace *trace) argument
3655 return !trace->sort_events ? 0 : __trace__flush_events(trace);
3658 static int trace__deliver_event(struct trace *trace, union perf_event *event) argument
3662 if (!trace->sort_events)
3663 return __trace__deliver_event(trace, event);
3665 err = evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last);
3669 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0, NULL);
3673 return trace__flush_events(trace);
3679 struct trace *trace = container_of(oe, struct trace, oe.data); local
3681 return __trace__deliver_event(trace, event->event);
3699 static int trace__expand_filter(struct trace *trace __maybe_unused, struct evsel *evsel)
3797 static int trace__expand_filters(struct trace *trace, struct evsel **err_evsel) argument
3799 struct evlist *evlist = trace->evlist;
3806 if (trace__expand_filter(trace, evsel)) {
3815 static int trace__run(struct trace *trace, int argc, const char **argv) argument
3817 struct evlist *evlist = trace->evlist;
3824 trace->live = true;
3826 if (!trace->raw_augmented_syscalls) {
3827 if (trace->trace_syscalls && trace__add_syscall_newtp(trace))
3830 if (trace->trace_syscalls)
3831 trace->vfs_getname = evlist__add_vfs_getname(evlist);
3834 if ((trace->trace_pgfaults & TRACE_PFMAJ)) {
3838 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param);
3842 if ((trace->trace_pgfaults & TRACE_PFMIN)) {
3846 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param);
3851 trace->opts.ignore_missing_thread = trace->opts.target.uid != UINT_MAX || trace->opts.target.pid;
3853 if (trace->sched &&
3860 * trace -G A -e sched:*switch
3865 * trace -e sched:*switch -G A
3873 * trace -G A -e sched:*switch -G B
3881 if (trace->cgroup)
3882 evlist__set_default_cgroup(trace->evlist, trace->cgroup);
3884 err = evlist__create_maps(evlist, &trace->opts.target);
3886 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n");
3890 err = trace__symbols_init(trace, evlist);
3892 fprintf(trace->output, "Problems initializing symbol libraries!\n");
3896 evlist__config(evlist, &trace->opts, &callchain_param);
3899 err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL);
3901 fprintf(trace->output, "Couldn't run the workload!\n");
3911 if (trace->syscalls.events.bpf_output) {
3918 perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) {
3919 bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__,
3921 xyarray__entry(trace->syscalls.events.bpf_output->core.fd,
3927 if (trace->skel)
3928 trace->filter_pids.map = trace->skel->maps.pids_filtered;
3930 err = trace__set_filter_pids(trace);
3935 if (trace->skel && trace->skel->progs.sys_enter)
3936 trace__init_syscalls_bpf_prog_array_maps(trace);
3939 if (trace->ev_qualifier_ids.nr > 0) {
3940 err = trace__set_ev_qualifier_filter(trace);
3944 if (trace->syscalls.events.sys_exit) {
3946 trace->syscalls.events.sys_exit->filter);
3961 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(trace->sctbl, "close"));
3963 err = trace__expand_filters(trace, &evsel);
3970 err = evlist__mmap(evlist, trace->opts.mmap_pages);
3974 if (!target__none(&trace->opts.target) && !trace->opts.target.initial_delay)
3980 if (trace->opts.target.initial_delay) {
3981 usleep(trace->opts.target.initial_delay * 1000);
3985 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
3998 evsel->core.attr.sample_max_stack = trace->max_stack;
4001 before = trace->nr_events;
4012 ++trace->nr_events;
4014 err = trace__deliver_event(trace, event);
4031 if (trace->nr_events == before) {
4040 if (trace__flush_events(trace))
4048 thread__zput(trace->current);
4052 if (trace->sort_events)
4053 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL);
4056 if (trace->summary)
4057 trace__fprintf_thread_summary(trace, trace->output);
4059 if (trace->show_tool_stats) {
4060 fprintf(trace->output, "Stats:\n "
4063 trace->stats.vfs_getname,
4064 trace->stats.proc_getname);
4069 trace__symbols__exit(trace);
4072 cgroup__put(trace->cgroup);
4073 trace->evlist = NULL;
4074 trace->live = false;
4095 fprintf(trace->output, "%s\n", errbuf);
4099 fprintf(trace->output,
4106 fprintf(trace->output, "Not enough memory to run!\n");
4110 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno));
4114 static int trace__replay(struct trace *trace) argument
4122 .force = trace->force,
4128 trace->tool.sample = trace__process_sample;
4129 trace->tool.mmap = perf_event__process_mmap;
4130 trace->tool.mmap2 = perf_event__process_mmap2;
4131 trace->tool.comm = perf_event__process_comm;
4132 trace->tool.exit = perf_event__process_exit;
4133 trace->tool.fork = perf_event__process_fork;
4134 trace->tool.attr = perf_event__process_attr;
4135 trace->tool.tracing_data = perf_event__process_tracing_data;
4136 trace->tool.build_id = perf_event__process_build_id;
4137 trace->tool.namespaces = perf_event__process_namespaces;
4139 trace->tool.ordered_events = true;
4140 trace->tool.ordering_requires_timestamps = true;
4143 trace->multiple_threads = true;
4145 session = perf_session__new(&data, &trace->tool);
4149 if (trace->opts.target.pid)
4150 symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
4152 if (trace->opts.target.tid)
4153 symbol_conf.tid_list_str = strdup(trace->opts.target.tid);
4158 trace->host = &session->machines.host;
4165 trace->syscalls.events.sys_enter = evsel;
4178 trace->syscalls.events.sys_exit = evsel;
4202 else if (trace->summary)
4203 trace__fprintf_thread_summary(trace, trace->output);
4235 struct trace *trace, FILE *fp) argument
4263 sc = &trace->syscalls.table[syscall_stats_entry->syscall];
4269 if (trace->errno_summary && stats->nr_failures) {
4270 const char *arch_name = perf_env__arch(trace->host->env);
4287 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) argument
4296 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0;
4305 if (trace->sched)
4310 printed += thread__dump_stats(ttrace, trace, fp);
4329 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) argument
4336 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i);
4344 printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
4354 struct trace *trace = opt->value; local
4356 trace->duration_filter = atof(str);
4365 struct trace *trace = opt->value; local
4375 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
4376 trace->filter_pids.entries = calloc(i, sizeof(pid_t));
4378 if (trace->filter_pids.entries == NULL)
4381 trace->filter_pids.entries[0] = getpid();
4383 for (i = 1; i < trace->filter_pids.nr; ++i)
4384 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
4392 static int trace__open_output(struct trace *trace, const char *filename) argument
4404 trace->output = fopen(filename, "w");
4406 return trace->output == NULL ? -errno : 0;
4494 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
4502 struct trace *trace = (struct trace *)opt->value; local
4515 trace->not_ev_qualifier = true;
4523 if (syscalltbl__id(trace->sctbl, s) >= 0 ||
4524 syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) {
4560 trace->ev_qualifier = strlist__new(lists[1], &slist_config);
4561 if (trace->ev_qualifier == NULL) {
4562 fputs("Not enough memory to parse event qualifier", trace->output);
4566 if (trace__validate_ev_qualifier(trace))
4568 trace->trace_syscalls = true;
4575 .evlistp = &trace->evlist,
4594 struct trace *trace = opt->value; local
4596 if (!list_empty(&trace->evlist->core.entries)) {
4598 .value = &trace->evlist,
4602 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
4609 struct trace *trace = arg; local
4612 if (!strcmp(var, "trace.add_events")) {
4613 trace->perfconfig_events = strdup(value);
4614 if (trace->perfconfig_events == NULL) {
4615 pr_err("Not enough memory for %s\n", "trace.add_events");
4618 } else if (!strcmp(var, "trace.show_timestamp")) {
4619 trace->show_tstamp = perf_config_bool(var, value);
4620 } else if (!strcmp(var, "trace.show_duration")) {
4621 trace->show_duration = perf_config_bool(var, value);
4622 } else if (!strcmp(var, "trace.show_arg_names")) {
4623 trace->show_arg_names = perf_config_bool(var, value);
4624 if (!trace->show_arg_names)
4625 trace->show_zeros = true;
4626 } else if (!strcmp(var, "trace.show_zeros")) {
4628 if (!trace->show_arg_names && !new_show_zeros) {
4629 pr_warning("trace.show_zeros has to be set when trace.show_arg_names=no\n");
4632 trace->show_zeros = new_show_zeros;
4633 } else if (!strcmp(var, "trace.show_prefix")) {
4634 trace->show_string_prefix = perf_config_bool(var, value);
4635 } else if (!strcmp(var, "trace.no_inherit")) {
4636 trace->opts.no_inherit = perf_config_bool(var, value);
4637 } else if (!strcmp(var, "trace.args_alignment")) {
4640 trace->args_alignment = args_alignment;
4641 } else if (!strcmp(var, "trace.tracepoint_beautifiers")) {
4643 trace->libtraceevent_print = true;
4645 trace->libtraceevent_print = false;
4651 static void trace__exit(struct trace *trace) argument
4655 strlist__delete(trace->ev_qualifier);
4656 zfree(&trace->ev_qualifier_ids.entries);
4657 if (trace->syscalls.table) {
4658 for (i = 0; i <= trace->sctbl->syscalls.max_id; i++)
4659 syscall__exit(&trace->syscalls.table[i]);
4660 zfree(&trace->syscalls.table);
4662 syscalltbl__delete(trace->sctbl);
4663 zfree(&trace->perfconfig_events);
4681 "perf trace [<options>] [<command>]",
4682 "perf trace [<options>] -- <command> [<options>]",
4683 "perf trace record [<options>] [<command>]",
4684 "perf trace record [<options>] -- <command> [<options>]",
4687 struct trace trace = { local
4711 OPT_CALLBACK('e', "event", &trace, "event",
4714 OPT_CALLBACK(0, "filter", &trace.evlist, "filter",
4716 OPT_BOOLEAN(0, "comm", &trace.show_comm,
4718 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"),
4719 OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace",
4723 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid",
4724 "trace events on existing process id"),
4725 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid",
4726 "trace events on existing thread id"),
4727 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids",
4729 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide,
4731 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu",
4733 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit,
4735 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages",
4737 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user",
4739 OPT_CALLBACK(0, "duration", &trace, "float",
4742 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
4744 OPT_BOOLEAN('T', "time", &trace.full_time,
4746 OPT_BOOLEAN(0, "failure", &trace.failure_only,
4748 OPT_BOOLEAN('s', "summary", &trace.summary_only,
4750 OPT_BOOLEAN('S', "with-summary", &trace.summary,
4752 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary,
4754 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min",
4755 "Trace pagefaults", parse_pagefaults, "maj"),
4756 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
4757 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
4758 OPT_CALLBACK(0, "call-graph", &trace.opts,
4761 OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print,
4763 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
4765 OPT_ULONG(0, "max-events", &trace.max_events,
4767 OPT_UINTEGER(0, "min-stack", &trace.min_stack,
4770 OPT_UINTEGER(0, "max-stack", &trace.max_stack,
4774 OPT_BOOLEAN(0, "sort-events", &trace.sort_events,
4776 OPT_BOOLEAN(0, "print-sample", &trace.print_sample,
4780 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only",
4782 OPT_INTEGER('D', "delay", &trace.opts.target.initial_delay,
4785 OPTS_EVSWITCH(&trace.evswitch),
4805 trace.evlist = evlist__new();
4806 trace.sctbl = syscalltbl__new();
4808 if (trace.evlist == NULL || trace.sctbl == NULL) {
4818 * global setting. If it fails we'll get something in 'perf trace -v'
4823 err = perf_config(trace__config, &trace);
4839 * .perfconfig trace.add_events, and filter those out.
4841 if (!trace.trace_syscalls && !trace.trace_pgfaults &&
4842 trace.evlist->core.nr_entries == 0 /* Was --events used? */) {
4843 trace.trace_syscalls = true;
4851 if (trace.perfconfig_events != NULL) {
4855 err = parse_events(trace.evlist, trace.perfconfig_events, &parse_err);
4857 parse_events_error__print(&parse_err, trace.perfconfig_events);
4863 if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) {
4869 if (!trace.trace_syscalls)
4872 trace.skel = augmented_raw_syscalls_bpf__open();
4873 if (!trace.skel) {
4882 bpf_object__for_each_program(prog, trace.skel->obj) {
4883 if (prog != trace.skel->progs.sys_enter && prog != trace.skel->progs.sys_exit)
4887 err = augmented_raw_syscalls_bpf__load(trace.skel);
4893 augmented_raw_syscalls_bpf__attach(trace.skel);
4894 trace__add_syscall_newtp(&trace);
4898 err = bpf__setup_bpf_output(trace.evlist);
4904 trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
4905 assert(!strcmp(evsel__name(trace.syscalls.events.bpf_output), "__augmented_syscalls__"));
4910 if (trace.trace_pgfaults) {
4911 trace.opts.sample_address = true;
4912 trace.opts.sample_time = true;
4915 if (trace.opts.mmap_pages == UINT_MAX)
4918 if (trace.max_stack == UINT_MAX) {
4919 trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack();
4924 if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) {
4925 record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false);
4931 trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4;
4936 if (trace.evlist->core.nr_entries > 0) {
4937 evlist__set_default_evsel_handler(trace.evlist, trace__event_handler);
4938 if (evlist__set_syscall_tp_fields(trace.evlist)) {
4944 if (trace.sort_events) {
4945 ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace);
4946 ordered_events__set_copy_on_queue(&trace.oe.data, true);
4960 if (trace.syscalls.events.bpf_output) {
4961 evlist__for_each_entry(trace.evlist, evsel) {
4965 trace.raw_augmented_syscalls = true;
4969 if (trace.syscalls.events.bpf_output->priv == NULL &&
4971 struct evsel *augmented = trace.syscalls.events.bpf_output;
5018 if (trace.raw_augmented_syscalls)
5019 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset;
5027 return trace__record(&trace, argc-1, &argv[1]);
5030 if (trace.errno_summary && !trace.summary && !trace.summary_only)
5031 trace.summary_only = true;
5034 if (trace.summary_only)
5035 trace.summary = trace.summary_only;
5038 if (trace.summary)
5042 err = trace__open_output(&trace, output_name);
5049 err = evswitch__init(&trace.evswitch, trace.evlist, stderr);
5053 err = target__validate(&trace.opts.target);
5055 target__strerror(&trace.opts.target, err, bf, sizeof(bf));
5056 fprintf(trace.output, "%s", bf);
5060 err = target__parse_uid(&trace.opts.target);
5062 target__strerror(&trace.opts.target, err, bf, sizeof(bf));
5063 fprintf(trace.output, "%s", bf);
5067 if (!argc && target__none(&trace.opts.target))
5068 trace.opts.target.system_wide = true;
5071 err = trace__replay(&trace);
5073 err = trace__run(&trace, argc, argv);
5077 fclose(trace.output);
5079 trace__exit(&trace);
5081 augmented_raw_syscalls_bpf__destroy(trace.skel);