diff options
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r-- | tools/perf/builtin-script.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index e2b9aff6506e..952dce979252 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -573,6 +573,7 @@ struct perf_script { | |||
573 | struct perf_tool tool; | 573 | struct perf_tool tool; |
574 | struct perf_session *session; | 574 | struct perf_session *session; |
575 | bool show_task_events; | 575 | bool show_task_events; |
576 | bool show_mmap_events; | ||
576 | }; | 577 | }; |
577 | 578 | ||
578 | static int process_attr(struct perf_tool *tool, union perf_event *event, | 579 | static int process_attr(struct perf_tool *tool, union perf_event *event, |
@@ -698,6 +699,68 @@ static int process_exit_event(struct perf_tool *tool, | |||
698 | return 0; | 699 | return 0; |
699 | } | 700 | } |
700 | 701 | ||
702 | static int process_mmap_event(struct perf_tool *tool, | ||
703 | union perf_event *event, | ||
704 | struct perf_sample *sample, | ||
705 | struct machine *machine) | ||
706 | { | ||
707 | struct thread *thread; | ||
708 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
709 | struct perf_session *session = script->session; | ||
710 | struct perf_evsel *evsel = perf_evlist__first(session->evlist); | ||
711 | |||
712 | if (perf_event__process_mmap(tool, event, sample, machine) < 0) | ||
713 | return -1; | ||
714 | |||
715 | thread = machine__findnew_thread(machine, event->mmap.pid, event->mmap.tid); | ||
716 | if (thread == NULL) { | ||
717 | pr_debug("problem processing MMAP event, skipping it.\n"); | ||
718 | return -1; | ||
719 | } | ||
720 | |||
721 | if (!evsel->attr.sample_id_all) { | ||
722 | sample->cpu = 0; | ||
723 | sample->time = 0; | ||
724 | sample->tid = event->mmap.tid; | ||
725 | sample->pid = event->mmap.pid; | ||
726 | } | ||
727 | print_sample_start(sample, thread, evsel); | ||
728 | perf_event__fprintf(event, stdout); | ||
729 | |||
730 | return 0; | ||
731 | } | ||
732 | |||
733 | static int process_mmap2_event(struct perf_tool *tool, | ||
734 | union perf_event *event, | ||
735 | struct perf_sample *sample, | ||
736 | struct machine *machine) | ||
737 | { | ||
738 | struct thread *thread; | ||
739 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
740 | struct perf_session *session = script->session; | ||
741 | struct perf_evsel *evsel = perf_evlist__first(session->evlist); | ||
742 | |||
743 | if (perf_event__process_mmap2(tool, event, sample, machine) < 0) | ||
744 | return -1; | ||
745 | |||
746 | thread = machine__findnew_thread(machine, event->mmap2.pid, event->mmap2.tid); | ||
747 | if (thread == NULL) { | ||
748 | pr_debug("problem processing MMAP2 event, skipping it.\n"); | ||
749 | return -1; | ||
750 | } | ||
751 | |||
752 | if (!evsel->attr.sample_id_all) { | ||
753 | sample->cpu = 0; | ||
754 | sample->time = 0; | ||
755 | sample->tid = event->mmap2.tid; | ||
756 | sample->pid = event->mmap2.pid; | ||
757 | } | ||
758 | print_sample_start(sample, thread, evsel); | ||
759 | perf_event__fprintf(event, stdout); | ||
760 | |||
761 | return 0; | ||
762 | } | ||
763 | |||
701 | static void sig_handler(int sig __maybe_unused) | 764 | static void sig_handler(int sig __maybe_unused) |
702 | { | 765 | { |
703 | session_done = 1; | 766 | session_done = 1; |
@@ -715,6 +778,10 @@ static int __cmd_script(struct perf_script *script) | |||
715 | script->tool.fork = process_fork_event; | 778 | script->tool.fork = process_fork_event; |
716 | script->tool.exit = process_exit_event; | 779 | script->tool.exit = process_exit_event; |
717 | } | 780 | } |
781 | if (script->show_mmap_events) { | ||
782 | script->tool.mmap = process_mmap_event; | ||
783 | script->tool.mmap2 = process_mmap2_event; | ||
784 | } | ||
718 | 785 | ||
719 | ret = perf_session__process_events(script->session, &script->tool); | 786 | ret = perf_session__process_events(script->session, &script->tool); |
720 | 787 | ||
@@ -1480,6 +1547,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1480 | "Show the path of [kernel.kallsyms]"), | 1547 | "Show the path of [kernel.kallsyms]"), |
1481 | OPT_BOOLEAN('\0', "show-task-events", &script.show_task_events, | 1548 | OPT_BOOLEAN('\0', "show-task-events", &script.show_task_events, |
1482 | "Show the fork/comm/exit events"), | 1549 | "Show the fork/comm/exit events"), |
1550 | OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events, | ||
1551 | "Show the mmap events"), | ||
1483 | OPT_END() | 1552 | OPT_END() |
1484 | }; | 1553 | }; |
1485 | const char * const script_usage[] = { | 1554 | const char * const script_usage[] = { |