* [PATCH tip 1/1] perf_counter tools: Shorten the DSO names using cwd
@ 2009-05-29 16:48 Arnaldo Carvalho de Melo
2009-05-29 17:16 ` [tip:perfcounters/core] " tip-bot for Arnaldo Carvalho de Melo
0 siblings, 1 reply; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2009-05-29 16:48 UTC (permalink / raw)
To: Ingo Molnar
Cc: Peter Zijlstra, Paul Mackerras, Mike Galbraith, Thomas Gleixner,
Steven Rostedt, Linux Kernel Mailing List
commit c33188d6cca8616c5bb9e1bbf95bc88cc3c1fa9c
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Fri May 29 13:43:08 2009 -0300
perf_counter tools: Shorten the DSO names using cwd
[acme@emilia linux-2.6-tip]$ pwd
/home/acme/git/linux-2.6-tip
Before (still available using -P/--full-paths)
[acme@emilia linux-2.6-tip]$ perf report -P | head -10
11.48% perf: 7454 [kernel]: clear_page_c
4.89% perf: 7454 [kernel]: vsnprintf
4.61% perf: 7454 /home/acme/git/linux-2.6-tip/Documentation/perf_counter/perf: dso__find_symbol
4.09% perf: 7454 [kernel]: number
4.06% perf: 7454 /home/acme/git/linux-2.6-tip/Documentation/perf_counter/perf: dso__fprintf
4.00% perf: 7454 /home/acme/git/linux-2.6-tip/Documentation/perf_counter/perf: symbol_filter
New default:
[acme@emilia linux-2.6-tip]$ perf report | head -10
11.48% perf: 7454 [kernel]: clear_page_c
4.89% perf: 7454 [kernel]: vsnprintf
4.61% perf: 7454 ./Documentation/perf_counter/perf: dso__find_symbol
4.09% perf: 7454 [kernel]: number
4.06% perf: 7454 ./Documentation/perf_counter/perf: dso__fprintf
4.00% perf: 7454 ./Documentation/perf_counter/perf: symbol_filter
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index 412d524..4705679 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -23,6 +23,7 @@ static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
static int dump_trace = 0;
static int verbose;
+static int full_paths;
static unsigned long page_size;
static unsigned long mmap_window = 32;
@@ -134,6 +135,16 @@ static int load_kernel(void)
return err;
}
+static int strcommon(const char *pathname, const char *cwd, int cwdlen)
+{
+ int n = 0;
+
+ while (pathname[n] == cwd[n] && n < cwdlen)
+ ++n;
+
+ return n;
+}
+
struct map {
struct list_head node;
uint64_t start;
@@ -142,16 +153,28 @@ struct map {
struct dso *dso;
};
-static struct map *map__new(struct mmap_event *event)
+static struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
{
struct map *self = malloc(sizeof(*self));
if (self != NULL) {
+ const char *filename = event->filename;
+ char newfilename[PATH_MAX];
+
+ if (cwd) {
+ int n = strcommon(filename, cwd, cwdlen);
+ if (n == cwdlen) {
+ snprintf(newfilename, sizeof(newfilename),
+ ".%s", filename + n);
+ filename = newfilename;
+ }
+ }
+
self->start = event->start;
self->end = event->start + event->len;
self->pgoff = event->pgoff;
- self->dso = dsos__findnew(event->filename);
+ self->dso = dsos__findnew(filename);
if (self->dso == NULL)
goto out_delete;
}
@@ -598,6 +621,8 @@ static int __cmd_report(void)
int ret, rc = EXIT_FAILURE;
uint32_t size;
unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0;
+ char cwd[PATH_MAX], *cwdp = cwd;
+ int cwdlen;
input = open(input_name, O_RDONLY);
if (input < 0) {
@@ -621,6 +646,14 @@ static int __cmd_report(void)
return EXIT_FAILURE;
}
+ if (!full_paths) {
+ if (getcwd(cwd, sizeof(cwd)) == NULL) {
+ perror("failed to get the current directory");
+ return EXIT_FAILURE;
+ }
+ cwdlen = strlen(cwd);
+ } else
+ cwdp = NULL;
remap:
buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
MAP_SHARED, input, offset);
@@ -710,7 +743,7 @@ more:
} else switch (event->header.type) {
case PERF_EVENT_MMAP: {
struct thread *thread = threads__findnew(event->mmap.pid);
- struct map *map = map__new(&event->mmap);
+ struct map *map = map__new(&event->mmap, cwdp, cwdlen);
if (dump_trace) {
fprintf(stderr, "%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n",
@@ -809,6 +842,8 @@ static const struct option options[] = {
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
"sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"),
+ OPT_BOOLEAN('P', "full-paths", &full_paths,
+ "Don't shorten the pathnames taking into account the cwd"),
OPT_END()
};
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip:perfcounters/core] perf_counter tools: Shorten the DSO names using cwd
2009-05-29 16:48 [PATCH tip 1/1] perf_counter tools: Shorten the DSO names using cwd Arnaldo Carvalho de Melo
@ 2009-05-29 17:16 ` tip-bot for Arnaldo Carvalho de Melo
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Arnaldo Carvalho de Melo @ 2009-05-29 17:16 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, acme, hpa, mingo, a.p.zijlstra, efault,
rostedt, tglx, mingo
Commit-ID: b78c07d45a7e71be7b5c5d7486f922355ccf23a8
Gitweb: http://git.kernel.org/tip/b78c07d45a7e71be7b5c5d7486f922355ccf23a8
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Fri, 29 May 2009 13:48:59 -0300
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 29 May 2009 19:14:08 +0200
perf_counter tools: Shorten the DSO names using cwd
[acme@emilia linux-2.6-tip]$ pwd
/home/acme/git/linux-2.6-tip
Before (still available using -P/--full-paths)
[acme@emilia linux-2.6-tip]$ perf report -P | head -10
11.48% perf: 7454 [kernel]: clear_page_c
4.89% perf: 7454 [kernel]: vsnprintf
4.61% perf: 7454 /home/acme/git/linux-2.6-tip/Documentation/perf_counter/perf: dso__find_symbol
4.09% perf: 7454 [kernel]: number
4.06% perf: 7454 /home/acme/git/linux-2.6-tip/Documentation/perf_counter/perf: dso__fprintf
4.00% perf: 7454 /home/acme/git/linux-2.6-tip/Documentation/perf_counter/perf: symbol_filter
New default:
[acme@emilia linux-2.6-tip]$ perf report | head -10
11.48% perf: 7454 [kernel]: clear_page_c
4.89% perf: 7454 [kernel]: vsnprintf
4.61% perf: 7454 ./Documentation/perf_counter/perf: dso__find_symbol
4.09% perf: 7454 [kernel]: number
4.06% perf: 7454 ./Documentation/perf_counter/perf: dso__fprintf
4.00% perf: 7454 ./Documentation/perf_counter/perf: symbol_filter
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090529164859.GN4747@ghostprotocols.net>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
Documentation/perf_counter/builtin-report.c | 41 +++++++++++++++++++++++++--
1 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index 412d524..4705679 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -23,6 +23,7 @@ static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
static int dump_trace = 0;
static int verbose;
+static int full_paths;
static unsigned long page_size;
static unsigned long mmap_window = 32;
@@ -134,6 +135,16 @@ static int load_kernel(void)
return err;
}
+static int strcommon(const char *pathname, const char *cwd, int cwdlen)
+{
+ int n = 0;
+
+ while (pathname[n] == cwd[n] && n < cwdlen)
+ ++n;
+
+ return n;
+}
+
struct map {
struct list_head node;
uint64_t start;
@@ -142,16 +153,28 @@ struct map {
struct dso *dso;
};
-static struct map *map__new(struct mmap_event *event)
+static struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
{
struct map *self = malloc(sizeof(*self));
if (self != NULL) {
+ const char *filename = event->filename;
+ char newfilename[PATH_MAX];
+
+ if (cwd) {
+ int n = strcommon(filename, cwd, cwdlen);
+ if (n == cwdlen) {
+ snprintf(newfilename, sizeof(newfilename),
+ ".%s", filename + n);
+ filename = newfilename;
+ }
+ }
+
self->start = event->start;
self->end = event->start + event->len;
self->pgoff = event->pgoff;
- self->dso = dsos__findnew(event->filename);
+ self->dso = dsos__findnew(filename);
if (self->dso == NULL)
goto out_delete;
}
@@ -598,6 +621,8 @@ static int __cmd_report(void)
int ret, rc = EXIT_FAILURE;
uint32_t size;
unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0;
+ char cwd[PATH_MAX], *cwdp = cwd;
+ int cwdlen;
input = open(input_name, O_RDONLY);
if (input < 0) {
@@ -621,6 +646,14 @@ static int __cmd_report(void)
return EXIT_FAILURE;
}
+ if (!full_paths) {
+ if (getcwd(cwd, sizeof(cwd)) == NULL) {
+ perror("failed to get the current directory");
+ return EXIT_FAILURE;
+ }
+ cwdlen = strlen(cwd);
+ } else
+ cwdp = NULL;
remap:
buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
MAP_SHARED, input, offset);
@@ -710,7 +743,7 @@ more:
} else switch (event->header.type) {
case PERF_EVENT_MMAP: {
struct thread *thread = threads__findnew(event->mmap.pid);
- struct map *map = map__new(&event->mmap);
+ struct map *map = map__new(&event->mmap, cwdp, cwdlen);
if (dump_trace) {
fprintf(stderr, "%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n",
@@ -809,6 +842,8 @@ static const struct option options[] = {
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
"sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"),
+ OPT_BOOLEAN('P', "full-paths", &full_paths,
+ "Don't shorten the pathnames taking into account the cwd"),
OPT_END()
};
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-05-29 17:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-29 16:48 [PATCH tip 1/1] perf_counter tools: Shorten the DSO names using cwd Arnaldo Carvalho de Melo
2009-05-29 17:16 ` [tip:perfcounters/core] " tip-bot for Arnaldo Carvalho de Melo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.