perf: Fix performance issue with perf report
[deliverable/linux.git] / tools / perf / util / event.c
CommitLineData
234fbbf5
ACM
1#include <linux/types.h>
2#include "event.h"
3#include "debug.h"
ec913369 4#include "session.h"
c410a338 5#include "sort.h"
234fbbf5 6#include "string.h"
c410a338 7#include "strlist.h"
62daacb5 8#include "thread.h"
234fbbf5
ACM
9
10static pid_t event__synthesize_comm(pid_t pid, int full,
cf553114 11 event__handler_t process,
d8f66248 12 struct perf_session *session)
234fbbf5
ACM
13{
14 event_t ev;
15 char filename[PATH_MAX];
16 char bf[BUFSIZ];
17 FILE *fp;
18 size_t size = 0;
19 DIR *tasks;
20 struct dirent dirent, *next;
21 pid_t tgid = 0;
22
23 snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
24
25 fp = fopen(filename, "r");
26 if (fp == NULL) {
27out_race:
28 /*
29 * We raced with a task exiting - just return:
30 */
31 pr_debug("couldn't open %s\n", filename);
32 return 0;
33 }
34
35 memset(&ev.comm, 0, sizeof(ev.comm));
36 while (!ev.comm.comm[0] || !ev.comm.pid) {
37 if (fgets(bf, sizeof(bf), fp) == NULL)
38 goto out_failure;
39
40 if (memcmp(bf, "Name:", 5) == 0) {
41 char *name = bf + 5;
42 while (*name && isspace(*name))
43 ++name;
44 size = strlen(name) - 1;
45 memcpy(ev.comm.comm, name, size++);
46 } else if (memcmp(bf, "Tgid:", 5) == 0) {
47 char *tgids = bf + 5;
48 while (*tgids && isspace(*tgids))
49 ++tgids;
50 tgid = ev.comm.pid = atoi(tgids);
51 }
52 }
53
54 ev.comm.header.type = PERF_RECORD_COMM;
55 size = ALIGN(size, sizeof(u64));
56 ev.comm.header.size = sizeof(ev.comm) - (sizeof(ev.comm.comm) - size);
57
58 if (!full) {
59 ev.comm.tid = pid;
60
d8f66248 61 process(&ev, session);
234fbbf5
ACM
62 goto out_fclose;
63 }
64
65 snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
66
67 tasks = opendir(filename);
68 if (tasks == NULL)
69 goto out_race;
70
71 while (!readdir_r(tasks, &dirent, &next) && next) {
72 char *end;
73 pid = strtol(dirent.d_name, &end, 10);
74 if (*end)
75 continue;
76
77 ev.comm.tid = pid;
78
d8f66248 79 process(&ev, session);
234fbbf5
ACM
80 }
81 closedir(tasks);
82
83out_fclose:
84 fclose(fp);
85 return tgid;
86
87out_failure:
88 pr_warning("couldn't get COMM and pgid, malformed %s\n", filename);
89 return -1;
90}
91
92static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
cf553114 93 event__handler_t process,
d8f66248 94 struct perf_session *session)
234fbbf5
ACM
95{
96 char filename[PATH_MAX];
97 FILE *fp;
98
99 snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
100
101 fp = fopen(filename, "r");
102 if (fp == NULL) {
103 /*
104 * We raced with a task exiting - just return:
105 */
106 pr_debug("couldn't open %s\n", filename);
107 return -1;
108 }
109
110 while (1) {
111 char bf[BUFSIZ], *pbf = bf;
112 event_t ev = {
18c3daa4
ACM
113 .header = {
114 .type = PERF_RECORD_MMAP,
a1645ce1
ZY
115 /*
116 * Just like the kernel, see __perf_event_mmap
117 * in kernel/perf_event.c
118 */
119 .misc = PERF_RECORD_MISC_USER,
18c3daa4 120 },
234fbbf5
ACM
121 };
122 int n;
123 size_t size;
124 if (fgets(bf, sizeof(bf), fp) == NULL)
125 break;
126
127 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
128 n = hex2u64(pbf, &ev.mmap.start);
129 if (n < 0)
130 continue;
131 pbf += n + 1;
132 n = hex2u64(pbf, &ev.mmap.len);
133 if (n < 0)
134 continue;
135 pbf += n + 3;
136 if (*pbf == 'x') { /* vm_exec */
4af8b35d 137 u64 vm_pgoff;
234fbbf5
ACM
138 char *execname = strchr(bf, '/');
139
140 /* Catch VDSO */
141 if (execname == NULL)
142 execname = strstr(bf, "[vdso]");
143
144 if (execname == NULL)
145 continue;
146
4af8b35d
AB
147 pbf += 3;
148 n = hex2u64(pbf, &vm_pgoff);
149 /* pgoff is in bytes, not pages */
150 if (n >= 0)
151 ev.mmap.pgoff = vm_pgoff << getpagesize();
152 else
153 ev.mmap.pgoff = 0;
154
234fbbf5
ACM
155 size = strlen(execname);
156 execname[size - 1] = '\0'; /* Remove \n */
157 memcpy(ev.mmap.filename, execname, size);
158 size = ALIGN(size, sizeof(u64));
159 ev.mmap.len -= ev.mmap.start;
160 ev.mmap.header.size = (sizeof(ev.mmap) -
161 (sizeof(ev.mmap.filename) - size));
162 ev.mmap.pid = tgid;
163 ev.mmap.tid = pid;
164
d8f66248 165 process(&ev, session);
234fbbf5
ACM
166 }
167 }
168
169 fclose(fp);
170 return 0;
171}
172
b7cece76 173int event__synthesize_modules(event__handler_t process,
a1645ce1 174 struct perf_session *session,
23346f21 175 struct machine *machine)
b7cece76
ACM
176{
177 struct rb_node *nd;
23346f21 178 struct map_groups *kmaps = &machine->kmaps;
a1645ce1 179 u16 misc;
b7cece76 180
a1645ce1
ZY
181 /*
182 * kernel uses 0 for user space maps, see kernel/perf_event.c
183 * __perf_event_mmap
184 */
23346f21 185 if (machine__is_host(machine))
a1645ce1
ZY
186 misc = PERF_RECORD_MISC_KERNEL;
187 else
188 misc = PERF_RECORD_MISC_GUEST_KERNEL;
189
190 for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]);
b7cece76
ACM
191 nd; nd = rb_next(nd)) {
192 event_t ev;
193 size_t size;
194 struct map *pos = rb_entry(nd, struct map, rb_node);
195
196 if (pos->dso->kernel)
197 continue;
198
199 size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
200 memset(&ev, 0, sizeof(ev));
a1645ce1 201 ev.mmap.header.misc = misc;
b7cece76
ACM
202 ev.mmap.header.type = PERF_RECORD_MMAP;
203 ev.mmap.header.size = (sizeof(ev.mmap) -
204 (sizeof(ev.mmap.filename) - size));
205 ev.mmap.start = pos->start;
206 ev.mmap.len = pos->end - pos->start;
23346f21 207 ev.mmap.pid = machine->pid;
b7cece76
ACM
208
209 memcpy(ev.mmap.filename, pos->dso->long_name,
210 pos->dso->long_name_len + 1);
211 process(&ev, session);
212 }
213
214 return 0;
215}
216
cf553114 217int event__synthesize_thread(pid_t pid, event__handler_t process,
d8f66248 218 struct perf_session *session)
234fbbf5 219{
d8f66248 220 pid_t tgid = event__synthesize_comm(pid, 1, process, session);
234fbbf5
ACM
221 if (tgid == -1)
222 return -1;
d8f66248 223 return event__synthesize_mmap_events(pid, tgid, process, session);
234fbbf5
ACM
224}
225
cf553114 226void event__synthesize_threads(event__handler_t process,
d8f66248 227 struct perf_session *session)
234fbbf5
ACM
228{
229 DIR *proc;
230 struct dirent dirent, *next;
231
232 proc = opendir("/proc");
233
234 while (!readdir_r(proc, &dirent, &next) && next) {
235 char *end;
236 pid_t pid = strtol(dirent.d_name, &end, 10);
237
238 if (*end) /* only interested in proper numerical dirents */
239 continue;
240
d8f66248 241 event__synthesize_thread(pid, process, session);
234fbbf5
ACM
242 }
243
244 closedir(proc);
245}
62daacb5 246
56b03f3c
ACM
247struct process_symbol_args {
248 const char *name;
249 u64 start;
250};
251
252static int find_symbol_cb(void *arg, const char *name, char type, u64 start)
253{
254 struct process_symbol_args *args = arg;
255
881516eb
ACM
256 /*
257 * Must be a function or at least an alias, as in PARISC64, where "_text" is
258 * an 'A' to the same address as "_stext".
259 */
260 if (!(symbol_type__is_a(type, MAP__FUNCTION) ||
261 type == 'A') || strcmp(name, args->name))
56b03f3c
ACM
262 return 0;
263
264 args->start = start;
265 return 1;
266}
267
cf553114 268int event__synthesize_kernel_mmap(event__handler_t process,
56b03f3c 269 struct perf_session *session,
23346f21 270 struct machine *machine,
56b03f3c
ACM
271 const char *symbol_name)
272{
273 size_t size;
a1645ce1
ZY
274 const char *filename, *mmap_name;
275 char path[PATH_MAX];
276 char name_buff[PATH_MAX];
277 struct map *map;
278
56b03f3c 279 event_t ev = {
18c3daa4
ACM
280 .header = {
281 .type = PERF_RECORD_MMAP,
18c3daa4 282 },
56b03f3c
ACM
283 };
284 /*
285 * We should get this from /sys/kernel/sections/.text, but till that is
286 * available use this, and after it is use this as a fallback for older
287 * kernels.
288 */
289 struct process_symbol_args args = { .name = symbol_name, };
290
48ea8f54 291 mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
23346f21 292 if (machine__is_host(machine)) {
a1645ce1
ZY
293 /*
294 * kernel uses PERF_RECORD_MISC_USER for user space maps,
295 * see kernel/perf_event.c __perf_event_mmap
296 */
297 ev.header.misc = PERF_RECORD_MISC_KERNEL;
298 filename = "/proc/kallsyms";
299 } else {
300 ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
23346f21 301 if (machine__is_default_guest(machine))
a1645ce1
ZY
302 filename = (char *) symbol_conf.default_guest_kallsyms;
303 else {
23346f21 304 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
a1645ce1
ZY
305 filename = path;
306 }
307 }
308
309 if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0)
56b03f3c
ACM
310 return -ENOENT;
311
23346f21 312 map = machine->vmlinux_maps[MAP__FUNCTION];
56b03f3c 313 size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename),
a1645ce1 314 "%s%s", mmap_name, symbol_name) + 1;
56b03f3c 315 size = ALIGN(size, sizeof(u64));
a1645ce1
ZY
316 ev.mmap.header.size = (sizeof(ev.mmap) -
317 (sizeof(ev.mmap.filename) - size));
b7cece76 318 ev.mmap.pgoff = args.start;
a1645ce1
ZY
319 ev.mmap.start = map->start;
320 ev.mmap.len = map->end - ev.mmap.start;
23346f21 321 ev.mmap.pid = machine->pid;
56b03f3c
ACM
322
323 return process(&ev, session);
324}
325
d599db3f
ACM
326static void thread__comm_adjust(struct thread *self)
327{
328 char *comm = self->comm;
329
330 if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
331 (!symbol_conf.comm_list ||
332 strlist__has_entry(symbol_conf.comm_list, comm))) {
333 unsigned int slen = strlen(comm);
334
335 if (slen > comms__col_width) {
336 comms__col_width = slen;
337 threads__col_width = slen + 6;
338 }
339 }
340}
341
342static int thread__set_comm_adjust(struct thread *self, const char *comm)
343{
344 int ret = thread__set_comm(self, comm);
345
346 if (ret)
347 return ret;
348
349 thread__comm_adjust(self);
350
351 return 0;
352}
353
b3165f41 354int event__process_comm(event_t *self, struct perf_session *session)
62daacb5 355{
b3165f41 356 struct thread *thread = perf_session__findnew(session, self->comm.pid);
62daacb5 357
bab81b62 358 dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid);
62daacb5 359
d599db3f 360 if (thread == NULL || thread__set_comm_adjust(thread, self->comm.comm)) {
62daacb5
ACM
361 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
362 return -1;
363 }
364
365 return 0;
366}
367
f823e441 368int event__process_lost(event_t *self, struct perf_session *session)
62daacb5
ACM
369{
370 dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost);
f823e441 371 session->events_stats.lost += self->lost.lost;
62daacb5
ACM
372 return 0;
373}
374
a1645ce1
ZY
375static void event_set_kernel_mmap_len(struct map **maps, event_t *self)
376{
377 maps[MAP__FUNCTION]->start = self->mmap.start;
378 maps[MAP__FUNCTION]->end = self->mmap.start + self->mmap.len;
379 /*
380 * Be a bit paranoid here, some perf.data file came with
381 * a zero sized synthesized MMAP event for the kernel.
382 */
383 if (maps[MAP__FUNCTION]->end == 0)
384 maps[MAP__FUNCTION]->end = ~0UL;
385}
386
387static int event__process_kernel_mmap(event_t *self,
388 struct perf_session *session)
62daacb5 389{
56b03f3c 390 struct map *map;
a1645ce1 391 char kmmap_prefix[PATH_MAX];
23346f21 392 struct machine *machine;
a1645ce1
ZY
393 enum dso_kernel_type kernel_type;
394 bool is_kernel_mmap;
395
23346f21
ACM
396 machine = perf_session__findnew_machine(session, self->mmap.pid);
397 if (!machine) {
398 pr_err("Can't find id %d's machine\n", self->mmap.pid);
a1645ce1
ZY
399 goto out_problem;
400 }
62daacb5 401
48ea8f54 402 machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
23346f21 403 if (machine__is_host(machine))
a1645ce1
ZY
404 kernel_type = DSO_TYPE_KERNEL;
405 else
406 kernel_type = DSO_TYPE_GUEST_KERNEL;
62daacb5 407
a1645ce1
ZY
408 is_kernel_mmap = memcmp(self->mmap.filename,
409 kmmap_prefix,
410 strlen(kmmap_prefix)) == 0;
411 if (self->mmap.filename[0] == '/' ||
412 (!is_kernel_mmap && self->mmap.filename[0] == '[')) {
b7cece76 413
a1645ce1
ZY
414 char short_module_name[1024];
415 char *name, *dot;
b7cece76 416
a1645ce1
ZY
417 if (self->mmap.filename[0] == '/') {
418 name = strrchr(self->mmap.filename, '/');
b7cece76
ACM
419 if (name == NULL)
420 goto out_problem;
421
422 ++name; /* skip / */
423 dot = strrchr(name, '.');
424 if (dot == NULL)
425 goto out_problem;
b7cece76 426 snprintf(short_module_name, sizeof(short_module_name),
a1645ce1 427 "[%.*s]", (int)(dot - name), name);
b7cece76 428 strxfrchar(short_module_name, '-', '_');
a1645ce1
ZY
429 } else
430 strcpy(short_module_name, self->mmap.filename);
431
d28c6223
ACM
432 map = machine__new_module(machine, self->mmap.start,
433 self->mmap.filename);
a1645ce1
ZY
434 if (map == NULL)
435 goto out_problem;
436
437 name = strdup(short_module_name);
438 if (name == NULL)
439 goto out_problem;
440
441 map->dso->short_name = name;
442 map->end = map->start + self->mmap.len;
443 } else if (is_kernel_mmap) {
444 const char *symbol_name = (self->mmap.filename +
445 strlen(kmmap_prefix));
446 /*
447 * Should be there already, from the build-id table in
448 * the header.
449 */
23346f21
ACM
450 struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
451 kmmap_prefix);
a1645ce1
ZY
452 if (kernel == NULL)
453 goto out_problem;
454
455 kernel->kernel = kernel_type;
d28c6223 456 if (__machine__create_kernel_maps(machine, kernel) < 0)
a1645ce1
ZY
457 goto out_problem;
458
23346f21
ACM
459 event_set_kernel_mmap_len(machine->vmlinux_maps, self);
460 perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
461 symbol_name,
462 self->mmap.pgoff);
463 if (machine__is_default_guest(machine)) {
b7cece76 464 /*
a1645ce1 465 * preload dso of guest kernel and modules
b7cece76 466 */
23346f21
ACM
467 dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
468 NULL);
a1645ce1
ZY
469 }
470 }
471 return 0;
472out_problem:
473 return -1;
474}
b7cece76 475
a1645ce1
ZY
476int event__process_mmap(event_t *self, struct perf_session *session)
477{
23346f21 478 struct machine *machine;
a1645ce1
ZY
479 struct thread *thread;
480 struct map *map;
481 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
482 int ret = 0;
b7cece76 483
a1645ce1
ZY
484 dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n",
485 self->mmap.pid, self->mmap.tid, self->mmap.start,
486 self->mmap.len, self->mmap.pgoff, self->mmap.filename);
487
488 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
489 cpumode == PERF_RECORD_MISC_KERNEL) {
490 ret = event__process_kernel_mmap(self, session);
491 if (ret < 0)
492 goto out_problem;
56b03f3c
ACM
493 return 0;
494 }
495
496 thread = perf_session__findnew(session, self->mmap.pid);
23346f21
ACM
497 machine = perf_session__find_host_machine(session);
498 map = map__new(&machine->user_dsos, self->mmap.start,
a1645ce1
ZY
499 self->mmap.len, self->mmap.pgoff,
500 self->mmap.pid, self->mmap.filename,
501 MAP__FUNCTION, session->cwd, session->cwdlen);
56b03f3c 502
62daacb5 503 if (thread == NULL || map == NULL)
b7cece76
ACM
504 goto out_problem;
505
506 thread__insert_map(thread, map);
507 return 0;
62daacb5 508
b7cece76
ACM
509out_problem:
510 dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
62daacb5
ACM
511 return 0;
512}
513
b3165f41 514int event__process_task(event_t *self, struct perf_session *session)
62daacb5 515{
b3165f41
ACM
516 struct thread *thread = perf_session__findnew(session, self->fork.pid);
517 struct thread *parent = perf_session__findnew(session, self->fork.ppid);
62daacb5
ACM
518
519 dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
520 self->fork.ppid, self->fork.ptid);
521 /*
522 * A thread clone will have the same PID for both parent and child.
523 */
524 if (thread == parent)
525 return 0;
526
527 if (self->header.type == PERF_RECORD_EXIT)
528 return 0;
529
530 if (thread == NULL || parent == NULL ||
531 thread__fork(thread, parent) < 0) {
532 dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
533 return -1;
534 }
535
536 return 0;
537}
1ed091c4 538
59ee68ec
ACM
539void thread__find_addr_map(struct thread *self,
540 struct perf_session *session, u8 cpumode,
a1645ce1 541 enum map_type type, pid_t pid, u64 addr,
59ee68ec 542 struct addr_location *al)
1ed091c4 543{
9958e1f0 544 struct map_groups *mg = &self->mg;
23346f21 545 struct machine *machine = NULL;
1ed091c4 546
9958e1f0 547 al->thread = self;
1ed091c4 548 al->addr = addr;
a1645ce1
ZY
549 al->cpumode = cpumode;
550 al->filtered = false;
1ed091c4 551
a1645ce1 552 if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
1ed091c4 553 al->level = 'k';
23346f21
ACM
554 machine = perf_session__find_host_machine(session);
555 mg = &machine->kmaps;
a1645ce1 556 } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
1ed091c4 557 al->level = '.';
23346f21 558 machine = perf_session__find_host_machine(session);
a1645ce1
ZY
559 } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
560 al->level = 'g';
23346f21
ACM
561 machine = perf_session__find_machine(session, pid);
562 if (!machine) {
a1645ce1
ZY
563 al->map = NULL;
564 return;
565 }
23346f21 566 mg = &machine->kmaps;
a1645ce1
ZY
567 } else {
568 /*
569 * 'u' means guest os user space.
570 * TODO: We don't support guest user space. Might support late.
571 */
572 if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest)
573 al->level = 'u';
574 else
575 al->level = 'H';
1ed091c4 576 al->map = NULL;
a1645ce1
ZY
577
578 if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
579 cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
580 !perf_guest)
581 al->filtered = true;
582 if ((cpumode == PERF_RECORD_MISC_USER ||
583 cpumode == PERF_RECORD_MISC_KERNEL) &&
584 !perf_host)
585 al->filtered = true;
586
1ed091c4
ACM
587 return;
588 }
589try_again:
9958e1f0 590 al->map = map_groups__find(mg, type, al->addr);
1ed091c4
ACM
591 if (al->map == NULL) {
592 /*
593 * If this is outside of all known maps, and is a negative
594 * address, try to look it up in the kernel dso, as it might be
595 * a vsyscall or vdso (which executes in user-mode).
596 *
597 * XXX This is nasty, we should have a symbol list in the
598 * "[vdso]" dso, but for now lets use the old trick of looking
599 * in the whole kernel symbol list.
600 */
a1645ce1 601 if ((long long)al->addr < 0 &&
23346f21
ACM
602 cpumode == PERF_RECORD_MISC_KERNEL &&
603 machine && mg != &machine->kmaps) {
604 mg = &machine->kmaps;
1ed091c4
ACM
605 goto try_again;
606 }
59ee68ec 607 } else
1ed091c4 608 al->addr = al->map->map_ip(al->map, al->addr);
59ee68ec
ACM
609}
610
611void thread__find_addr_location(struct thread *self,
612 struct perf_session *session, u8 cpumode,
a1645ce1 613 enum map_type type, pid_t pid, u64 addr,
59ee68ec
ACM
614 struct addr_location *al,
615 symbol_filter_t filter)
616{
a1645ce1 617 thread__find_addr_map(self, session, cpumode, type, pid, addr, al);
59ee68ec 618 if (al->map != NULL)
9de89fe7 619 al->sym = map__find_symbol(al->map, al->addr, filter);
59ee68ec
ACM
620 else
621 al->sym = NULL;
1ed091c4
ACM
622}
623
c410a338
ACM
624static void dso__calc_col_width(struct dso *self)
625{
626 if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
627 (!symbol_conf.dso_list ||
628 strlist__has_entry(symbol_conf.dso_list, self->name))) {
629 unsigned int slen = strlen(self->name);
630 if (slen > dsos__col_width)
631 dsos__col_width = slen;
632 }
633
634 self->slen_calculated = 1;
635}
636
b3165f41
ACM
637int event__preprocess_sample(const event_t *self, struct perf_session *session,
638 struct addr_location *al, symbol_filter_t filter)
1ed091c4
ACM
639{
640 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
b3165f41 641 struct thread *thread = perf_session__findnew(session, self->ip.pid);
1ed091c4
ACM
642
643 if (thread == NULL)
644 return -1;
645
c410a338
ACM
646 if (symbol_conf.comm_list &&
647 !strlist__has_entry(symbol_conf.comm_list, thread->comm))
648 goto out_filtered;
649
1ed091c4
ACM
650 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
651
96415e4d 652 thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
a1645ce1 653 self->ip.pid, self->ip.ip, al);
1ed091c4
ACM
654 dump_printf(" ...... dso: %s\n",
655 al->map ? al->map->dso->long_name :
656 al->level == 'H' ? "[hypervisor]" : "<not found>");
96415e4d
ACM
657 al->sym = NULL;
658
659 if (al->map) {
660 if (symbol_conf.dso_list &&
661 (!al->map || !al->map->dso ||
662 !(strlist__has_entry(symbol_conf.dso_list,
663 al->map->dso->short_name) ||
664 (al->map->dso->short_name != al->map->dso->long_name &&
665 strlist__has_entry(symbol_conf.dso_list,
666 al->map->dso->long_name)))))
667 goto out_filtered;
668 /*
669 * We have to do this here as we may have a dso with no symbol
670 * hit that has a name longer than the ones with symbols
671 * sampled.
672 */
673 if (!sort_dso.elide && !al->map->dso->slen_calculated)
674 dso__calc_col_width(al->map->dso);
675
676 al->sym = map__find_symbol(al->map, al->addr, filter);
677 }
c410a338
ACM
678
679 if (symbol_conf.sym_list && al->sym &&
680 !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
681 goto out_filtered;
682
c410a338
ACM
683 return 0;
684
685out_filtered:
686 al->filtered = true;
1ed091c4
ACM
687 return 0;
688}
180f95e2
OH
689
690int event__parse_sample(event_t *event, u64 type, struct sample_data *data)
691{
692 u64 *array = event->sample.array;
693
694 if (type & PERF_SAMPLE_IP) {
695 data->ip = event->ip.ip;
696 array++;
697 }
698
699 if (type & PERF_SAMPLE_TID) {
700 u32 *p = (u32 *)array;
701 data->pid = p[0];
702 data->tid = p[1];
703 array++;
704 }
705
706 if (type & PERF_SAMPLE_TIME) {
707 data->time = *array;
708 array++;
709 }
710
711 if (type & PERF_SAMPLE_ADDR) {
712 data->addr = *array;
713 array++;
714 }
715
02bf60aa 716 data->id = -1ULL;
180f95e2
OH
717 if (type & PERF_SAMPLE_ID) {
718 data->id = *array;
719 array++;
720 }
721
722 if (type & PERF_SAMPLE_STREAM_ID) {
723 data->stream_id = *array;
724 array++;
725 }
726
727 if (type & PERF_SAMPLE_CPU) {
728 u32 *p = (u32 *)array;
729 data->cpu = *p;
730 array++;
731 }
732
733 if (type & PERF_SAMPLE_PERIOD) {
734 data->period = *array;
735 array++;
736 }
737
738 if (type & PERF_SAMPLE_READ) {
739 pr_debug("PERF_SAMPLE_READ is unsuported for now\n");
740 return -1;
741 }
742
743 if (type & PERF_SAMPLE_CALLCHAIN) {
744 data->callchain = (struct ip_callchain *)array;
745 array += 1 + data->callchain->nr;
746 }
747
748 if (type & PERF_SAMPLE_RAW) {
749 u32 *p = (u32 *)array;
750 data->raw_size = *p;
751 p++;
752 data->raw_data = p;
753 }
754
755 return 0;
756}
This page took 0.089923 seconds and 5 git commands to generate.