From: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
To: Arnaldo Carvalho de Melo <acme@infradead.org>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
David Ahern <dsahern@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
yrl.pp-manager.tt@hitachi.com,
Akihiro Nagai <akihiro.nagai.hw@hitachi.com>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
Arnaldo Carvalho de Melo <acme@infradead.org>,
David Ahern <dsahern@gmail.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Subject: [PATCH -tip v2 5/6] perf script: add the offset field specifier
Date: Sun, 17 Jul 2011 18:31:09 +0900 [thread overview]
Message-ID: <20110717093109.3447.20340.stgit@linux3> (raw)
In-Reply-To: <20110717093031.3447.52715.stgit@linux3>
Add the offset field specifier 'offs' to show the offset from
the symbols in the output of perf-script. We can get the more
detailed address information.
Output sample:
# perf script -f ip,addr,sym,offs
301ec016b0 (unknown) ffffffff81467612 irq_return+0x0
301ec016b0 _start+0x0 ffffffff81467612 irq_return+0x0
301ec04b70 _dl_start+0x0 301ec016b3 _start+0x3
301ec04b70 _dl_start+0x0 ffffffff81467612 irq_return+0x0
301ec04b96 _dl_start+0x26 ffffffff81467612 irq_return+0x0
301ec04b9d _dl_start+0x2d ffffffff81467612 irq_return+0x0
301ec04c0d _dl_start+0x9d 301ec04beb _dl_start+0x7b
301ec04bf0 _dl_start+0x80 301ec04c11 _dl_start+0xa1
[snip]
Changes in v2:
- change the way to output offset from '--show-symbol-offset' to
'offs' field.
- clean up codes.
Signed-off-by: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/Documentation/perf-script.txt | 2 +-
tools/perf/builtin-script.c | 20 +++++++++++++++++---
tools/perf/util/session.c | 7 +++++--
tools/perf/util/session.h | 3 ++-
tools/perf/util/symbol.c | 22 +++++++++++++++-------
tools/perf/util/symbol.h | 2 ++
6 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index db01786..ee4d477 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -115,7 +115,7 @@ OPTIONS
-f::
--fields::
Comma separated list of fields to print. Options are:
- comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr.
+ comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, offs.
Field list can be prepended with the type, trace, sw or hw,
to indicate to which event type the field list applies.
e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7708d89..fd68185 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -37,6 +37,7 @@ enum perf_output_field {
PERF_OUTPUT_SYM = 1U << 8,
PERF_OUTPUT_DSO = 1U << 9,
PERF_OUTPUT_ADDR = 1U << 10,
+ PERF_OUTPUT_OFFSET = 1U << 11,
};
struct output_option {
@@ -54,6 +55,7 @@ struct output_option {
{.str = "sym", .field = PERF_OUTPUT_SYM},
{.str = "dso", .field = PERF_OUTPUT_DSO},
{.str = "addr", .field = PERF_OUTPUT_ADDR},
+ {.str = "offs", .field = PERF_OUTPUT_OFFSET},
};
/* default set to maintain compatibility with current format */
@@ -190,6 +192,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
"to symbols.\n");
return -EINVAL;
}
+ if (PRINT_FIELD(OFFSET) && !PRINT_FIELD(SYM)) {
+ pr_err("Display of offsets requested but symbol is not"
+ "selected.\n");
+ return -EINVAL;
+ }
if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
pr_err("Display of DSO requested but neither sample IP nor "
"sample address\nis selected. Hence, no addresses to convert "
@@ -350,7 +357,10 @@ static void print_sample_addr(union perf_event *event,
if (PRINT_FIELD(SYM)) {
printf(" ");
- symbol__print_symname(al.sym);
+ if (PRINT_FIELD(OFFSET))
+ symbol__print_symname_offs(al.sym, &al);
+ else
+ symbol__print_symname(al.sym);
}
if (PRINT_FIELD(DSO)) {
@@ -386,7 +396,8 @@ static void process_event(union perf_event *event __unused,
else
printf("\n");
perf_session__print_ip(event, sample, session,
- PRINT_FIELD(SYM), PRINT_FIELD(DSO));
+ PRINT_FIELD(SYM), PRINT_FIELD(DSO),
+ PRINT_FIELD(OFFSET));
}
printf("\n");
@@ -1082,7 +1093,10 @@ static const struct option options[] = {
OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
"Look for files with symbols relative to this directory"),
OPT_CALLBACK('f', "fields", NULL, "str",
- "comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr",
+ "comma separated output fields prepend with 'type:'. "
+ "Valid types: hw,sw,trace,raw. "
+ "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
+ "addr,offs",
parse_output_fields),
OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 442be3a..3728e67 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1211,7 +1211,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
void perf_session__print_ip(union perf_event *event,
struct perf_sample *sample,
struct perf_session *session,
- int print_sym, int print_dso)
+ int print_sym, int print_dso, int print_offset)
{
struct addr_location al;
struct callchain_cursor *cursor = &session->callchain_cursor;
@@ -1258,7 +1258,10 @@ void perf_session__print_ip(union perf_event *event,
printf("%16" PRIx64, sample->ip);
if (print_sym) {
printf(" ");
- symbol__print_symname(al.sym);
+ if (print_offset)
+ symbol__print_symname_offs(al.sym, &al);
+ else
+ symbol__print_symname(al.sym);
}
if (print_dso) {
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 5de754f..e6e5586 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -170,7 +170,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
void perf_session__print_ip(union perf_event *event,
struct perf_sample *sample,
struct perf_session *session,
- int print_sym, int print_dso);
+ int print_sym, int print_dso,
+ int print_offset);
int perf_session__cpu_bitmap(struct perf_session *session,
const char *cpu_list, unsigned long *cpu_bitmap);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 85e19c4..abfecf6 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -175,16 +175,24 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
sym->name);
}
-void symbol__print_symname(const struct symbol *sym)
+void symbol__print_symname_offs(const struct symbol *sym,
+ const struct addr_location *al)
{
- const char *symname;
+ unsigned long offset;
- if (sym && sym->name)
- symname = sym->name;
- else
- symname = "(unknown)";
+ if (sym && sym->name) {
+ printf("%s", sym->name);
+ if (al) {
+ offset = al->addr - sym->start;
+ printf("+0x%lx", offset);
+ }
+ } else
+ printf("(unknown)");
+}
- printf("%s", symname);
+void symbol__print_symname(const struct symbol *sym)
+{
+ symbol__print_symname_offs(sym, NULL);
}
void dso__set_long_name(struct dso *dso, char *name)
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 1ec17b4..554b2fe 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -238,6 +238,8 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
int symbol__init(void);
void symbol__exit(void);
+void symbol__print_symname_offs(const struct symbol *sym,
+ const struct addr_location *al);
void symbol__print_symname(const struct symbol *sym);
bool symbol_type__is_a(char symbol_type, enum map_type map_type);
next prev parent reply other threads:[~2011-07-17 9:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-17 9:30 [PATCH -tip v2 0/6] perf script: add BTS analysis features Akihiro Nagai
2011-07-17 9:30 ` [PATCH -tip v2 1/6] [BUGFIX] perf script: print correct IP address Akihiro Nagai
2011-07-17 15:59 ` David Ahern
2011-07-17 17:29 ` Frederic Weisbecker
2011-07-17 9:30 ` [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols Akihiro Nagai
2011-07-17 16:07 ` David Ahern
2011-07-17 16:30 ` David Ahern
2011-07-21 9:36 ` Akihiro Nagai
2011-07-21 9:42 ` Peter Zijlstra
2011-07-21 14:39 ` David Ahern
2011-07-22 4:25 ` Akihiro Nagai
2011-07-17 9:30 ` [PATCH -tip v2 3/6] perf script: resolve DSOs and symbols for user-space Akihiro Nagai
2011-07-17 16:20 ` David Ahern
2011-07-21 9:36 ` Akihiro Nagai
2011-07-17 9:31 ` [PATCH -tip v2 4/6] perf script: print DSOs and symbols for BTS branch_from addr Akihiro Nagai
2011-07-17 16:22 ` David Ahern
2011-07-21 9:36 ` Akihiro Nagai
2011-07-17 9:31 ` Akihiro Nagai [this message]
2011-07-17 16:28 ` [PATCH -tip v2 5/6] perf script: add the offset field specifier David Ahern
2011-07-17 9:31 ` [PATCH -tip v2 6/6] perf script: add option resolving vmlinux path Akihiro Nagai
2011-07-17 16:36 ` David Ahern
2011-07-21 9:36 ` Akihiro Nagai
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=20110717093109.3447.20340.stgit@linux3 \
--to=akihiro.nagai.hw@hitachi.com \
--cc=acme@infradead.org \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=yrl.pp-manager.tt@hitachi.com \
/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