Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | |
| 3 | #include "util/util.h" |
| 4 | #include "util/cache.h" |
| 5 | #include "util/symbol.h" |
| 6 | #include "util/thread.h" |
| 7 | #include "util/header.h" |
| 8 | |
| 9 | #include "util/parse-options.h" |
| 10 | |
| 11 | #include "perf.h" |
| 12 | #include "util/debug.h" |
| 13 | |
| 14 | #include "util/trace-event.h" |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 15 | #include "util/data_map.h" |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 16 | |
| 17 | static char const *input_name = "perf.data"; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 18 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 19 | static struct perf_header *header; |
| 20 | static u64 sample_type; |
| 21 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame^] | 22 | static int process_sample_event(event_t *event) |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 23 | { |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 24 | u64 ip = event->ip.ip; |
Ingo Molnar | 6ddf259 | 2009-09-03 12:00:22 +0200 | [diff] [blame] | 25 | u64 timestamp = -1; |
Ingo Molnar | cd6feee | 2009-09-02 20:20:38 +0200 | [diff] [blame] | 26 | u32 cpu = -1; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 27 | u64 period = 1; |
| 28 | void *more_data = event->ip.__more_data; |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 29 | struct thread *thread = threads__findnew(event->ip.pid); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 30 | |
Ingo Molnar | 6ddf259 | 2009-09-03 12:00:22 +0200 | [diff] [blame] | 31 | if (sample_type & PERF_SAMPLE_TIME) { |
| 32 | timestamp = *(u64 *)more_data; |
| 33 | more_data += sizeof(u64); |
| 34 | } |
| 35 | |
Ingo Molnar | cd6feee | 2009-09-02 20:20:38 +0200 | [diff] [blame] | 36 | if (sample_type & PERF_SAMPLE_CPU) { |
| 37 | cpu = *(u32 *)more_data; |
| 38 | more_data += sizeof(u32); |
| 39 | more_data += sizeof(u32); /* reserved */ |
| 40 | } |
| 41 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 42 | if (sample_type & PERF_SAMPLE_PERIOD) { |
| 43 | period = *(u64 *)more_data; |
| 44 | more_data += sizeof(u64); |
| 45 | } |
| 46 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame^] | 47 | dump_printf("(IP, %d): %d/%d: %p period: %Ld\n", |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 48 | event->header.misc, |
| 49 | event->ip.pid, event->ip.tid, |
| 50 | (void *)(long)ip, |
| 51 | (long long)period); |
| 52 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 53 | if (thread == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 54 | pr_debug("problem processing %d event, skipping it.\n", |
| 55 | event->header.type); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | |
Julia Lawall | f39cdf2 | 2009-10-17 08:43:17 +0200 | [diff] [blame] | 59 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 60 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 61 | if (sample_type & PERF_SAMPLE_RAW) { |
| 62 | struct { |
| 63 | u32 size; |
| 64 | char data[0]; |
| 65 | } *raw = more_data; |
| 66 | |
| 67 | /* |
| 68 | * FIXME: better resolve from pid from the struct trace_entry |
| 69 | * field, although it should be the same than this perf |
| 70 | * event pid |
| 71 | */ |
Ingo Molnar | 6ddf259 | 2009-09-03 12:00:22 +0200 | [diff] [blame] | 72 | print_event(cpu, raw->data, raw->size, timestamp, thread->comm); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 73 | } |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame^] | 74 | event__stats.total += period; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 79 | static int sample_type_check(u64 type) |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 80 | { |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 81 | sample_type = type; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 82 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 83 | if (!(sample_type & PERF_SAMPLE_RAW)) { |
| 84 | fprintf(stderr, |
| 85 | "No trace sample to read. Did you call perf record " |
| 86 | "without -R?"); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 93 | static struct perf_file_handler file_handler = { |
| 94 | .process_sample_event = process_sample_event, |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame^] | 95 | .process_comm_event = event__process_comm, |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 96 | .sample_type_check = sample_type_check, |
| 97 | }; |
| 98 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 99 | static int __cmd_trace(void) |
| 100 | { |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 101 | register_idle_thread(); |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 102 | register_perf_file_handler(&file_handler); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 103 | |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 104 | return mmap_dispatch_perf_file(&header, input_name, |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame^] | 105 | 0, 0, &event__cwdlen, &event__cwd); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static const char * const annotate_usage[] = { |
| 109 | "perf trace [<options>] <command>", |
| 110 | NULL |
| 111 | }; |
| 112 | |
| 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)"), |
Steven Rostedt | cda4846 | 2009-10-14 15:43:42 -0400 | [diff] [blame] | 118 | OPT_BOOLEAN('l', "latency", &latency_format, |
| 119 | "show latency attributes (irqs/preemption disabled, etc)"), |
Masami Hiramatsu | 1909629 | 2009-08-21 14:56:03 -0400 | [diff] [blame] | 120 | OPT_END() |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | int cmd_trace(int argc, const char **argv, const char *prefix __used) |
| 124 | { |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 125 | symbol__init(0); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 126 | |
| 127 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
| 128 | if (argc) { |
| 129 | /* |
| 130 | * Special case: if there's an argument left then assume tha |
| 131 | * it's a symbol filter: |
| 132 | */ |
| 133 | if (argc > 1) |
| 134 | usage_with_options(annotate_usage, options); |
| 135 | } |
| 136 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 137 | setup_pager(); |
| 138 | |
| 139 | return __cmd_trace(); |
| 140 | } |