Lines Matching refs:trace
245 struct trace *trace; member
1216 struct trace { struct
1314 struct trace *trace) in thread__fd_path() argument
1325 if (!trace->live) in thread__fd_path()
1327 ++trace->stats.proc_getname; in thread__fd_path()
1340 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1361 static bool trace__filter_duration(struct trace *trace, double t) in trace__filter_duration() argument
1363 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1366 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) in trace__fprintf_tstamp() argument
1368 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in trace__fprintf_tstamp()
1382 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, in trace__fprintf_entry_head() argument
1385 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); in trace__fprintf_entry_head()
1388 if (trace->multiple_threads) { in trace__fprintf_entry_head()
1389 if (trace->show_comm) in trace__fprintf_entry_head()
1397 static int trace__process_event(struct trace *trace, struct machine *machine, in trace__process_event() argument
1404 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1420 struct trace *trace = container_of(tool, struct trace, tool); in trace__tool_process() local
1421 return trace__process_event(trace, machine, event, sample); in trace__tool_process()
1424 static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) in trace__symbols_init() argument
1431 trace->host = machine__new_host(); in trace__symbols_init()
1432 if (trace->host == NULL) in trace__symbols_init()
1435 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1466 static int trace__read_syscall_info(struct trace *trace, int id) in trace__read_syscall_info() argument
1470 const char *name = audit_syscall_to_name(id, trace->audit.machine); in trace__read_syscall_info()
1475 if (id > trace->syscalls.max) { in trace__read_syscall_info()
1476 struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); in trace__read_syscall_info()
1481 if (trace->syscalls.max != -1) { in trace__read_syscall_info()
1482 memset(nsyscalls + trace->syscalls.max + 1, 0, in trace__read_syscall_info()
1483 (id - trace->syscalls.max) * sizeof(*sc)); in trace__read_syscall_info()
1488 trace->syscalls.table = nsyscalls; in trace__read_syscall_info()
1489 trace->syscalls.max = id; in trace__read_syscall_info()
1492 sc = trace->syscalls.table + id; in trace__read_syscall_info()
1495 if (trace->ev_qualifier) { in trace__read_syscall_info()
1496 bool in = strlist__find(trace->ev_qualifier, name) != NULL; in trace__read_syscall_info()
1498 if (!(in ^ trace->not_ev_qualifier)) { in trace__read_syscall_info()
1544 unsigned char *args, struct trace *trace, in syscall__scnprintf_args() argument
1557 .trace = trace, in syscall__scnprintf_args()
1611 typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel,
1615 static struct syscall *trace__syscall_info(struct trace *trace, in trace__syscall_info() argument
1633 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", in trace__syscall_info()
1639 if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) && in trace__syscall_info()
1640 trace__read_syscall_info(trace, id)) in trace__syscall_info()
1643 if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL)) in trace__syscall_info()
1646 return &trace->syscalls.table[id]; in trace__syscall_info()
1650 fprintf(trace->output, "Problems reading syscall %d", id); in trace__syscall_info()
1651 if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) in trace__syscall_info()
1652 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); in trace__syscall_info()
1653 fputs(" information\n", trace->output); in trace__syscall_info()
1684 static int trace__printf_interrupted_entry(struct trace *trace, struct perf_sample *sample) in trace__printf_interrupted_entry() argument
1690 if (trace->current == NULL) in trace__printf_interrupted_entry()
1693 ttrace = thread__priv(trace->current); in trace__printf_interrupted_entry()
1700 printed = trace__fprintf_entry_head(trace, trace->current, duration, sample->time, trace->output); in trace__printf_interrupted_entry()
1701 printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str); in trace__printf_interrupted_entry()
1707 static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, in trace__sys_enter() argument
1716 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__sys_enter()
1725 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_enter()
1726 ttrace = thread__trace(thread, trace->output); in trace__sys_enter()
1738 if (!trace->summary_only) in trace__sys_enter()
1739 trace__printf_interrupted_entry(trace, sample); in trace__sys_enter()
1746 args, trace, thread); in trace__sys_enter()
1749 if (!trace->duration_filter && !trace->summary_only) { in trace__sys_enter()
1750 trace__fprintf_entry_head(trace, thread, 1, sample->time, trace->output); in trace__sys_enter()
1751 fprintf(trace->output, "%-70s\n", ttrace->entry_str); in trace__sys_enter()
1756 if (trace->current != thread) { in trace__sys_enter()
1757 thread__put(trace->current); in trace__sys_enter()
1758 trace->current = thread__get(thread); in trace__sys_enter()
1764 static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, in trace__sys_exit() argument
1772 struct syscall *sc = trace__syscall_info(trace, evsel, id); in trace__sys_exit()
1781 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__sys_exit()
1782 ttrace = thread__trace(thread, trace->output); in trace__sys_exit()
1786 if (trace->summary) in trace__sys_exit()
1791 if (id == trace->audit.open_id && ret >= 0 && trace->last_vfs_getname) { in trace__sys_exit()
1792 trace__set_fd_pathname(thread, ret, trace->last_vfs_getname); in trace__sys_exit()
1793 trace->last_vfs_getname = NULL; in trace__sys_exit()
1794 ++trace->stats.vfs_getname; in trace__sys_exit()
1801 if (trace__filter_duration(trace, duration)) in trace__sys_exit()
1803 } else if (trace->duration_filter) in trace__sys_exit()
1806 if (trace->summary_only) in trace__sys_exit()
1809 trace__fprintf_entry_head(trace, thread, duration, sample->time, trace->output); in trace__sys_exit()
1812 fprintf(trace->output, "%-70s", ttrace->entry_str); in trace__sys_exit()
1814 fprintf(trace->output, " ... ["); in trace__sys_exit()
1815 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); in trace__sys_exit()
1816 fprintf(trace->output, "]: %s()", sc->name); in trace__sys_exit()
1821 fprintf(trace->output, ") = %ld", ret); in trace__sys_exit()
1827 fprintf(trace->output, ") = -1 %s %s", e, emsg); in trace__sys_exit()
1829 fprintf(trace->output, ") = 0 Timeout"); in trace__sys_exit()
1831 fprintf(trace->output, ") = %#lx", ret); in trace__sys_exit()
1835 fputc('\n', trace->output); in trace__sys_exit()
1842 static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, in trace__vfs_getname() argument
1846 trace->last_vfs_getname = perf_evsel__rawptr(evsel, sample, "pathname"); in trace__vfs_getname()
1850 static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evsel, in trace__sched_stat_runtime() argument
1856 struct thread *thread = machine__findnew_thread(trace->host, in trace__sched_stat_runtime()
1859 struct thread_trace *ttrace = thread__trace(thread, trace->output); in trace__sched_stat_runtime()
1865 trace->runtime_ms += runtime_ms; in trace__sched_stat_runtime()
1869 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", in trace__sched_stat_runtime()
1878 static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel, in trace__event_handler() argument
1882 trace__printf_interrupted_entry(trace, sample); in trace__event_handler()
1883 trace__fprintf_tstamp(trace, sample->time, trace->output); in trace__event_handler()
1885 if (trace->trace_syscalls) in trace__event_handler()
1886 fprintf(trace->output, "( ): "); in trace__event_handler()
1888 fprintf(trace->output, "%s:", evsel->name); in trace__event_handler()
1893 trace->output); in trace__event_handler()
1896 fprintf(trace->output, ")\n"); in trace__event_handler()
1917 static int trace__pgfault(struct trace *trace, in trace__pgfault() argument
1928 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); in trace__pgfault()
1929 ttrace = thread__trace(thread, trace->output); in trace__pgfault()
1938 if (trace->summary_only) in trace__pgfault()
1944 trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); in trace__pgfault()
1946 fprintf(trace->output, "%sfault [", in trace__pgfault()
1950 print_location(trace->output, sample, &al, false, true); in trace__pgfault()
1952 fprintf(trace->output, "] => "); in trace__pgfault()
1967 print_location(trace->output, sample, &al, true, false); in trace__pgfault()
1969 fprintf(trace->output, " (%c%c)\n", map_type, al.level); in trace__pgfault()
1974 static bool skip_sample(struct trace *trace, struct perf_sample *sample) in skip_sample() argument
1976 if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) || in skip_sample()
1977 (trace->tid_list && intlist__find(trace->tid_list, sample->tid))) in skip_sample()
1980 if (trace->pid_list || trace->tid_list) in skip_sample()
1992 struct trace *trace = container_of(tool, struct trace, tool); in trace__process_sample() local
1997 if (skip_sample(trace, sample)) in trace__process_sample()
2000 if (!trace->full_time && trace->base_time == 0) in trace__process_sample()
2001 trace->base_time = sample->time; in trace__process_sample()
2004 ++trace->nr_events; in trace__process_sample()
2005 handler(trace, evsel, event, sample); in trace__process_sample()
2011 static int parse_target_str(struct trace *trace) in parse_target_str() argument
2013 if (trace->opts.target.pid) { in parse_target_str()
2014 trace->pid_list = intlist__new(trace->opts.target.pid); in parse_target_str()
2015 if (trace->pid_list == NULL) { in parse_target_str()
2021 if (trace->opts.target.tid) { in parse_target_str()
2022 trace->tid_list = intlist__new(trace->opts.target.tid); in parse_target_str()
2023 if (trace->tid_list == NULL) { in parse_target_str()
2032 static int trace__record(struct trace *trace, int argc, const char **argv) in trace__record() argument
2062 if (trace->trace_syscalls) { in trace__record()
2077 if (trace->trace_pgfaults & TRACE_PFMAJ) in trace__record()
2081 if (trace->trace_pgfaults & TRACE_PFMIN) in trace__record()
2091 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
2132 static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *s… in trace__handle_event() argument
2137 if (!trace->full_time && trace->base_time == 0) in trace__handle_event()
2138 trace->base_time = sample->time; in trace__handle_event()
2141 trace__process_event(trace, trace->host, event, sample); in trace__handle_event()
2145 evsel = perf_evlist__id2evsel(trace->evlist, sample->id); in trace__handle_event()
2147 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); in trace__handle_event()
2153 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", in trace__handle_event()
2158 handler(trace, evsel, event, sample); in trace__handle_event()
2162 static int trace__run(struct trace *trace, int argc, const char **argv) in trace__run() argument
2164 struct perf_evlist *evlist = trace->evlist; in trace__run()
2170 trace->live = true; in trace__run()
2172 if (trace->trace_syscalls && in trace__run()
2177 if (trace->trace_syscalls) in trace__run()
2180 if ((trace->trace_pgfaults & TRACE_PFMAJ) && in trace__run()
2185 if ((trace->trace_pgfaults & TRACE_PFMIN) && in trace__run()
2189 if (trace->sched && in trace__run()
2194 err = perf_evlist__create_maps(evlist, &trace->opts.target); in trace__run()
2196 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); in trace__run()
2200 err = trace__symbols_init(trace, evlist); in trace__run()
2202 fprintf(trace->output, "Problems initializing symbol libraries!\n"); in trace__run()
2206 perf_evlist__config(evlist, &trace->opts); in trace__run()
2212 err = perf_evlist__prepare_workload(evlist, &trace->opts.target, in trace__run()
2215 fprintf(trace->output, "Couldn't run the workload!\n"); in trace__run()
2230 if (trace->filter_pids.nr > 0) in trace__run()
2231 err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); in trace__run()
2240 err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false); in trace__run()
2244 if (!target__none(&trace->opts.target)) in trace__run()
2250 trace->multiple_threads = evlist->threads->map[0] == -1 || in trace__run()
2254 before = trace->nr_events; in trace__run()
2262 ++trace->nr_events; in trace__run()
2266 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); in trace__run()
2270 trace__handle_event(trace, event, &sample); in trace__run()
2284 if (trace->nr_events == before) { in trace__run()
2298 thread__zput(trace->current); in trace__run()
2303 if (trace->summary) in trace__run()
2304 trace__fprintf_thread_summary(trace, trace->output); in trace__run()
2306 if (trace->show_tool_stats) { in trace__run()
2307 fprintf(trace->output, "Stats:\n " in trace__run()
2310 trace->stats.vfs_getname, in trace__run()
2311 trace->stats.proc_getname); in trace__run()
2317 trace->evlist = NULL; in trace__run()
2318 trace->live = false; in trace__run()
2339 fprintf(trace->output, "%s\n", errbuf); in trace__run()
2343 fprintf(trace->output, "Not enough memory to run!\n"); in trace__run()
2347 static int trace__replay(struct trace *trace) in trace__replay() argument
2355 .force = trace->force, in trace__replay()
2361 trace->tool.sample = trace__process_sample; in trace__replay()
2362 trace->tool.mmap = perf_event__process_mmap; in trace__replay()
2363 trace->tool.mmap2 = perf_event__process_mmap2; in trace__replay()
2364 trace->tool.comm = perf_event__process_comm; in trace__replay()
2365 trace->tool.exit = perf_event__process_exit; in trace__replay()
2366 trace->tool.fork = perf_event__process_fork; in trace__replay()
2367 trace->tool.attr = perf_event__process_attr; in trace__replay()
2368 trace->tool.tracing_data = perf_event__process_tracing_data; in trace__replay()
2369 trace->tool.build_id = perf_event__process_build_id; in trace__replay()
2371 trace->tool.ordered_events = true; in trace__replay()
2372 trace->tool.ordering_requires_timestamps = true; in trace__replay()
2375 trace->multiple_threads = true; in trace__replay()
2377 session = perf_session__new(&file, false, &trace->tool); in trace__replay()
2384 trace->host = &session->machines.host; in trace__replay()
2424 err = parse_target_str(trace); in trace__replay()
2434 else if (trace->summary) in trace__replay()
2435 trace__fprintf_thread_summary(trace, trace->output); in trace__replay()
2453 struct trace *trace, FILE *fp) in thread__dump_stats() argument
2482 sc = &trace->syscalls.table[inode->i]; in thread__dump_stats()
2500 struct trace *trace; member
2509 struct trace *trace = data->trace; in trace__fprintf_one_thread() local
2516 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; in trace__fprintf_one_thread()
2526 printed += thread__dump_stats(ttrace, trace, fp); in trace__fprintf_one_thread()
2533 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) in trace__fprintf_thread_summary() argument
2537 .trace = trace in trace__fprintf_thread_summary()
2541 machine__for_each_thread(trace->host, trace__fprintf_one_thread, &data); in trace__fprintf_thread_summary()
2549 struct trace *trace = opt->value; in trace__set_duration() local
2551 trace->duration_filter = atof(str); in trace__set_duration()
2560 struct trace *trace = opt->value; in trace__set_filter_pids() local
2570 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; in trace__set_filter_pids()
2571 trace->filter_pids.entries = calloc(i, sizeof(pid_t)); in trace__set_filter_pids()
2573 if (trace->filter_pids.entries == NULL) in trace__set_filter_pids()
2576 trace->filter_pids.entries[0] = getpid(); in trace__set_filter_pids()
2578 for (i = 1; i < trace->filter_pids.nr; ++i) in trace__set_filter_pids()
2579 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; in trace__set_filter_pids()
2587 static int trace__open_output(struct trace *trace, const char *filename) in trace__open_output() argument
2599 trace->output = fopen(filename, "w"); in trace__open_output()
2601 return trace->output == NULL ? -errno : 0; in trace__open_output()
2638 struct trace trace = { in cmd_trace() local
2641 .open_id = audit_name_to_syscall("open", trace.audit.machine), in cmd_trace()
2663 OPT_CALLBACK(0, "event", &trace.evlist, "event", in cmd_trace()
2666 OPT_BOOLEAN(0, "comm", &trace.show_comm, in cmd_trace()
2668 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), in cmd_trace()
2673 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", in cmd_trace()
2675 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", in cmd_trace()
2677 OPT_CALLBACK(0, "filter-pids", &trace, "float", in cmd_trace()
2679 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, in cmd_trace()
2681 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", in cmd_trace()
2683 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, in cmd_trace()
2685 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", in cmd_trace()
2688 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", in cmd_trace()
2690 OPT_CALLBACK(0, "duration", &trace, "float", in cmd_trace()
2693 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), in cmd_trace()
2695 OPT_BOOLEAN('T', "time", &trace.full_time, in cmd_trace()
2697 OPT_BOOLEAN('s', "summary", &trace.summary_only, in cmd_trace()
2699 OPT_BOOLEAN('S', "with-summary", &trace.summary, in cmd_trace()
2701 OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", in cmd_trace()
2703 OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), in cmd_trace()
2704 OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), in cmd_trace()
2714 trace.evlist = perf_evlist__new(); in cmd_trace()
2715 if (trace.evlist == NULL) in cmd_trace()
2718 if (trace.evlist == NULL) { in cmd_trace()
2726 if (trace.trace_pgfaults) { in cmd_trace()
2727 trace.opts.sample_address = true; in cmd_trace()
2728 trace.opts.sample_time = true; in cmd_trace()
2731 if (trace.evlist->nr_entries > 0) in cmd_trace()
2732 evlist__set_evsel_handler(trace.evlist, trace__event_handler); in cmd_trace()
2735 return trace__record(&trace, argc-1, &argv[1]); in cmd_trace()
2738 if (trace.summary_only) in cmd_trace()
2739 trace.summary = trace.summary_only; in cmd_trace()
2741 if (!trace.trace_syscalls && !trace.trace_pgfaults && in cmd_trace()
2742 trace.evlist->nr_entries == 0 /* Was --events used? */) { in cmd_trace()
2748 err = trace__open_output(&trace, output_name); in cmd_trace()
2758 trace.not_ev_qualifier = *s == '!'; in cmd_trace()
2759 if (trace.not_ev_qualifier) in cmd_trace()
2761 trace.ev_qualifier = strlist__new(true, s); in cmd_trace()
2762 if (trace.ev_qualifier == NULL) { in cmd_trace()
2764 trace.output); in cmd_trace()
2770 err = target__validate(&trace.opts.target); in cmd_trace()
2772 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
2773 fprintf(trace.output, "%s", bf); in cmd_trace()
2777 err = target__parse_uid(&trace.opts.target); in cmd_trace()
2779 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); in cmd_trace()
2780 fprintf(trace.output, "%s", bf); in cmd_trace()
2784 if (!argc && target__none(&trace.opts.target)) in cmd_trace()
2785 trace.opts.target.system_wide = true; in cmd_trace()
2788 err = trace__replay(&trace); in cmd_trace()
2790 err = trace__run(&trace, argc, argv); in cmd_trace()
2794 fclose(trace.output); in cmd_trace()