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 unsigned long total
= 0;
20 static unsigned long total_comm
= 0;
22 static struct perf_header
*header
;
23 static u64 sample_type
;
30 process_comm_event(event_t
*event
, unsigned long offset
, unsigned long head
)
32 struct thread
*thread
= threads__findnew(event
->comm
.pid
);
34 dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n",
35 (void *)(offset
+ head
),
36 (void *)(long)(event
->header
.size
),
37 event
->comm
.comm
, event
->comm
.pid
);
40 thread__set_comm(thread
, event
->comm
.comm
)) {
41 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
50 process_sample_event(event_t
*event
, unsigned long offset
, unsigned long head
)
52 u64 ip
= event
->ip
.ip
;
56 void *more_data
= event
->ip
.__more_data
;
57 struct thread
*thread
= threads__findnew(event
->ip
.pid
);
59 if (sample_type
& PERF_SAMPLE_TIME
) {
60 timestamp
= *(u64
*)more_data
;
61 more_data
+= sizeof(u64
);
64 if (sample_type
& PERF_SAMPLE_CPU
) {
65 cpu
= *(u32
*)more_data
;
66 more_data
+= sizeof(u32
);
67 more_data
+= sizeof(u32
); /* reserved */
70 if (sample_type
& PERF_SAMPLE_PERIOD
) {
71 period
= *(u64
*)more_data
;
72 more_data
+= sizeof(u64
);
75 dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n",
76 (void *)(offset
+ head
),
77 (void *)(long)(event
->header
.size
),
79 event
->ip
.pid
, event
->ip
.tid
,
84 pr_debug("problem processing %d event, skipping it.\n",
89 dump_printf(" ... thread: %s:%d\n", thread
->comm
, thread
->pid
);
91 if (sample_type
& PERF_SAMPLE_RAW
) {
98 * FIXME: better resolve from pid from the struct trace_entry
99 * field, although it should be the same than this perf
102 print_event(cpu
, raw
->data
, raw
->size
, timestamp
, thread
->comm
);
109 static int sample_type_check(u64 type
)
113 if (!(sample_type
& PERF_SAMPLE_RAW
)) {
115 "No trace sample to read. Did you call perf record "
123 static struct perf_file_handler file_handler
= {
124 .process_sample_event
= process_sample_event
,
125 .process_comm_event
= process_comm_event
,
126 .sample_type_check
= sample_type_check
,
129 static int __cmd_trace(void)
131 register_idle_thread();
132 register_perf_file_handler(&file_handler
);
134 return mmap_dispatch_perf_file(&header
, input_name
,
135 0, 0, &cwdlen
, &cwd
);
138 static const char * const annotate_usage
[] = {
139 "perf trace [<options>] <command>",
143 static const struct option options
[] = {
144 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
145 "dump raw trace in ASCII"),
146 OPT_BOOLEAN('v', "verbose", &verbose
,
147 "be more verbose (show symbol address, etc)"),
148 OPT_BOOLEAN('l', "latency", &latency_format
,
149 "show latency attributes (irqs/preemption disabled, etc)"),
153 int cmd_trace(int argc
, const char **argv
, const char *prefix __used
)
157 argc
= parse_options(argc
, argv
, options
, annotate_usage
, 0);
160 * Special case: if there's an argument left then assume tha
161 * it's a symbol filter:
164 usage_with_options(annotate_usage
, options
);
169 return __cmd_trace();