aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/event.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/event.c')
-rw-r--r--tools/perf/util/event.c187
1 files changed, 98 insertions, 89 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 5c886fbd50ce..731265f4ad19 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -7,7 +7,7 @@
7#include "strlist.h" 7#include "strlist.h"
8#include "thread.h" 8#include "thread.h"
9 9
10static const char *event__name[] = { 10static const char *perf_event__names[] = {
11 [0] = "TOTAL", 11 [0] = "TOTAL",
12 [PERF_RECORD_MMAP] = "MMAP", 12 [PERF_RECORD_MMAP] = "MMAP",
13 [PERF_RECORD_LOST] = "LOST", 13 [PERF_RECORD_LOST] = "LOST",
@@ -25,13 +25,13 @@ static const char *event__name[] = {
25 [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND", 25 [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND",
26}; 26};
27 27
28const char *event__get_event_name(unsigned int id) 28const char *perf_event__name(unsigned int id)
29{ 29{
30 if (id >= ARRAY_SIZE(event__name)) 30 if (id >= ARRAY_SIZE(perf_event__names))
31 return "INVALID"; 31 return "INVALID";
32 if (!event__name[id]) 32 if (!perf_event__names[id])
33 return "UNKNOWN"; 33 return "UNKNOWN";
34 return event__name[id]; 34 return perf_event__names[id];
35} 35}
36 36
37static struct perf_sample synth_sample = { 37static struct perf_sample synth_sample = {
@@ -43,9 +43,9 @@ static struct perf_sample synth_sample = {
43 .period = 1, 43 .period = 1,
44}; 44};
45 45
46static pid_t event__synthesize_comm(event_t *event, pid_t pid, int full, 46static pid_t perf_event__synthesize_comm(union perf_event *event, pid_t pid,
47 event__handler_t process, 47 int full, perf_event__handler_t process,
48 struct perf_session *session) 48 struct perf_session *session)
49{ 49{
50 char filename[PATH_MAX]; 50 char filename[PATH_MAX];
51 char bf[BUFSIZ]; 51 char bf[BUFSIZ];
@@ -126,9 +126,10 @@ out:
126 return tgid; 126 return tgid;
127} 127}
128 128
129static int event__synthesize_mmap_events(event_t *event, pid_t pid, pid_t tgid, 129static int perf_event__synthesize_mmap_events(union perf_event *event,
130 event__handler_t process, 130 pid_t pid, pid_t tgid,
131 struct perf_session *session) 131 perf_event__handler_t process,
132 struct perf_session *session)
132{ 133{
133 char filename[PATH_MAX]; 134 char filename[PATH_MAX];
134 FILE *fp; 135 FILE *fp;
@@ -199,14 +200,14 @@ static int event__synthesize_mmap_events(event_t *event, pid_t pid, pid_t tgid,
199 return 0; 200 return 0;
200} 201}
201 202
202int event__synthesize_modules(event__handler_t process, 203int perf_event__synthesize_modules(perf_event__handler_t process,
203 struct perf_session *session, 204 struct perf_session *session,
204 struct machine *machine) 205 struct machine *machine)
205{ 206{
206 struct rb_node *nd; 207 struct rb_node *nd;
207 struct map_groups *kmaps = &machine->kmaps; 208 struct map_groups *kmaps = &machine->kmaps;
208 event_t *event = zalloc(sizeof(event->mmap) + session->id_hdr_size); 209 union perf_event *event = zalloc((sizeof(event->mmap) +
209 210 session->id_hdr_size));
210 if (event == NULL) { 211 if (event == NULL) {
211 pr_debug("Not enough memory synthesizing mmap event " 212 pr_debug("Not enough memory synthesizing mmap event "
212 "for kernel modules\n"); 213 "for kernel modules\n");
@@ -251,22 +252,23 @@ int event__synthesize_modules(event__handler_t process,
251 return 0; 252 return 0;
252} 253}
253 254
254static int __event__synthesize_thread(event_t *comm_event, event_t *mmap_event, 255static int __event__synthesize_thread(union perf_event *comm_event,
255 pid_t pid, event__handler_t process, 256 union perf_event *mmap_event,
257 pid_t pid, perf_event__handler_t process,
256 struct perf_session *session) 258 struct perf_session *session)
257{ 259{
258 pid_t tgid = event__synthesize_comm(comm_event, pid, 1, process, 260 pid_t tgid = perf_event__synthesize_comm(comm_event, pid, 1, process,
259 session); 261 session);
260 if (tgid == -1) 262 if (tgid == -1)
261 return -1; 263 return -1;
262 return event__synthesize_mmap_events(mmap_event, pid, tgid, 264 return perf_event__synthesize_mmap_events(mmap_event, pid, tgid,
263 process, session); 265 process, session);
264} 266}
265 267
266int event__synthesize_thread(pid_t pid, event__handler_t process, 268int perf_event__synthesize_thread(pid_t pid, perf_event__handler_t process,
267 struct perf_session *session) 269 struct perf_session *session)
268{ 270{
269 event_t *comm_event, *mmap_event; 271 union perf_event *comm_event, *mmap_event;
270 int err = -1; 272 int err = -1;
271 273
272 comm_event = malloc(sizeof(comm_event->comm) + session->id_hdr_size); 274 comm_event = malloc(sizeof(comm_event->comm) + session->id_hdr_size);
@@ -286,12 +288,12 @@ out:
286 return err; 288 return err;
287} 289}
288 290
289int event__synthesize_threads(event__handler_t process, 291int perf_event__synthesize_threads(perf_event__handler_t process,
290 struct perf_session *session) 292 struct perf_session *session)
291{ 293{
292 DIR *proc; 294 DIR *proc;
293 struct dirent dirent, *next; 295 struct dirent dirent, *next;
294 event_t *comm_event, *mmap_event; 296 union perf_event *comm_event, *mmap_event;
295 int err = -1; 297 int err = -1;
296 298
297 comm_event = malloc(sizeof(comm_event->comm) + session->id_hdr_size); 299 comm_event = malloc(sizeof(comm_event->comm) + session->id_hdr_size);
@@ -349,10 +351,10 @@ static int find_symbol_cb(void *arg, const char *name, char type,
349 return 1; 351 return 1;
350} 352}
351 353
352int event__synthesize_kernel_mmap(event__handler_t process, 354int perf_event__synthesize_kernel_mmap(perf_event__handler_t process,
353 struct perf_session *session, 355 struct perf_session *session,
354 struct machine *machine, 356 struct machine *machine,
355 const char *symbol_name) 357 const char *symbol_name)
356{ 358{
357 size_t size; 359 size_t size;
358 const char *filename, *mmap_name; 360 const char *filename, *mmap_name;
@@ -366,8 +368,8 @@ int event__synthesize_kernel_mmap(event__handler_t process,
366 * kernels. 368 * kernels.
367 */ 369 */
368 struct process_symbol_args args = { .name = symbol_name, }; 370 struct process_symbol_args args = { .name = symbol_name, };
369 event_t *event = zalloc(sizeof(event->mmap) + session->id_hdr_size); 371 union perf_event *event = zalloc((sizeof(event->mmap) +
370 372 session->id_hdr_size));
371 if (event == NULL) { 373 if (event == NULL) {
372 pr_debug("Not enough memory synthesizing mmap event " 374 pr_debug("Not enough memory synthesizing mmap event "
373 "for kernel modules\n"); 375 "for kernel modules\n");
@@ -440,14 +442,15 @@ static int thread__set_comm_adjust(struct thread *self, const char *comm,
440 return 0; 442 return 0;
441} 443}
442 444
443int event__process_comm(event_t *self, struct perf_sample *sample __used, 445int perf_event__process_comm(union perf_event *event,
444 struct perf_session *session) 446 struct perf_sample *sample __used,
447 struct perf_session *session)
445{ 448{
446 struct thread *thread = perf_session__findnew(session, self->comm.tid); 449 struct thread *thread = perf_session__findnew(session, event->comm.tid);
447 450
448 dump_printf(": %s:%d\n", self->comm.comm, self->comm.tid); 451 dump_printf(": %s:%d\n", event->comm.comm, event->comm.tid);
449 452
450 if (thread == NULL || thread__set_comm_adjust(thread, self->comm.comm, 453 if (thread == NULL || thread__set_comm_adjust(thread, event->comm.comm,
451 &session->hists)) { 454 &session->hists)) {
452 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); 455 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
453 return -1; 456 return -1;
@@ -456,19 +459,21 @@ int event__process_comm(event_t *self, struct perf_sample *sample __used,
456 return 0; 459 return 0;
457} 460}
458 461
459int event__process_lost(event_t *self, struct perf_sample *sample __used, 462int perf_event__process_lost(union perf_event *event,
460 struct perf_session *session) 463 struct perf_sample *sample __used,
464 struct perf_session *session)
461{ 465{
462 dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n", 466 dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n",
463 self->lost.id, self->lost.lost); 467 event->lost.id, event->lost.lost);
464 session->hists.stats.total_lost += self->lost.lost; 468 session->hists.stats.total_lost += event->lost.lost;
465 return 0; 469 return 0;
466} 470}
467 471
468static void event_set_kernel_mmap_len(struct map **maps, event_t *self) 472static void perf_event__set_kernel_mmap_len(union perf_event *event,
473 struct map **maps)
469{ 474{
470 maps[MAP__FUNCTION]->start = self->mmap.start; 475 maps[MAP__FUNCTION]->start = event->mmap.start;
471 maps[MAP__FUNCTION]->end = self->mmap.start + self->mmap.len; 476 maps[MAP__FUNCTION]->end = event->mmap.start + event->mmap.len;
472 /* 477 /*
473 * Be a bit paranoid here, some perf.data file came with 478 * Be a bit paranoid here, some perf.data file came with
474 * a zero sized synthesized MMAP event for the kernel. 479 * a zero sized synthesized MMAP event for the kernel.
@@ -477,8 +482,8 @@ static void event_set_kernel_mmap_len(struct map **maps, event_t *self)
477 maps[MAP__FUNCTION]->end = ~0ULL; 482 maps[MAP__FUNCTION]->end = ~0ULL;
478} 483}
479 484
480static int event__process_kernel_mmap(event_t *self, 485static int perf_event__process_kernel_mmap(union perf_event *event,
481 struct perf_session *session) 486 struct perf_session *session)
482{ 487{
483 struct map *map; 488 struct map *map;
484 char kmmap_prefix[PATH_MAX]; 489 char kmmap_prefix[PATH_MAX];
@@ -486,9 +491,9 @@ static int event__process_kernel_mmap(event_t *self,
486 enum dso_kernel_type kernel_type; 491 enum dso_kernel_type kernel_type;
487 bool is_kernel_mmap; 492 bool is_kernel_mmap;
488 493
489 machine = perf_session__findnew_machine(session, self->mmap.pid); 494 machine = perf_session__findnew_machine(session, event->mmap.pid);
490 if (!machine) { 495 if (!machine) {
491 pr_err("Can't find id %d's machine\n", self->mmap.pid); 496 pr_err("Can't find id %d's machine\n", event->mmap.pid);
492 goto out_problem; 497 goto out_problem;
493 } 498 }
494 499
@@ -498,17 +503,17 @@ static int event__process_kernel_mmap(event_t *self,
498 else 503 else
499 kernel_type = DSO_TYPE_GUEST_KERNEL; 504 kernel_type = DSO_TYPE_GUEST_KERNEL;
500 505
501 is_kernel_mmap = memcmp(self->mmap.filename, 506 is_kernel_mmap = memcmp(event->mmap.filename,
502 kmmap_prefix, 507 kmmap_prefix,
503 strlen(kmmap_prefix)) == 0; 508 strlen(kmmap_prefix)) == 0;
504 if (self->mmap.filename[0] == '/' || 509 if (event->mmap.filename[0] == '/' ||
505 (!is_kernel_mmap && self->mmap.filename[0] == '[')) { 510 (!is_kernel_mmap && event->mmap.filename[0] == '[')) {
506 511
507 char short_module_name[1024]; 512 char short_module_name[1024];
508 char *name, *dot; 513 char *name, *dot;
509 514
510 if (self->mmap.filename[0] == '/') { 515 if (event->mmap.filename[0] == '/') {
511 name = strrchr(self->mmap.filename, '/'); 516 name = strrchr(event->mmap.filename, '/');
512 if (name == NULL) 517 if (name == NULL)
513 goto out_problem; 518 goto out_problem;
514 519
@@ -520,10 +525,10 @@ static int event__process_kernel_mmap(event_t *self,
520 "[%.*s]", (int)(dot - name), name); 525 "[%.*s]", (int)(dot - name), name);
521 strxfrchar(short_module_name, '-', '_'); 526 strxfrchar(short_module_name, '-', '_');
522 } else 527 } else
523 strcpy(short_module_name, self->mmap.filename); 528 strcpy(short_module_name, event->mmap.filename);
524 529
525 map = machine__new_module(machine, self->mmap.start, 530 map = machine__new_module(machine, event->mmap.start,
526 self->mmap.filename); 531 event->mmap.filename);
527 if (map == NULL) 532 if (map == NULL)
528 goto out_problem; 533 goto out_problem;
529 534
@@ -533,9 +538,9 @@ static int event__process_kernel_mmap(event_t *self,
533 538
534 map->dso->short_name = name; 539 map->dso->short_name = name;
535 map->dso->sname_alloc = 1; 540 map->dso->sname_alloc = 1;
536 map->end = map->start + self->mmap.len; 541 map->end = map->start + event->mmap.len;
537 } else if (is_kernel_mmap) { 542 } else if (is_kernel_mmap) {
538 const char *symbol_name = (self->mmap.filename + 543 const char *symbol_name = (event->mmap.filename +
539 strlen(kmmap_prefix)); 544 strlen(kmmap_prefix));
540 /* 545 /*
541 * Should be there already, from the build-id table in 546 * Should be there already, from the build-id table in
@@ -550,10 +555,10 @@ static int event__process_kernel_mmap(event_t *self,
550 if (__machine__create_kernel_maps(machine, kernel) < 0) 555 if (__machine__create_kernel_maps(machine, kernel) < 0)
551 goto out_problem; 556 goto out_problem;
552 557
553 event_set_kernel_mmap_len(machine->vmlinux_maps, self); 558 perf_event__set_kernel_mmap_len(event, machine->vmlinux_maps);
554 perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, 559 perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
555 symbol_name, 560 symbol_name,
556 self->mmap.pgoff); 561 event->mmap.pgoff);
557 if (machine__is_default_guest(machine)) { 562 if (machine__is_default_guest(machine)) {
558 /* 563 /*
559 * preload dso of guest kernel and modules 564 * preload dso of guest kernel and modules
@@ -567,22 +572,23 @@ out_problem:
567 return -1; 572 return -1;
568} 573}
569 574
570int event__process_mmap(event_t *self, struct perf_sample *sample __used, 575int perf_event__process_mmap(union perf_event *event,
571 struct perf_session *session) 576 struct perf_sample *sample __used,
577 struct perf_session *session)
572{ 578{
573 struct machine *machine; 579 struct machine *machine;
574 struct thread *thread; 580 struct thread *thread;
575 struct map *map; 581 struct map *map;
576 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 582 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
577 int ret = 0; 583 int ret = 0;
578 584
579 dump_printf(" %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %s\n", 585 dump_printf(" %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %s\n",
580 self->mmap.pid, self->mmap.tid, self->mmap.start, 586 event->mmap.pid, event->mmap.tid, event->mmap.start,
581 self->mmap.len, self->mmap.pgoff, self->mmap.filename); 587 event->mmap.len, event->mmap.pgoff, event->mmap.filename);
582 588
583 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 589 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
584 cpumode == PERF_RECORD_MISC_KERNEL) { 590 cpumode == PERF_RECORD_MISC_KERNEL) {
585 ret = event__process_kernel_mmap(self, session); 591 ret = perf_event__process_kernel_mmap(event, session);
586 if (ret < 0) 592 if (ret < 0)
587 goto out_problem; 593 goto out_problem;
588 return 0; 594 return 0;
@@ -591,12 +597,12 @@ int event__process_mmap(event_t *self, struct perf_sample *sample __used,
591 machine = perf_session__find_host_machine(session); 597 machine = perf_session__find_host_machine(session);
592 if (machine == NULL) 598 if (machine == NULL)
593 goto out_problem; 599 goto out_problem;
594 thread = perf_session__findnew(session, self->mmap.pid); 600 thread = perf_session__findnew(session, event->mmap.pid);
595 if (thread == NULL) 601 if (thread == NULL)
596 goto out_problem; 602 goto out_problem;
597 map = map__new(&machine->user_dsos, self->mmap.start, 603 map = map__new(&machine->user_dsos, event->mmap.start,
598 self->mmap.len, self->mmap.pgoff, 604 event->mmap.len, event->mmap.pgoff,
599 self->mmap.pid, self->mmap.filename, 605 event->mmap.pid, event->mmap.filename,
600 MAP__FUNCTION); 606 MAP__FUNCTION);
601 if (map == NULL) 607 if (map == NULL)
602 goto out_problem; 608 goto out_problem;
@@ -609,16 +615,17 @@ out_problem:
609 return 0; 615 return 0;
610} 616}
611 617
612int event__process_task(event_t *self, struct perf_sample *sample __used, 618int perf_event__process_task(union perf_event *event,
613 struct perf_session *session) 619 struct perf_sample *sample __used,
620 struct perf_session *session)
614{ 621{
615 struct thread *thread = perf_session__findnew(session, self->fork.tid); 622 struct thread *thread = perf_session__findnew(session, event->fork.tid);
616 struct thread *parent = perf_session__findnew(session, self->fork.ptid); 623 struct thread *parent = perf_session__findnew(session, event->fork.ptid);
617 624
618 dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid, 625 dump_printf("(%d:%d):(%d:%d)\n", event->fork.pid, event->fork.tid,
619 self->fork.ppid, self->fork.ptid); 626 event->fork.ppid, event->fork.ptid);
620 627
621 if (self->header.type == PERF_RECORD_EXIT) { 628 if (event->header.type == PERF_RECORD_EXIT) {
622 perf_session__remove_thread(session, thread); 629 perf_session__remove_thread(session, thread);
623 return 0; 630 return 0;
624 } 631 }
@@ -632,22 +639,22 @@ int event__process_task(event_t *self, struct perf_sample *sample __used,
632 return 0; 639 return 0;
633} 640}
634 641
635int event__process(event_t *event, struct perf_sample *sample, 642int perf_event__process(union perf_event *event, struct perf_sample *sample,
636 struct perf_session *session) 643 struct perf_session *session)
637{ 644{
638 switch (event->header.type) { 645 switch (event->header.type) {
639 case PERF_RECORD_COMM: 646 case PERF_RECORD_COMM:
640 event__process_comm(event, sample, session); 647 perf_event__process_comm(event, sample, session);
641 break; 648 break;
642 case PERF_RECORD_MMAP: 649 case PERF_RECORD_MMAP:
643 event__process_mmap(event, sample, session); 650 perf_event__process_mmap(event, sample, session);
644 break; 651 break;
645 case PERF_RECORD_FORK: 652 case PERF_RECORD_FORK:
646 case PERF_RECORD_EXIT: 653 case PERF_RECORD_EXIT:
647 event__process_task(event, sample, session); 654 perf_event__process_task(event, sample, session);
648 break; 655 break;
649 case PERF_RECORD_LOST: 656 case PERF_RECORD_LOST:
650 event__process_lost(event, sample, session); 657 perf_event__process_lost(event, sample, session);
651 default: 658 default:
652 break; 659 break;
653 } 660 }
@@ -756,12 +763,14 @@ static void dso__calc_col_width(struct dso *self, struct hists *hists)
756 self->slen_calculated = 1; 763 self->slen_calculated = 1;
757} 764}
758 765
759int event__preprocess_sample(const event_t *self, struct perf_session *session, 766int perf_event__preprocess_sample(const union perf_event *event,
760 struct addr_location *al, struct perf_sample *sample, 767 struct perf_session *session,
761 symbol_filter_t filter) 768 struct addr_location *al,
769 struct perf_sample *sample,
770 symbol_filter_t filter)
762{ 771{
763 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 772 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
764 struct thread *thread = perf_session__findnew(session, self->ip.pid); 773 struct thread *thread = perf_session__findnew(session, event->ip.pid);
765 774
766 if (thread == NULL) 775 if (thread == NULL)
767 return -1; 776 return -1;
@@ -783,7 +792,7 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,
783 machine__create_kernel_maps(&session->host_machine); 792 machine__create_kernel_maps(&session->host_machine);
784 793
785 thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, 794 thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
786 self->ip.pid, self->ip.ip, al); 795 event->ip.pid, event->ip.ip, al);
787 dump_printf(" ...... dso: %s\n", 796 dump_printf(" ...... dso: %s\n",
788 al->map ? al->map->dso->long_name : 797 al->map ? al->map->dso->long_name :
789 al->level == 'H' ? "[hypervisor]" : "<not found>"); 798 al->level == 'H' ? "[hypervisor]" : "<not found>");