4 #include "util/cache.h"
5 #include "util/symbol.h"
6 #include "util/thread.h"
7 #include "util/header.h"
9 #include "util/parse-options.h"
12 #include "util/debug.h"
14 #include "util/trace-event.h"
15 #include "util/data_map.h"
17 static char const *input_name = "perf.data";
19 static struct perf_header *header;
20 static u64 sample_type;
22 static int process_sample_event(event_t *event)
24 u64 ip = event->ip.ip;
28 void *more_data = event->ip.__more_data;
29 struct thread *thread = threads__findnew(event->ip.pid);
31 if (sample_type & PERF_SAMPLE_TIME) {
32 timestamp = *(u64 *)more_data;
33 more_data += sizeof(u64);
36 if (sample_type & PERF_SAMPLE_CPU) {
37 cpu = *(u32 *)more_data;
38 more_data += sizeof(u32);
39 more_data += sizeof(u32); /* reserved */
42 if (sample_type & PERF_SAMPLE_PERIOD) {
43 period = *(u64 *)more_data;
44 more_data += sizeof(u64);
47 dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
49 event->ip.pid, event->ip.tid,
54 pr_debug("problem processing %d event, skipping it.\n",
59 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
61 if (sample_type & PERF_SAMPLE_RAW) {
68 * FIXME: better resolve from pid from the struct trace_entry
69 * field, although it should be the same than this perf
72 print_event(cpu, raw->data, raw->size, timestamp, thread->comm);
74 event__stats.total += period;
79 static int sample_type_check(u64 type)
83 if (!(sample_type & PERF_SAMPLE_RAW)) {
85 "No trace sample to read. Did you call perf record "
93 static struct perf_file_handler file_handler = {
94 .process_sample_event = process_sample_event,
95 .process_comm_event = event__process_comm,
96 .sample_type_check = sample_type_check,
99 static int __cmd_trace(void)
101 register_idle_thread();
102 register_perf_file_handler(&file_handler);
104 return mmap_dispatch_perf_file(&header, input_name,
105 0, 0, &event__cwdlen, &event__cwd);
108 static const char * const annotate_usage[] = {
109 "perf trace [<options>] <command>",
113 static const struct option options[] = {
114 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
115 "dump raw trace in ASCII"),
116 OPT_BOOLEAN('v', "verbose", &verbose,
117 "be more verbose (show symbol address, etc)"),
118 OPT_BOOLEAN('l', "latency", &latency_format,
119 "show latency attributes (irqs/preemption disabled, etc)"),
123 int cmd_trace(int argc, const char **argv, const char *prefix __used)
127 argc = parse_options(argc, argv, options, annotate_usage, 0);
130 * Special case: if there's an argument left then assume tha
131 * it's a symbol filter:
134 usage_with_options(annotate_usage, options);
139 return __cmd_trace();