blob: 558bcf99694935a706fd2d0e4dde914880918c7f [file] [log] [blame]
Xiao Guangrongb8f46c52010-02-03 11:53:14 +08001#define _FILE_OFFSET_BITS 64
2
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02003#include <linux/kernel.h>
4
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -02005#include <byteswap.h>
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02006#include <unistd.h>
7#include <sys/types.h>
Arnaldo Carvalho de Meloa41794c2010-05-18 18:29:23 -03008#include <sys/mman.h>
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02009
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030010#include "evlist.h"
11#include "evsel.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020012#include "session.h"
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020013#include "sort.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020014#include "util.h"
15
16static int perf_session__open(struct perf_session *self, bool force)
17{
18 struct stat input_stat;
19
Tom Zanussi8dc58102010-04-01 23:59:15 -050020 if (!strcmp(self->filename, "-")) {
21 self->fd_pipe = true;
22 self->fd = STDIN_FILENO;
23
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -030024 if (perf_session__read_header(self, self->fd) < 0)
Tom Zanussi8dc58102010-04-01 23:59:15 -050025 pr_err("incompatible file format");
26
27 return 0;
28 }
29
Xiao Guangrongf887f302010-02-04 16:46:42 +080030 self->fd = open(self->filename, O_RDONLY);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020031 if (self->fd < 0) {
Andy Isaacson0f2c3de2010-06-11 20:36:15 -070032 int err = errno;
33
34 pr_err("failed to open %s: %s", self->filename, strerror(err));
35 if (err == ENOENT && !strcmp(self->filename, "perf.data"))
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020036 pr_err(" (try 'perf record' first)");
37 pr_err("\n");
38 return -errno;
39 }
40
41 if (fstat(self->fd, &input_stat) < 0)
42 goto out_close;
43
44 if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) {
45 pr_err("file %s not owned by current user or root\n",
46 self->filename);
47 goto out_close;
48 }
49
50 if (!input_stat.st_size) {
51 pr_info("zero-sized file (%s), nothing to do!\n",
52 self->filename);
53 goto out_close;
54 }
55
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -030056 if (perf_session__read_header(self, self->fd) < 0) {
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020057 pr_err("incompatible file format");
58 goto out_close;
59 }
60
Arnaldo Carvalho de Meloc2a70652011-06-02 11:04:54 -030061 if (!perf_evlist__valid_sample_type(self->evlist)) {
62 pr_err("non matching sample_type");
63 goto out_close;
64 }
65
66 if (!perf_evlist__valid_sample_id_all(self->evlist)) {
67 pr_err("non matching sample_id_all");
68 goto out_close;
69 }
70
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020071 self->size = input_stat.st_size;
72 return 0;
73
74out_close:
75 close(self->fd);
76 self->fd = -1;
77 return -1;
78}
79
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -020080static void perf_session__id_header_size(struct perf_session *session)
Tom Zanussi8dc58102010-04-01 23:59:15 -050081{
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -020082 struct perf_sample *data;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -020083 u64 sample_type = session->sample_type;
84 u16 size = 0;
85
86 if (!session->sample_id_all)
87 goto out;
88
89 if (sample_type & PERF_SAMPLE_TID)
90 size += sizeof(data->tid) * 2;
91
92 if (sample_type & PERF_SAMPLE_TIME)
93 size += sizeof(data->time);
94
95 if (sample_type & PERF_SAMPLE_ID)
96 size += sizeof(data->id);
97
98 if (sample_type & PERF_SAMPLE_STREAM_ID)
99 size += sizeof(data->stream_id);
100
101 if (sample_type & PERF_SAMPLE_CPU)
102 size += sizeof(data->cpu) * 2;
103out:
104 session->id_hdr_size = size;
105}
106
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200107void perf_session__update_sample_type(struct perf_session *self)
108{
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -0300109 self->sample_type = perf_evlist__sample_type(self->evlist);
Arnaldo Carvalho de Meloc2a70652011-06-02 11:04:54 -0300110 self->sample_size = __perf_evsel__sample_size(self->sample_type);
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -0300111 self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200112 perf_session__id_header_size(self);
113}
114
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800115int perf_session__create_kernel_maps(struct perf_session *self)
116{
Arnaldo Carvalho de Melod118f8b2010-05-10 12:51:05 -0300117 int ret = machine__create_kernel_maps(&self->host_machine);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800118
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800119 if (ret >= 0)
Arnaldo Carvalho de Melod118f8b2010-05-10 12:51:05 -0300120 ret = machines__create_guest_kernel_maps(&self->machines);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800121 return ret;
122}
123
Arnaldo Carvalho de Melo076c6e452010-08-02 18:18:28 -0300124static void perf_session__destroy_kernel_maps(struct perf_session *self)
125{
126 machine__destroy_kernel_maps(&self->host_machine);
127 machines__destroy_guest_kernel_maps(&self->machines);
128}
129
Ian Munsie21ef97f2010-12-10 14:09:16 +1100130struct perf_session *perf_session__new(const char *filename, int mode,
131 bool force, bool repipe,
132 struct perf_event_ops *ops)
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200133{
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200134 size_t len = filename ? strlen(filename) + 1 : 0;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200135 struct perf_session *self = zalloc(sizeof(*self) + len);
136
137 if (self == NULL)
138 goto out;
139
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200140 memcpy(self->filename, filename, len);
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200141 self->threads = RB_ROOT;
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -0300142 INIT_LIST_HEAD(&self->dead_threads);
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200143 self->last_match = NULL;
Thomas Gleixner55b446292010-11-30 17:49:46 +0000144 /*
145 * On 64bit we can mmap the data file in one go. No need for tiny mmap
146 * slices. On 32bit we use 32MB.
147 */
148#if BITS_PER_LONG == 64
149 self->mmap_window = ULLONG_MAX;
150#else
151 self->mmap_window = 32 * 1024 * 1024ULL;
152#endif
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300153 self->machines = RB_ROOT;
Tom Zanussi454c4072010-05-01 01:41:20 -0500154 self->repipe = repipe;
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000155 INIT_LIST_HEAD(&self->ordered_samples.samples);
Thomas Gleixner020bb752010-11-30 17:49:53 +0000156 INIT_LIST_HEAD(&self->ordered_samples.sample_cache);
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000157 INIT_LIST_HEAD(&self->ordered_samples.to_free);
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300158 machine__init(&self->host_machine, "", HOST_KERNEL_ID);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200159
Arnaldo Carvalho de Melo64abebf72010-01-27 21:05:52 -0200160 if (mode == O_RDONLY) {
161 if (perf_session__open(self, force) < 0)
162 goto out_delete;
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -0300163 perf_session__update_sample_type(self);
Arnaldo Carvalho de Melo64abebf72010-01-27 21:05:52 -0200164 } else if (mode == O_WRONLY) {
165 /*
166 * In O_RDONLY mode this will be performed when reading the
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200167 * kernel MMAP event, in perf_event__process_mmap().
Arnaldo Carvalho de Melo64abebf72010-01-27 21:05:52 -0200168 */
169 if (perf_session__create_kernel_maps(self) < 0)
170 goto out_delete;
171 }
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -0200172
Ian Munsie21ef97f2010-12-10 14:09:16 +1100173 if (ops && ops->ordering_requires_timestamps &&
174 ops->ordered_samples && !self->sample_id_all) {
175 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
176 ops->ordered_samples = false;
177 }
178
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200179out:
180 return self;
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200181out_delete:
182 perf_session__delete(self);
183 return NULL;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200184}
185
Arnaldo Carvalho de Melod65a4582010-07-30 18:31:28 -0300186static void perf_session__delete_dead_threads(struct perf_session *self)
187{
188 struct thread *n, *t;
189
190 list_for_each_entry_safe(t, n, &self->dead_threads, node) {
191 list_del(&t->node);
192 thread__delete(t);
193 }
194}
195
196static void perf_session__delete_threads(struct perf_session *self)
197{
198 struct rb_node *nd = rb_first(&self->threads);
199
200 while (nd) {
201 struct thread *t = rb_entry(nd, struct thread, rb_node);
202
203 rb_erase(&t->rb_node, &self->threads);
204 nd = rb_next(nd);
205 thread__delete(t);
206 }
207}
208
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200209void perf_session__delete(struct perf_session *self)
210{
Arnaldo Carvalho de Melo076c6e452010-08-02 18:18:28 -0300211 perf_session__destroy_kernel_maps(self);
Arnaldo Carvalho de Melod65a4582010-07-30 18:31:28 -0300212 perf_session__delete_dead_threads(self);
213 perf_session__delete_threads(self);
214 machine__exit(&self->host_machine);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200215 close(self->fd);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200216 free(self);
217}
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200218
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -0300219void perf_session__remove_thread(struct perf_session *self, struct thread *th)
220{
Arnaldo Carvalho de Melo70597f22010-08-02 18:59:28 -0300221 self->last_match = NULL;
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -0300222 rb_erase(&th->rb_node, &self->threads);
223 /*
224 * We may have references to this thread, for instance in some hist_entry
225 * instances, so just move them to a separate list.
226 */
227 list_add_tail(&th->node, &self->dead_threads);
228}
229
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200230static bool symbol__match_parent_regex(struct symbol *sym)
231{
232 if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0))
233 return 1;
234
235 return 0;
236}
237
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100238int perf_session__resolve_callchain(struct perf_session *self,
239 struct thread *thread,
240 struct ip_callchain *chain,
241 struct symbol **parent)
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200242{
243 u8 cpumode = PERF_RECORD_MISC_USER;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200244 unsigned int i;
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100245 int err;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200246
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100247 callchain_cursor_reset(&self->callchain_cursor);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200248
249 for (i = 0; i < chain->nr; i++) {
Sam Liaod797fdc2011-06-07 23:49:46 +0800250 u64 ip;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200251 struct addr_location al;
252
Sam Liaod797fdc2011-06-07 23:49:46 +0800253 if (callchain_param.order == ORDER_CALLEE)
254 ip = chain->ips[i];
255 else
256 ip = chain->ips[chain->nr - i - 1];
257
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200258 if (ip >= PERF_CONTEXT_MAX) {
259 switch (ip) {
260 case PERF_CONTEXT_HV:
261 cpumode = PERF_RECORD_MISC_HYPERVISOR; break;
262 case PERF_CONTEXT_KERNEL:
263 cpumode = PERF_RECORD_MISC_KERNEL; break;
264 case PERF_CONTEXT_USER:
265 cpumode = PERF_RECORD_MISC_USER; break;
266 default:
267 break;
268 }
269 continue;
270 }
271
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800272 al.filtered = false;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200273 thread__find_addr_location(thread, self, cpumode,
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800274 MAP__FUNCTION, thread->pid, ip, &al, NULL);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200275 if (al.sym != NULL) {
276 if (sort__has_parent && !*parent &&
277 symbol__match_parent_regex(al.sym))
278 *parent = al.sym;
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200279 if (!symbol_conf.use_callchain)
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200280 break;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200281 }
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100282
283 err = callchain_cursor_append(&self->callchain_cursor,
284 ip, al.map, al.sym);
285 if (err)
286 return err;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200287 }
288
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100289 return 0;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200290}
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200291
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200292static int process_event_synth_stub(union perf_event *event __used,
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200293 struct perf_session *session __used)
294{
295 dump_printf(": unhandled!\n");
296 return 0;
297}
298
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300299static int process_event_sample_stub(union perf_event *event __used,
300 struct perf_sample *sample __used,
301 struct perf_evsel *evsel __used,
302 struct perf_session *session __used)
303{
304 dump_printf(": unhandled!\n");
305 return 0;
306}
307
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200308static int process_event_stub(union perf_event *event __used,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200309 struct perf_sample *sample __used,
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200310 struct perf_session *session __used)
311{
312 dump_printf(": unhandled!\n");
313 return 0;
314}
315
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200316static int process_finished_round_stub(union perf_event *event __used,
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +0200317 struct perf_session *session __used,
318 struct perf_event_ops *ops __used)
319{
320 dump_printf(": unhandled!\n");
321 return 0;
322}
323
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200324static int process_finished_round(union perf_event *event,
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +0200325 struct perf_session *session,
326 struct perf_event_ops *ops);
327
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200328static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
329{
Arnaldo Carvalho de Melo55aa6402009-12-27 21:37:05 -0200330 if (handler->sample == NULL)
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300331 handler->sample = process_event_sample_stub;
Arnaldo Carvalho de Melo55aa6402009-12-27 21:37:05 -0200332 if (handler->mmap == NULL)
333 handler->mmap = process_event_stub;
334 if (handler->comm == NULL)
335 handler->comm = process_event_stub;
336 if (handler->fork == NULL)
337 handler->fork = process_event_stub;
338 if (handler->exit == NULL)
339 handler->exit = process_event_stub;
340 if (handler->lost == NULL)
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200341 handler->lost = perf_event__process_lost;
Arnaldo Carvalho de Melo55aa6402009-12-27 21:37:05 -0200342 if (handler->read == NULL)
343 handler->read = process_event_stub;
344 if (handler->throttle == NULL)
345 handler->throttle = process_event_stub;
346 if (handler->unthrottle == NULL)
347 handler->unthrottle = process_event_stub;
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500348 if (handler->attr == NULL)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200349 handler->attr = process_event_synth_stub;
Tom Zanussicd19a032010-04-01 23:59:20 -0500350 if (handler->event_type == NULL)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200351 handler->event_type = process_event_synth_stub;
Tom Zanussi92155452010-04-01 23:59:21 -0500352 if (handler->tracing_data == NULL)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200353 handler->tracing_data = process_event_synth_stub;
Tom Zanussic7929e42010-04-01 23:59:22 -0500354 if (handler->build_id == NULL)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200355 handler->build_id = process_event_synth_stub;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +0200356 if (handler->finished_round == NULL) {
357 if (handler->ordered_samples)
358 handler->finished_round = process_finished_round;
359 else
360 handler->finished_round = process_finished_round_stub;
361 }
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200362}
363
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200364void mem_bswap_64(void *src, int byte_size)
365{
366 u64 *m = src;
367
368 while (byte_size > 0) {
369 *m = bswap_64(*m);
370 byte_size -= sizeof(u64);
371 ++m;
372 }
373}
374
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200375static void perf_event__all64_swap(union perf_event *event)
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200376{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200377 struct perf_event_header *hdr = &event->header;
378 mem_bswap_64(hdr + 1, event->header.size - sizeof(*hdr));
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200379}
380
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200381static void perf_event__comm_swap(union perf_event *event)
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200382{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200383 event->comm.pid = bswap_32(event->comm.pid);
384 event->comm.tid = bswap_32(event->comm.tid);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200385}
386
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200387static void perf_event__mmap_swap(union perf_event *event)
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200388{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200389 event->mmap.pid = bswap_32(event->mmap.pid);
390 event->mmap.tid = bswap_32(event->mmap.tid);
391 event->mmap.start = bswap_64(event->mmap.start);
392 event->mmap.len = bswap_64(event->mmap.len);
393 event->mmap.pgoff = bswap_64(event->mmap.pgoff);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200394}
395
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200396static void perf_event__task_swap(union perf_event *event)
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200397{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200398 event->fork.pid = bswap_32(event->fork.pid);
399 event->fork.tid = bswap_32(event->fork.tid);
400 event->fork.ppid = bswap_32(event->fork.ppid);
401 event->fork.ptid = bswap_32(event->fork.ptid);
402 event->fork.time = bswap_64(event->fork.time);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200403}
404
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200405static void perf_event__read_swap(union perf_event *event)
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200406{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200407 event->read.pid = bswap_32(event->read.pid);
408 event->read.tid = bswap_32(event->read.tid);
409 event->read.value = bswap_64(event->read.value);
410 event->read.time_enabled = bswap_64(event->read.time_enabled);
411 event->read.time_running = bswap_64(event->read.time_running);
412 event->read.id = bswap_64(event->read.id);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200413}
414
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200415static void perf_event__attr_swap(union perf_event *event)
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500416{
417 size_t size;
418
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200419 event->attr.attr.type = bswap_32(event->attr.attr.type);
420 event->attr.attr.size = bswap_32(event->attr.attr.size);
421 event->attr.attr.config = bswap_64(event->attr.attr.config);
422 event->attr.attr.sample_period = bswap_64(event->attr.attr.sample_period);
423 event->attr.attr.sample_type = bswap_64(event->attr.attr.sample_type);
424 event->attr.attr.read_format = bswap_64(event->attr.attr.read_format);
425 event->attr.attr.wakeup_events = bswap_32(event->attr.attr.wakeup_events);
426 event->attr.attr.bp_type = bswap_32(event->attr.attr.bp_type);
427 event->attr.attr.bp_addr = bswap_64(event->attr.attr.bp_addr);
428 event->attr.attr.bp_len = bswap_64(event->attr.attr.bp_len);
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500429
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200430 size = event->header.size;
431 size -= (void *)&event->attr.id - (void *)event;
432 mem_bswap_64(event->attr.id, size);
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500433}
434
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200435static void perf_event__event_type_swap(union perf_event *event)
Tom Zanussicd19a032010-04-01 23:59:20 -0500436{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200437 event->event_type.event_type.event_id =
438 bswap_64(event->event_type.event_type.event_id);
Tom Zanussicd19a032010-04-01 23:59:20 -0500439}
440
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200441static void perf_event__tracing_data_swap(union perf_event *event)
Tom Zanussi92155452010-04-01 23:59:21 -0500442{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200443 event->tracing_data.size = bswap_32(event->tracing_data.size);
Tom Zanussi92155452010-04-01 23:59:21 -0500444}
445
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200446typedef void (*perf_event__swap_op)(union perf_event *event);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200447
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200448static perf_event__swap_op perf_event__swap_ops[] = {
449 [PERF_RECORD_MMAP] = perf_event__mmap_swap,
450 [PERF_RECORD_COMM] = perf_event__comm_swap,
451 [PERF_RECORD_FORK] = perf_event__task_swap,
452 [PERF_RECORD_EXIT] = perf_event__task_swap,
453 [PERF_RECORD_LOST] = perf_event__all64_swap,
454 [PERF_RECORD_READ] = perf_event__read_swap,
455 [PERF_RECORD_SAMPLE] = perf_event__all64_swap,
456 [PERF_RECORD_HEADER_ATTR] = perf_event__attr_swap,
457 [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap,
458 [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,
459 [PERF_RECORD_HEADER_BUILD_ID] = NULL,
460 [PERF_RECORD_HEADER_MAX] = NULL,
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200461};
462
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200463struct sample_queue {
464 u64 timestamp;
Thomas Gleixnere4c2df12010-12-07 12:48:50 +0000465 u64 file_offset;
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200466 union perf_event *event;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200467 struct list_head list;
468};
469
Thomas Gleixner020bb752010-11-30 17:49:53 +0000470static void perf_session_free_sample_buffers(struct perf_session *session)
471{
472 struct ordered_samples *os = &session->ordered_samples;
473
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000474 while (!list_empty(&os->to_free)) {
Thomas Gleixner020bb752010-11-30 17:49:53 +0000475 struct sample_queue *sq;
476
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000477 sq = list_entry(os->to_free.next, struct sample_queue, list);
Thomas Gleixner020bb752010-11-30 17:49:53 +0000478 list_del(&sq->list);
479 free(sq);
480 }
481}
482
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100483static int perf_session_deliver_event(struct perf_session *session,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200484 union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200485 struct perf_sample *sample,
Thomas Gleixnerf74725d2010-12-07 12:48:53 +0000486 struct perf_event_ops *ops,
487 u64 file_offset);
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100488
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200489static void flush_sample_queue(struct perf_session *s,
490 struct perf_event_ops *ops)
491{
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000492 struct ordered_samples *os = &s->ordered_samples;
493 struct list_head *head = &os->samples;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200494 struct sample_queue *tmp, *iter;
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200495 struct perf_sample sample;
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000496 u64 limit = os->next_flush;
497 u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL;
Frederic Weisbecker5538bec2011-05-22 02:17:22 +0200498 int ret;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200499
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +0200500 if (!ops->ordered_samples || !limit)
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200501 return;
502
503 list_for_each_entry_safe(iter, tmp, head, list) {
504 if (iter->timestamp > limit)
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000505 break;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200506
Frederic Weisbecker5538bec2011-05-22 02:17:22 +0200507 ret = perf_session__parse_sample(s, iter->event, &sample);
508 if (ret)
509 pr_err("Can't parse sample, err = %d\n", ret);
510 else
511 perf_session_deliver_event(s, iter->event, &sample, ops,
512 iter->file_offset);
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200513
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000514 os->last_flush = iter->timestamp;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200515 list_del(&iter->list);
Thomas Gleixner020bb752010-11-30 17:49:53 +0000516 list_add(&iter->list, &os->sample_cache);
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200517 }
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000518
519 if (list_empty(head)) {
520 os->last_sample = NULL;
521 } else if (last_ts <= limit) {
522 os->last_sample =
523 list_entry(head->prev, struct sample_queue, list);
524 }
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200525}
526
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +0200527/*
528 * When perf record finishes a pass on every buffers, it records this pseudo
529 * event.
530 * We record the max timestamp t found in the pass n.
531 * Assuming these timestamps are monotonic across cpus, we know that if
532 * a buffer still has events with timestamps below t, they will be all
533 * available and then read in the pass n + 1.
534 * Hence when we start to read the pass n + 2, we can safely flush every
535 * events with timestamps below t.
536 *
537 * ============ PASS n =================
538 * CPU 0 | CPU 1
539 * |
540 * cnt1 timestamps | cnt2 timestamps
541 * 1 | 2
542 * 2 | 3
543 * - | 4 <--- max recorded
544 *
545 * ============ PASS n + 1 ==============
546 * CPU 0 | CPU 1
547 * |
548 * cnt1 timestamps | cnt2 timestamps
549 * 3 | 5
550 * 4 | 6
551 * 5 | 7 <---- max recorded
552 *
553 * Flush every events below timestamp 4
554 *
555 * ============ PASS n + 2 ==============
556 * CPU 0 | CPU 1
557 * |
558 * cnt1 timestamps | cnt2 timestamps
559 * 6 | 8
560 * 7 | 9
561 * - | 10
562 *
563 * Flush every events below timestamp 7
564 * etc...
565 */
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200566static int process_finished_round(union perf_event *event __used,
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +0200567 struct perf_session *session,
568 struct perf_event_ops *ops)
569{
570 flush_sample_queue(session, ops);
571 session->ordered_samples.next_flush = session->ordered_samples.max_timestamp;
572
573 return 0;
574}
575
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200576/* The queue is ordered by time */
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100577static void __queue_event(struct sample_queue *new, struct perf_session *s)
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200578{
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000579 struct ordered_samples *os = &s->ordered_samples;
580 struct sample_queue *sample = os->last_sample;
581 u64 timestamp = new->timestamp;
582 struct list_head *p;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200583
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000584 os->last_sample = new;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200585
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000586 if (!sample) {
587 list_add(&new->list, &os->samples);
588 os->max_timestamp = timestamp;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200589 return;
590 }
591
592 /*
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000593 * last_sample might point to some random place in the list as it's
594 * the last queued event. We expect that the new event is close to
595 * this.
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200596 */
Thomas Gleixnera1225de2010-11-30 17:49:33 +0000597 if (sample->timestamp <= timestamp) {
598 while (sample->timestamp <= timestamp) {
599 p = sample->list.next;
600 if (p == &os->samples) {
601 list_add_tail(&new->list, &os->samples);
602 os->max_timestamp = timestamp;
603 return;
604 }
605 sample = list_entry(p, struct sample_queue, list);
606 }
607 list_add_tail(&new->list, &sample->list);
608 } else {
609 while (sample->timestamp > timestamp) {
610 p = sample->list.prev;
611 if (p == &os->samples) {
612 list_add(&new->list, &os->samples);
613 return;
614 }
615 sample = list_entry(p, struct sample_queue, list);
616 }
617 list_add(&new->list, &sample->list);
618 }
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200619}
620
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000621#define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct sample_queue))
622
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200623static int perf_session_queue_event(struct perf_session *s, union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200624 struct perf_sample *sample, u64 file_offset)
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200625{
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000626 struct ordered_samples *os = &s->ordered_samples;
627 struct list_head *sc = &os->sample_cache;
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200628 u64 timestamp = sample->time;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200629 struct sample_queue *new;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200630
Thomas Gleixner79a14c12010-12-07 12:48:44 +0000631 if (!timestamp || timestamp == ~0ULL)
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100632 return -ETIME;
633
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200634 if (timestamp < s->ordered_samples.last_flush) {
635 printf("Warning: Timestamp below last timeslice flush\n");
636 return -EINVAL;
637 }
638
Thomas Gleixner020bb752010-11-30 17:49:53 +0000639 if (!list_empty(sc)) {
640 new = list_entry(sc->next, struct sample_queue, list);
641 list_del(&new->list);
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000642 } else if (os->sample_buffer) {
643 new = os->sample_buffer + os->sample_buffer_idx;
644 if (++os->sample_buffer_idx == MAX_SAMPLE_BUFFER)
645 os->sample_buffer = NULL;
Thomas Gleixner020bb752010-11-30 17:49:53 +0000646 } else {
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000647 os->sample_buffer = malloc(MAX_SAMPLE_BUFFER * sizeof(*new));
648 if (!os->sample_buffer)
Thomas Gleixner020bb752010-11-30 17:49:53 +0000649 return -ENOMEM;
Thomas Gleixner5c891f32010-11-30 17:49:55 +0000650 list_add(&os->sample_buffer->list, &os->to_free);
651 os->sample_buffer_idx = 2;
652 new = os->sample_buffer + 1;
Thomas Gleixner020bb752010-11-30 17:49:53 +0000653 }
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200654
655 new->timestamp = timestamp;
Thomas Gleixnere4c2df12010-12-07 12:48:50 +0000656 new->file_offset = file_offset;
Thomas Gleixnerfe174202010-11-30 17:49:49 +0000657 new->event = event;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200658
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100659 __queue_event(new, s);
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200660
661 return 0;
662}
663
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200664static void callchain__printf(struct perf_sample *sample)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200665{
666 unsigned int i;
667
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200668 printf("... chain: nr:%" PRIu64 "\n", sample->callchain->nr);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200669
670 for (i = 0; i < sample->callchain->nr; i++)
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200671 printf("..... %2d: %016" PRIx64 "\n",
672 i, sample->callchain->ips[i]);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200673}
674
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200675static void perf_session__print_tstamp(struct perf_session *session,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200676 union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200677 struct perf_sample *sample)
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200678{
679 if (event->header.type != PERF_RECORD_SAMPLE &&
680 !session->sample_id_all) {
681 fputs("-1 -1 ", stdout);
682 return;
683 }
684
685 if ((session->sample_type & PERF_SAMPLE_CPU))
686 printf("%u ", sample->cpu);
687
688 if (session->sample_type & PERF_SAMPLE_TIME)
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200689 printf("%" PRIu64 " ", sample->time);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200690}
691
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200692static void dump_event(struct perf_session *session, union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200693 u64 file_offset, struct perf_sample *sample)
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000694{
695 if (!dump_trace)
696 return;
697
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200698 printf("\n%#" PRIx64 " [%#x]: event: %d\n",
699 file_offset, event->header.size, event->header.type);
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000700
701 trace_event(event);
702
703 if (sample)
704 perf_session__print_tstamp(session, event, sample);
705
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200706 printf("%#" PRIx64 " [%#x]: PERF_RECORD_%s", file_offset,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200707 event->header.size, perf_event__name(event->header.type));
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000708}
709
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200710static void dump_sample(struct perf_session *session, union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200711 struct perf_sample *sample)
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000712{
Arnaldo Carvalho de Meloddbc24b2010-12-09 12:20:20 -0200713 if (!dump_trace)
714 return;
715
David Ahern7cec0922011-05-30 13:08:23 -0600716 printf("(IP, %d): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRIx64 "\n",
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200717 event->header.misc, sample->pid, sample->tid, sample->ip,
David Ahern7cec0922011-05-30 13:08:23 -0600718 sample->period, sample->addr);
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000719
720 if (session->sample_type & PERF_SAMPLE_CALLCHAIN)
Arnaldo Carvalho de Meloddbc24b2010-12-09 12:20:20 -0200721 callchain__printf(sample);
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000722}
723
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100724static int perf_session_deliver_event(struct perf_session *session,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200725 union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200726 struct perf_sample *sample,
Thomas Gleixnerf74725d2010-12-07 12:48:53 +0000727 struct perf_event_ops *ops,
Thomas Gleixner532e7262010-12-07 12:48:55 +0000728 u64 file_offset)
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100729{
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300730 struct perf_evsel *evsel;
731
Thomas Gleixner532e7262010-12-07 12:48:55 +0000732 dump_event(session, event, file_offset, sample);
733
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100734 switch (event->header.type) {
735 case PERF_RECORD_SAMPLE:
Thomas Gleixner532e7262010-12-07 12:48:55 +0000736 dump_sample(session, event, sample);
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300737 evsel = perf_evlist__id2evsel(session->evlist, sample->id);
738 if (evsel == NULL) {
739 ++session->hists.stats.nr_unknown_id;
740 return -1;
741 }
742 return ops->sample(event, sample, evsel, session);
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100743 case PERF_RECORD_MMAP:
744 return ops->mmap(event, sample, session);
745 case PERF_RECORD_COMM:
746 return ops->comm(event, sample, session);
747 case PERF_RECORD_FORK:
748 return ops->fork(event, sample, session);
749 case PERF_RECORD_EXIT:
750 return ops->exit(event, sample, session);
751 case PERF_RECORD_LOST:
752 return ops->lost(event, sample, session);
753 case PERF_RECORD_READ:
754 return ops->read(event, sample, session);
755 case PERF_RECORD_THROTTLE:
756 return ops->throttle(event, sample, session);
757 case PERF_RECORD_UNTHROTTLE:
758 return ops->unthrottle(event, sample, session);
759 default:
760 ++session->hists.stats.nr_unknown_events;
761 return -1;
762 }
763}
764
Thomas Gleixner3dfc2c02010-12-07 12:48:58 +0000765static int perf_session__preprocess_sample(struct perf_session *session,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200766 union perf_event *event, struct perf_sample *sample)
Thomas Gleixner3dfc2c02010-12-07 12:48:58 +0000767{
768 if (event->header.type != PERF_RECORD_SAMPLE ||
769 !(session->sample_type & PERF_SAMPLE_CALLCHAIN))
770 return 0;
771
772 if (!ip_callchain__valid(sample->callchain, event)) {
773 pr_debug("call-chain problem with event, skipping it.\n");
774 ++session->hists.stats.nr_invalid_chains;
775 session->hists.stats.total_invalid_chains += sample->period;
776 return -EINVAL;
777 }
778 return 0;
779}
780
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200781static int perf_session__process_user_event(struct perf_session *session, union perf_event *event,
Thomas Gleixnerba74f062010-12-07 12:49:01 +0000782 struct perf_event_ops *ops, u64 file_offset)
783{
784 dump_event(session, event, file_offset, NULL);
785
786 /* These events are processed right away */
787 switch (event->header.type) {
788 case PERF_RECORD_HEADER_ATTR:
789 return ops->attr(event, session);
790 case PERF_RECORD_HEADER_EVENT_TYPE:
791 return ops->event_type(event, session);
792 case PERF_RECORD_HEADER_TRACING_DATA:
793 /* setup for reading amidst mmap */
794 lseek(session->fd, file_offset, SEEK_SET);
795 return ops->tracing_data(event, session);
796 case PERF_RECORD_HEADER_BUILD_ID:
797 return ops->build_id(event, session);
798 case PERF_RECORD_FINISHED_ROUND:
799 return ops->finished_round(event, session, ops);
800 default:
801 return -EINVAL;
802 }
803}
804
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100805static int perf_session__process_event(struct perf_session *session,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200806 union perf_event *event,
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200807 struct perf_event_ops *ops,
Thomas Gleixner0331ee02010-11-30 17:49:38 +0000808 u64 file_offset)
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200809{
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200810 struct perf_sample sample;
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100811 int ret;
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200812
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200813 if (session->header.needs_swap &&
814 perf_event__swap_ops[event->header.type])
815 perf_event__swap_ops[event->header.type](event);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200816
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000817 if (event->header.type >= PERF_RECORD_HEADER_MAX)
818 return -EINVAL;
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200819
Thomas Gleixner9aefcab02010-12-07 12:48:47 +0000820 hists__inc_nr_events(&session->hists, event->header.type);
821
822 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
Thomas Gleixnerba74f062010-12-07 12:49:01 +0000823 return perf_session__process_user_event(session, event, ops, file_offset);
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100824
Thomas Gleixner3dfc2c02010-12-07 12:48:58 +0000825 /*
826 * For all kernel events we get the sample data
827 */
Frederic Weisbecker5538bec2011-05-22 02:17:22 +0200828 ret = perf_session__parse_sample(session, event, &sample);
829 if (ret)
830 return ret;
Thomas Gleixner3dfc2c02010-12-07 12:48:58 +0000831
832 /* Preprocess sample records - precheck callchains */
833 if (perf_session__preprocess_sample(session, event, &sample))
834 return 0;
835
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100836 if (ops->ordered_samples) {
Thomas Gleixnere4c2df12010-12-07 12:48:50 +0000837 ret = perf_session_queue_event(session, event, &sample,
838 file_offset);
Thomas Gleixnercbf41642010-12-05 14:32:55 +0100839 if (ret != -ETIME)
840 return ret;
841 }
842
Thomas Gleixnerf74725d2010-12-07 12:48:53 +0000843 return perf_session_deliver_event(session, event, &sample, ops,
844 file_offset);
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200845}
846
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200847void perf_event_header__bswap(struct perf_event_header *self)
848{
849 self->type = bswap_32(self->type);
850 self->misc = bswap_16(self->misc);
851 self->size = bswap_16(self->size);
852}
853
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -0200854static struct thread *perf_session__register_idle_thread(struct perf_session *self)
855{
856 struct thread *thread = perf_session__findnew(self, 0);
857
858 if (thread == NULL || thread__set_comm(thread, "swapper")) {
859 pr_err("problem inserting idle task.\n");
860 thread = NULL;
861 }
862
863 return thread;
864}
865
Arnaldo Carvalho de Melo11095992011-01-04 16:25:15 -0200866static void perf_session__warn_about_errors(const struct perf_session *session,
867 const struct perf_event_ops *ops)
868{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200869 if (ops->lost == perf_event__process_lost &&
Arnaldo Carvalho de Melo11095992011-01-04 16:25:15 -0200870 session->hists.stats.total_lost != 0) {
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200871 ui__warning("Processed %" PRIu64 " events and LOST %" PRIu64
872 "!\n\nCheck IO/CPU overload!\n\n",
Arnaldo Carvalho de Melo11095992011-01-04 16:25:15 -0200873 session->hists.stats.total_period,
874 session->hists.stats.total_lost);
875 }
876
877 if (session->hists.stats.nr_unknown_events != 0) {
878 ui__warning("Found %u unknown events!\n\n"
879 "Is this an older tool processing a perf.data "
880 "file generated by a more recent tool?\n\n"
881 "If that is not the case, consider "
882 "reporting to linux-kernel@vger.kernel.org.\n\n",
883 session->hists.stats.nr_unknown_events);
884 }
885
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300886 if (session->hists.stats.nr_unknown_id != 0) {
887 ui__warning("%u samples with id not present in the header\n",
888 session->hists.stats.nr_unknown_id);
889 }
890
Arnaldo Carvalho de Melo11095992011-01-04 16:25:15 -0200891 if (session->hists.stats.nr_invalid_chains != 0) {
892 ui__warning("Found invalid callchains!\n\n"
893 "%u out of %u events were discarded for this reason.\n\n"
894 "Consider reporting to linux-kernel@vger.kernel.org.\n\n",
895 session->hists.stats.nr_invalid_chains,
896 session->hists.stats.nr_events[PERF_RECORD_SAMPLE]);
897 }
898}
899
Tom Zanussi8dc58102010-04-01 23:59:15 -0500900#define session_done() (*(volatile int *)(&session_done))
901volatile int session_done;
902
903static int __perf_session__process_pipe_events(struct perf_session *self,
904 struct perf_event_ops *ops)
905{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200906 union perf_event event;
Tom Zanussi8dc58102010-04-01 23:59:15 -0500907 uint32_t size;
908 int skip = 0;
909 u64 head;
910 int err;
911 void *p;
912
913 perf_event_ops__fill_defaults(ops);
914
915 head = 0;
916more:
Arnaldo Carvalho de Melo1e7972c2011-01-03 16:50:55 -0200917 err = readn(self->fd, &event, sizeof(struct perf_event_header));
Tom Zanussi8dc58102010-04-01 23:59:15 -0500918 if (err <= 0) {
919 if (err == 0)
920 goto done;
921
922 pr_err("failed to read event header\n");
923 goto out_err;
924 }
925
926 if (self->header.needs_swap)
927 perf_event_header__bswap(&event.header);
928
929 size = event.header.size;
930 if (size == 0)
931 size = 8;
932
933 p = &event;
934 p += sizeof(struct perf_event_header);
935
Tom Zanussi794e43b2010-05-05 00:27:40 -0500936 if (size - sizeof(struct perf_event_header)) {
Arnaldo Carvalho de Melo1e7972c2011-01-03 16:50:55 -0200937 err = readn(self->fd, p, size - sizeof(struct perf_event_header));
Tom Zanussi794e43b2010-05-05 00:27:40 -0500938 if (err <= 0) {
939 if (err == 0) {
940 pr_err("unexpected end of event stream\n");
941 goto done;
942 }
Tom Zanussi8dc58102010-04-01 23:59:15 -0500943
Tom Zanussi794e43b2010-05-05 00:27:40 -0500944 pr_err("failed to read event data\n");
945 goto out_err;
946 }
Tom Zanussi8dc58102010-04-01 23:59:15 -0500947 }
948
949 if (size == 0 ||
Thomas Gleixner0331ee02010-11-30 17:49:38 +0000950 (skip = perf_session__process_event(self, &event, ops, head)) < 0) {
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200951 dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n",
Tom Zanussi8dc58102010-04-01 23:59:15 -0500952 head, event.header.size, event.header.type);
953 /*
954 * assume we lost track of the stream, check alignment, and
955 * increment a single u64 in the hope to catch on again 'soon'.
956 */
957 if (unlikely(head & 7))
958 head &= ~7ULL;
959
960 size = 8;
961 }
962
963 head += size;
964
Tom Zanussi8dc58102010-04-01 23:59:15 -0500965 if (skip > 0)
966 head += skip;
967
968 if (!session_done())
969 goto more;
970done:
971 err = 0;
972out_err:
Arnaldo Carvalho de Melo11095992011-01-04 16:25:15 -0200973 perf_session__warn_about_errors(self, ops);
Thomas Gleixner020bb752010-11-30 17:49:53 +0000974 perf_session_free_sample_buffers(self);
Tom Zanussi8dc58102010-04-01 23:59:15 -0500975 return err;
976}
977
Frederic Weisbecker998bedc2011-05-23 13:06:28 +0200978static union perf_event *
979fetch_mmaped_event(struct perf_session *session,
980 u64 head, size_t mmap_size, char *buf)
981{
982 union perf_event *event;
983
984 /*
985 * Ensure we have enough space remaining to read
986 * the size of the event in the headers.
987 */
988 if (head + sizeof(event->header) > mmap_size)
989 return NULL;
990
991 event = (union perf_event *)(buf + head);
992
993 if (session->header.needs_swap)
994 perf_event_header__bswap(&event->header);
995
996 if (head + event->header.size > mmap_size)
997 return NULL;
998
999 return event;
1000}
1001
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001002int __perf_session__process_events(struct perf_session *session,
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -02001003 u64 data_offset, u64 data_size,
1004 u64 file_size, struct perf_event_ops *ops)
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001005{
Thomas Gleixner55b446292010-11-30 17:49:46 +00001006 u64 head, page_offset, file_offset, file_pos, progress_next;
Thomas Gleixnerfe174202010-11-30 17:49:49 +00001007 int err, mmap_prot, mmap_flags, map_idx = 0;
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001008 struct ui_progress *progress;
Thomas Gleixner55b446292010-11-30 17:49:46 +00001009 size_t page_size, mmap_size;
Thomas Gleixnerfe174202010-11-30 17:49:49 +00001010 char *buf, *mmaps[8];
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -02001011 union perf_event *event;
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001012 uint32_t size;
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001013
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001014 perf_event_ops__fill_defaults(ops);
1015
Arnaldo Carvalho de Melo1b759622010-01-14 18:30:04 -02001016 page_size = sysconf(_SC_PAGESIZE);
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001017
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001018 page_offset = page_size * (data_offset / page_size);
1019 file_offset = page_offset;
1020 head = data_offset - page_offset;
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001021
Thomas Gleixnerd6513282010-11-30 17:49:44 +00001022 if (data_offset + data_size < file_size)
1023 file_size = data_offset + data_size;
1024
Thomas Gleixner55b446292010-11-30 17:49:46 +00001025 progress_next = file_size / 16;
1026 progress = ui_progress__new("Processing events...", file_size);
1027 if (progress == NULL)
1028 return -1;
1029
1030 mmap_size = session->mmap_window;
1031 if (mmap_size > file_size)
1032 mmap_size = file_size;
1033
Thomas Gleixnerfe174202010-11-30 17:49:49 +00001034 memset(mmaps, 0, sizeof(mmaps));
1035
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -02001036 mmap_prot = PROT_READ;
1037 mmap_flags = MAP_SHARED;
1038
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001039 if (session->header.needs_swap) {
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -02001040 mmap_prot |= PROT_WRITE;
1041 mmap_flags = MAP_PRIVATE;
1042 }
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001043remap:
Thomas Gleixner55b446292010-11-30 17:49:46 +00001044 buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, session->fd,
1045 file_offset);
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001046 if (buf == MAP_FAILED) {
1047 pr_err("failed to mmap file\n");
1048 err = -errno;
1049 goto out_err;
1050 }
Thomas Gleixnerfe174202010-11-30 17:49:49 +00001051 mmaps[map_idx] = buf;
1052 map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1);
Thomas Gleixnerd6513282010-11-30 17:49:44 +00001053 file_pos = file_offset + head;
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001054
1055more:
Frederic Weisbecker998bedc2011-05-23 13:06:28 +02001056 event = fetch_mmaped_event(session, head, mmap_size, buf);
1057 if (!event) {
Thomas Gleixnerfe174202010-11-30 17:49:49 +00001058 if (mmaps[map_idx]) {
1059 munmap(mmaps[map_idx], mmap_size);
1060 mmaps[map_idx] = NULL;
1061 }
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001062
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001063 page_offset = page_size * (head / page_size);
1064 file_offset += page_offset;
1065 head -= page_offset;
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001066 goto remap;
1067 }
1068
1069 size = event->header.size;
1070
Thomas Gleixnerd6513282010-11-30 17:49:44 +00001071 if (size == 0 ||
1072 perf_session__process_event(session, event, ops, file_pos) < 0) {
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -02001073 dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n",
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001074 file_offset + head, event->header.size,
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001075 event->header.type);
1076 /*
1077 * assume we lost track of the stream, check alignment, and
1078 * increment a single u64 in the hope to catch on again 'soon'.
1079 */
1080 if (unlikely(head & 7))
1081 head &= ~7ULL;
1082
1083 size = 8;
1084 }
1085
1086 head += size;
Thomas Gleixnerd6513282010-11-30 17:49:44 +00001087 file_pos += size;
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001088
Thomas Gleixner55b446292010-11-30 17:49:46 +00001089 if (file_pos >= progress_next) {
1090 progress_next += file_size / 16;
1091 ui_progress__update(progress, file_pos);
1092 }
1093
Thomas Gleixnerd6513282010-11-30 17:49:44 +00001094 if (file_pos < file_size)
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001095 goto more;
Thomas Gleixnerd6513282010-11-30 17:49:44 +00001096
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001097 err = 0;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +02001098 /* do the final flush for ordered samples */
Thomas Gleixner0331ee02010-11-30 17:49:38 +00001099 session->ordered_samples.next_flush = ULLONG_MAX;
1100 flush_sample_queue(session, ops);
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001101out_err:
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -03001102 ui_progress__delete(progress);
Arnaldo Carvalho de Melo11095992011-01-04 16:25:15 -02001103 perf_session__warn_about_errors(session, ops);
Thomas Gleixner020bb752010-11-30 17:49:53 +00001104 perf_session_free_sample_buffers(session);
Arnaldo Carvalho de Melo06aae5902009-12-27 21:36:59 -02001105 return err;
1106}
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -02001107
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -02001108int perf_session__process_events(struct perf_session *self,
1109 struct perf_event_ops *ops)
1110{
1111 int err;
1112
1113 if (perf_session__register_idle_thread(self) == NULL)
1114 return -ENOMEM;
1115
Tom Zanussi8dc58102010-04-01 23:59:15 -05001116 if (!self->fd_pipe)
1117 err = __perf_session__process_events(self,
1118 self->header.data_offset,
1119 self->header.data_size,
1120 self->size, ops);
1121 else
1122 err = __perf_session__process_pipe_events(self, ops);
Dave Martin88ca8952010-07-27 11:46:12 -03001123
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -02001124 return err;
1125}
1126
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -02001127bool perf_session__has_traces(struct perf_session *self, const char *msg)
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -02001128{
1129 if (!(self->sample_type & PERF_SAMPLE_RAW)) {
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -02001130 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg);
1131 return false;
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -02001132 }
1133
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -02001134 return true;
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -02001135}
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -02001136
Zhang, Yanmina1645ce2010-04-19 13:32:50 +08001137int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -02001138 const char *symbol_name,
1139 u64 addr)
1140{
1141 char *bracket;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -02001142 enum map_type i;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +08001143 struct ref_reloc_sym *ref;
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -02001144
Zhang, Yanmina1645ce2010-04-19 13:32:50 +08001145 ref = zalloc(sizeof(struct ref_reloc_sym));
1146 if (ref == NULL)
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -02001147 return -ENOMEM;
1148
Zhang, Yanmina1645ce2010-04-19 13:32:50 +08001149 ref->name = strdup(symbol_name);
1150 if (ref->name == NULL) {
1151 free(ref);
1152 return -ENOMEM;
1153 }
1154
1155 bracket = strchr(ref->name, ']');
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -02001156 if (bracket)
1157 *bracket = '\0';
1158
Zhang, Yanmina1645ce2010-04-19 13:32:50 +08001159 ref->addr = addr;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -02001160
1161 for (i = 0; i < MAP__NR_TYPES; ++i) {
Zhang, Yanmina1645ce2010-04-19 13:32:50 +08001162 struct kmap *kmap = map__kmap(maps[i]);
1163 kmap->ref_reloc_sym = ref;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -02001164 }
1165
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -02001166 return 0;
1167}
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -03001168
1169size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
1170{
1171 return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) +
1172 __dsos__fprintf(&self->host_machine.user_dsos, fp) +
1173 machines__fprintf_dsos(&self->machines, fp);
1174}
Arnaldo Carvalho de Melof8690972010-05-19 13:41:23 -03001175
1176size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
1177 bool with_hits)
1178{
1179 size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits);
1180 return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
1181}
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -03001182
1183size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
1184{
1185 struct perf_evsel *pos;
1186 size_t ret = fprintf(fp, "Aggregated stats:\n");
1187
1188 ret += hists__fprintf_nr_events(&session->hists, fp);
1189
1190 list_for_each_entry(pos, &session->evlist->entries, node) {
1191 ret += fprintf(fp, "%s stats:\n", event_name(pos));
1192 ret += hists__fprintf_nr_events(&pos->hists, fp);
1193 }
1194
1195 return ret;
1196}
David Ahernc0230b22011-03-09 22:23:27 -07001197
David Ahern9cbdb702011-04-06 21:54:20 -06001198struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
1199 unsigned int type)
1200{
1201 struct perf_evsel *pos;
1202
1203 list_for_each_entry(pos, &session->evlist->entries, node) {
1204 if (pos->attr.type == type)
1205 return pos;
1206 }
1207 return NULL;
1208}
1209
David Ahern787bef12011-05-27 14:28:43 -06001210void perf_session__print_ip(union perf_event *event,
1211 struct perf_sample *sample,
1212 struct perf_session *session,
David Ahern610723f2011-05-27 14:28:44 -06001213 int print_sym, int print_dso)
David Ahernc0230b22011-03-09 22:23:27 -07001214{
1215 struct addr_location al;
1216 const char *symname, *dsoname;
1217 struct callchain_cursor *cursor = &session->callchain_cursor;
1218 struct callchain_cursor_node *node;
1219
1220 if (perf_event__preprocess_sample(event, session, &al, sample,
1221 NULL) < 0) {
1222 error("problem processing %d event, skipping it.\n",
1223 event->header.type);
1224 return;
1225 }
1226
1227 if (symbol_conf.use_callchain && sample->callchain) {
1228
1229 if (perf_session__resolve_callchain(session, al.thread,
1230 sample->callchain, NULL) != 0) {
1231 if (verbose)
1232 error("Failed to resolve callchain. Skipping\n");
1233 return;
1234 }
1235 callchain_cursor_commit(cursor);
1236
1237 while (1) {
1238 node = callchain_cursor_current(cursor);
1239 if (!node)
1240 break;
1241
David Ahern787bef12011-05-27 14:28:43 -06001242 printf("\t%16" PRIx64, node->ip);
1243 if (print_sym) {
1244 if (node->sym && node->sym->name)
1245 symname = node->sym->name;
1246 else
1247 symname = "";
David Ahernc0230b22011-03-09 22:23:27 -07001248
David Ahern610723f2011-05-27 14:28:44 -06001249 printf(" %s", symname);
1250 }
1251 if (print_dso) {
David Ahern787bef12011-05-27 14:28:43 -06001252 if (node->map && node->map->dso && node->map->dso->name)
1253 dsoname = node->map->dso->name;
1254 else
1255 dsoname = "";
David Ahernc0230b22011-03-09 22:23:27 -07001256
David Ahern610723f2011-05-27 14:28:44 -06001257 printf(" (%s)", dsoname);
David Ahern787bef12011-05-27 14:28:43 -06001258 }
1259 printf("\n");
David Ahernc0230b22011-03-09 22:23:27 -07001260
1261 callchain_cursor_advance(cursor);
1262 }
1263
1264 } else {
David Ahern787bef12011-05-27 14:28:43 -06001265 printf("%16" PRIx64, al.addr);
1266 if (print_sym) {
1267 if (al.sym && al.sym->name)
1268 symname = al.sym->name;
1269 else
1270 symname = "";
David Ahernc0230b22011-03-09 22:23:27 -07001271
David Ahern610723f2011-05-27 14:28:44 -06001272 printf(" %s", symname);
1273 }
1274
1275 if (print_dso) {
David Ahern787bef12011-05-27 14:28:43 -06001276 if (al.map && al.map->dso && al.map->dso->name)
1277 dsoname = al.map->dso->name;
1278 else
1279 dsoname = "";
David Ahernc0230b22011-03-09 22:23:27 -07001280
David Ahern610723f2011-05-27 14:28:44 -06001281 printf(" (%s)", dsoname);
David Ahern787bef12011-05-27 14:28:43 -06001282 }
David Ahernc0230b22011-03-09 22:23:27 -07001283 }
1284}