Lines Matching refs:trace
422 struct trace {
444 static bool trace__filter_duration(struct trace *trace, double t)
446 return t < (trace->duration_filter * NSEC_PER_MSEC);
449 static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
451 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC;
463 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread,
466 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp);
469 if (trace->multiple_threads)
475 static int trace__process_event(struct trace *trace, struct machine *machine,
482 color_fprintf(trace->output, PERF_COLOR_RED,
498 struct trace *trace = container_of(tool, struct trace, tool);
499 return trace__process_event(trace, machine, event);
502 static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
509 machine__init(&trace->host, "", HOST_KERNEL_ID);
510 machine__create_kernel_maps(&trace->host);
512 if (perf_target__has_task(&trace->opts.target)) {
513 err = perf_event__synthesize_thread_map(&trace->tool, evlist->threads,
515 &trace->host);
517 err = perf_event__synthesize_threads(&trace->tool, trace__tool_process,
518 &trace->host);
547 static int trace__read_syscall_info(struct trace *trace, int id)
551 const char *name = audit_syscall_to_name(id, trace->audit_machine);
556 if (id > trace->syscalls.max) {
557 struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc));
562 if (trace->syscalls.max != -1) {
563 memset(nsyscalls + trace->syscalls.max + 1, 0,
564 (id - trace->syscalls.max) * sizeof(*sc));
569 trace->syscalls.table = nsyscalls;
570 trace->syscalls.max = id;
573 sc = trace->syscalls.table + id;
576 if (trace->ev_qualifier) {
577 bool in = strlist__find(trace->ev_qualifier, name) != NULL;
579 if (!(in ^ trace->not_ev_qualifier)) {
643 typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel,
646 static struct syscall *trace__syscall_info(struct trace *trace,
666 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",
672 if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) &&
673 trace__read_syscall_info(trace, id))
676 if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL))
679 return &trace->syscalls.table[id];
683 fprintf(trace->output, "Problems reading syscall %d", id);
684 if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)
685 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);
686 fputs(" information\n", trace->output);
691 static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
698 struct syscall *sc = trace__syscall_info(trace, evsel, sample);
707 thread = machine__findnew_thread(&trace->host, sample->pid,
709 ttrace = thread__trace(thread, trace->output);
715 fprintf(trace->output, "Problems reading syscall arguments\n");
734 if (!trace->duration_filter) {
735 trace__fprintf_entry_head(trace, thread, 1, sample->time, trace->output);
736 fprintf(trace->output, "%-70s\n", ttrace->entry_str);
744 static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
750 struct syscall *sc = trace__syscall_info(trace, evsel, sample);
759 thread = machine__findnew_thread(&trace->host, sample->pid,
761 ttrace = thread__trace(thread, trace->output);
773 if (trace__filter_duration(trace, duration))
775 } else if (trace->duration_filter)
778 trace__fprintf_entry_head(trace, thread, duration, sample->time, trace->output);
781 fprintf(trace->output, "%-70s", ttrace->entry_str);
783 fprintf(trace->output, " ... [");
784 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued");
785 fprintf(trace->output, "]: %s()", sc->name);
790 fprintf(trace->output, ") = %d", ret);
796 fprintf(trace->output, ") = -1 %s %s", e, emsg);
798 fprintf(trace->output, ") = 0 Timeout");
800 fprintf(trace->output, ") = %#x", ret);
804 fputc('\n', trace->output);
811 static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evsel,
816 struct thread *thread = machine__findnew_thread(&trace->host,
819 struct thread_trace *ttrace = thread__trace(thread, trace->output);
825 trace->runtime_ms += runtime_ms;
829 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n",
838 static bool skip_sample(struct trace *trace, struct perf_sample *sample)
840 if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) ||
841 (trace->tid_list && intlist__find(trace->tid_list, sample->tid)))
844 if (trace->pid_list || trace->tid_list)
856 struct trace *trace = container_of(tool, struct trace, tool);
861 if (skip_sample(trace, sample))
864 if (trace->base_time == 0)
865 trace->base_time = sample->time;
868 handler(trace, evsel, sample);
883 static int parse_target_str(struct trace *trace)
885 if (trace->opts.target.pid) {
886 trace->pid_list = intlist__new(trace->opts.target.pid);
887 if (trace->pid_list == NULL) {
893 if (trace->opts.target.tid) {
894 trace->tid_list = intlist__new(trace->opts.target.tid);
895 if (trace->tid_list == NULL) {
904 static int trace__run(struct trace *trace, int argc, const char **argv)
913 fprintf(trace->output, "Not enough memory to run!\n");
919 fprintf(trace->output, "Couldn't read the raw_syscalls tracepoints information!\n");
923 if (trace->sched &&
926 fprintf(trace->output, "Couldn't read the sched_stat_runtime tracepoint information!\n");
930 err = perf_evlist__create_maps(evlist, &trace->opts.target);
932 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n");
936 err = trace__symbols_init(trace, evlist);
938 fprintf(trace->output, "Problems initializing symbol libraries!\n");
942 perf_evlist__config(evlist, &trace->opts);
948 err = perf_evlist__prepare_workload(evlist, &trace->opts.target,
951 fprintf(trace->output, "Couldn't run the workload!\n");
958 fprintf(trace->output, "Couldn't create the events: %s\n", strerror(errno));
964 fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
973 trace->multiple_threads = evlist->threads->map[0] == -1 || evlist->threads->nr > 1;
975 before = trace->nr_events;
985 ++trace->nr_events;
989 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err);
993 if (trace->base_time == 0)
994 trace->base_time = sample.time;
997 trace__process_event(trace, &trace->host, event);
1003 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample.id);
1008 fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
1015 handler(trace, evsel, &sample);
1024 if (trace->nr_events == before) {
1048 static int trace__replay(struct trace *trace)
1058 trace->tool.sample = trace__process_sample;
1059 trace->tool.mmap = perf_event__process_mmap;
1060 trace->tool.mmap2 = perf_event__process_mmap2;
1061 trace->tool.comm = perf_event__process_comm;
1062 trace->tool.exit = perf_event__process_exit;
1063 trace->tool.fork = perf_event__process_fork;
1064 trace->tool.attr = perf_event__process_attr;
1065 trace->tool.tracing_data = perf_event__process_tracing_data;
1066 trace->tool.build_id = perf_event__process_build_id;
1068 trace->tool.ordered_samples = true;
1069 trace->tool.ordering_requires_timestamps = true;
1072 trace->multiple_threads = true;
1078 &trace->tool);
1096 err = parse_target_str(trace);
1102 err = perf_session__process_events(session, &trace->tool);
1124 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp)
1129 for (nd = rb_first(&trace->host.threads); nd; nd = rb_next(nd)) {
1138 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0;
1160 struct trace *trace = opt->value;
1162 trace->duration_filter = atof(str);
1166 static int trace__open_output(struct trace *trace, const char *filename)
1178 trace->output = fopen(filename, "w");
1180 return trace->output == NULL ? -errno : 0;
1186 "perf trace [<options>] [<command>]",
1187 "perf trace [<options>] -- <command> [<options>]",
1190 struct trace trace = {
1211 "list of events to trace"),
1214 OPT_STRING('p', "pid", &trace.opts.target.pid, "pid",
1215 "trace events on existing process id"),
1216 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid",
1217 "trace events on existing thread id"),
1218 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide,
1220 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu",
1222 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit,
1224 OPT_UINTEGER('m', "mmap-pages", &trace.opts.mmap_pages,
1226 OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user",
1228 OPT_CALLBACK(0, "duration", &trace, "float",
1231 OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
1241 err = trace__open_output(&trace, output_name);
1251 trace.not_ev_qualifier = *s == '!';
1252 if (trace.not_ev_qualifier)
1254 trace.ev_qualifier = strlist__new(true, s);
1255 if (trace.ev_qualifier == NULL) {
1257 trace.output);
1263 err = perf_target__validate(&trace.opts.target);
1265 perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf));
1266 fprintf(trace.output, "%s", bf);
1270 err = perf_target__parse_uid(&trace.opts.target);
1272 perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf));
1273 fprintf(trace.output, "%s", bf);
1277 if (!argc && perf_target__none(&trace.opts.target))
1278 trace.opts.target.system_wide = true;
1281 err = trace__replay(&trace);
1283 err = trace__run(&trace, argc, argv);
1285 if (trace.sched && !err)
1286 trace__fprintf_thread_summary(&trace, trace.output);
1290 fclose(trace.output);