From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung.kim@lge.com>,
LKML <linux-kernel@vger.kernel.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>, David Ahern <dsahern@gmail.com>
Subject: [RFC/PATCH 3/3] perf script: Print mmap[2] events also
Date: Mon, 18 Nov 2013 12:00:42 +0900 [thread overview]
Message-ID: <1384743642-15120-3-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1384743642-15120-1-git-send-email-namhyung@kernel.org>
If --show-mmap option is given, also print internal MMAP and MMAP2
events. It would be helpful for debugging.
Suggested-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-script.txt | 3 ++
tools/perf/builtin-script.c | 78 ++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 9a9a7c3d592d..ad67f3b0efda 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -206,6 +206,9 @@ OPTIONS
--show-task
Display task related events (e.g. FORK, COMM, EXIT).
+--show-mmap
+ Display mmap related events (e.g. MMAP, MMAP2).
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-script-perl[1],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index bc4cbb8b8867..4b88bdb936b4 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -549,6 +549,7 @@ struct perf_script {
struct perf_tool tool;
struct perf_session *session;
bool show_task_events;
+ bool show_mmap_events;
};
static int process_attr(struct perf_tool *tool, union perf_event *event,
@@ -679,6 +680,77 @@ static int process_exit_event(struct perf_tool *tool,
return 0;
}
+static int process_mmap_event(struct perf_tool *tool,
+ union perf_event *event,
+ struct perf_sample *sample,
+ struct machine *machine)
+{
+ struct thread *thread;
+ struct perf_script *script = container_of(tool, struct perf_script, tool);
+ struct perf_session *session = script->session;
+ struct perf_evsel *evsel = perf_evlist__first(session->evlist);
+
+ if (perf_event__process_mmap(tool, event, sample, machine) < 0)
+ return -1;
+
+ thread = machine__findnew_thread(machine, event->mmap.pid, event->mmap.tid);
+ if (thread == NULL) {
+ pr_debug("problem processing MMAP event, skipping it.\n");
+ return -1;
+ }
+
+ if (!evsel->attr.sample_id_all) {
+ sample->cpu = 0;
+ sample->time = 0;
+ sample->tid = event->comm.tid;
+ sample->pid = event->comm.pid;
+ }
+ print_sample_start(sample, thread, evsel);
+ printf("mmap: [(%#"PRIx64" - %#"PRIx64") @ %#"PRIx64" ]: %c %s\n",
+ event->mmap.start, event->mmap.start + event->mmap.len,
+ event->mmap.pgoff,
+ (event->header.misc & PERF_RECORD_MISC_MMAP_DATA) ? 'r' : 'x',
+ event->mmap.filename);
+
+ return 0;
+}
+
+static int process_mmap2_event(struct perf_tool *tool,
+ union perf_event *event,
+ struct perf_sample *sample,
+ struct machine *machine)
+{
+ struct thread *thread;
+ struct perf_script *script = container_of(tool, struct perf_script, tool);
+ struct perf_session *session = script->session;
+ struct perf_evsel *evsel = perf_evlist__first(session->evlist);
+
+ if (perf_event__process_mmap2(tool, event, sample, machine) < 0)
+ return -1;
+
+ thread = machine__findnew_thread(machine, event->mmap2.pid, event->mmap2.tid);
+ if (thread == NULL) {
+ pr_debug("problem processing MMAP2 event, skipping it.\n");
+ return -1;
+ }
+
+ if (!evsel->attr.sample_id_all) {
+ sample->cpu = 0;
+ sample->time = 0;
+ sample->tid = event->mmap2.tid;
+ sample->pid = event->mmap2.pid;
+ }
+ print_sample_start(sample, thread, evsel);
+ printf("mmap: [(%#"PRIx64" - %#"PRIx64") @ %#"PRIx64" %02x:%02x %"PRIu64"]: %c %s\n",
+ event->mmap2.start, event->mmap2.start + event->mmap2.len,
+ event->mmap2.pgoff, event->mmap2.maj, event->mmap2.min,
+ event->mmap2.ino,
+ (event->header.misc & PERF_RECORD_MISC_MMAP_DATA) ? 'r' : 'x',
+ event->mmap2.filename);
+
+ return 0;
+}
+
static void sig_handler(int sig __maybe_unused)
{
session_done = 1;
@@ -696,6 +768,10 @@ static int __cmd_script(struct perf_script *script)
script->tool.fork = process_fork_event;
script->tool.exit = process_exit_event;
}
+ if (script->show_mmap_events) {
+ script->tool.mmap = process_mmap_event;
+ script->tool.mmap2 = process_mmap2_event;
+ }
ret = perf_session__process_events(script->session, &script->tool);
@@ -1461,6 +1537,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"Show the path of [kernel.kallsyms]"),
OPT_BOOLEAN('\0', "show-task", &script.show_task_events,
"Show the fork/comm/exit events"),
+ OPT_BOOLEAN('\0', "show-mmap", &script.show_mmap_events,
+ "Show the mmap events"),
OPT_END()
};
const char * const script_usage[] = {
--
1.7.11.7
next prev parent reply other threads:[~2013-11-18 3:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-18 3:00 [PATCH 1/3] perf script: Move evname print code to process_event() Namhyung Kim
2013-11-18 3:00 ` [RFC/PATCH 2/3] perf script: Print comm, fork and exit events also Namhyung Kim
2013-11-18 4:44 ` David Ahern
2013-11-18 3:00 ` Namhyung Kim [this message]
2013-11-18 4:47 ` [RFC/PATCH 3/3] perf script: Print mmap[2] " David Ahern
2013-11-18 5:18 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1384743642-15120-3-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®