aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/perf_counter/builtin-report.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index 412d524dd658..4705679debae 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;
23 23
24static int dump_trace = 0; 24static int dump_trace = 0;
25static int verbose; 25static int verbose;
26static int full_paths;
26 27
27static unsigned long page_size; 28static unsigned long page_size;
28static unsigned long mmap_window = 32; 29static unsigned long mmap_window = 32;
@@ -134,6 +135,16 @@ static int load_kernel(void)
134 return err; 135 return err;
135} 136}
136 137
138static int strcommon(const char *pathname, const char *cwd, int cwdlen)
139{
140 int n = 0;
141
142 while (pathname[n] == cwd[n] && n < cwdlen)
143 ++n;
144
145 return n;
146}
147
137struct map { 148struct map {
138 struct list_head node; 149 struct list_head node;
139 uint64_t start; 150 uint64_t start;
@@ -142,16 +153,28 @@ struct map {
142 struct dso *dso; 153 struct dso *dso;
143}; 154};
144 155
145static struct map *map__new(struct mmap_event *event) 156static struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
146{ 157{
147 struct map *self = malloc(sizeof(*self)); 158 struct map *self = malloc(sizeof(*self));
148 159
149 if (self != NULL) { 160 if (self != NULL) {
161 const char *filename = event->filename;
162 char newfilename[PATH_MAX];
163
164 if (cwd) {
165 int n = strcommon(filename, cwd, cwdlen);
166 if (n == cwdlen) {
167 snprintf(newfilename, sizeof(newfilename),
168 ".%s", filename + n);
169 filename = newfilename;
170 }
171 }
172
150 self->start = event->start; 173 self->start = event->start;
151 self->end = event->start + event->len; 174 self->end = event->start + event->len;
152 self->pgoff = event->pgoff; 175 self->pgoff = event->pgoff;
153 176
154 self->dso = dsos__findnew(event->filename); 177 self->dso = dsos__findnew(filename);
155 if (self->dso == NULL) 178 if (self->dso == NULL)
156 goto out_delete; 179 goto out_delete;
157 } 180 }
@@ -598,6 +621,8 @@ static int __cmd_report(void)
598 int ret, rc = EXIT_FAILURE; 621 int ret, rc = EXIT_FAILURE;
599 uint32_t size; 622 uint32_t size;
600 unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0; 623 unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0;
624 char cwd[PATH_MAX], *cwdp = cwd;
625 int cwdlen;
601 626
602 input = open(input_name, O_RDONLY); 627 input = open(input_name, O_RDONLY);
603 if (input < 0) { 628 if (input < 0) {
@@ -621,6 +646,14 @@ static int __cmd_report(void)
621 return EXIT_FAILURE; 646 return EXIT_FAILURE;
622 } 647 }
623 648
649 if (!full_paths) {
650 if (getcwd(cwd, sizeof(cwd)) == NULL) {
651 perror("failed to get the current directory");
652 return EXIT_FAILURE;
653 }
654 cwdlen = strlen(cwd);
655 } else
656 cwdp = NULL;
624remap: 657remap:
625 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, 658 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
626 MAP_SHARED, input, offset); 659 MAP_SHARED, input, offset);
@@ -710,7 +743,7 @@ more:
710 } else switch (event->header.type) { 743 } else switch (event->header.type) {
711 case PERF_EVENT_MMAP: { 744 case PERF_EVENT_MMAP: {
712 struct thread *thread = threads__findnew(event->mmap.pid); 745 struct thread *thread = threads__findnew(event->mmap.pid);
713 struct map *map = map__new(&event->mmap); 746 struct map *map = map__new(&event->mmap, cwdp, cwdlen);
714 747
715 if (dump_trace) { 748 if (dump_trace) {
716 fprintf(stderr, "%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n", 749 fprintf(stderr, "%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n",
@@ -809,6 +842,8 @@ static const struct option options[] = {
809 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), 842 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
810 OPT_STRING('s', "sort", &sort_order, "key[,key2...]", 843 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
811 "sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"), 844 "sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"),
845 OPT_BOOLEAN('P', "full-paths", &full_paths,
846 "Don't shorten the pathnames taking into account the cwd"),
812 OPT_END() 847 OPT_END()
813}; 848};
814 849