aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-08-12 05:07:25 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2009-08-12 06:37:37 -0400
commit66e274f3b8d7fc89d38997e85b900e188f8d5cc0 (patch)
tree5a0de899b891b2ce8440d2a3275b4ae7cb88b6c3 /tools/perf/util
parent1fe2c1066ce6a30bda7b27785ee3d9b8e62ffbbd (diff)
perf tools: Factorize the map helpers
Factorize the dso mapping helpers into a single purpose common file "util/map.c" Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Brice Goglin <Brice.Goglin@inria.fr>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/callchain.h1
-rw-r--r--tools/perf/util/event.h30
-rw-r--r--tools/perf/util/map.c97
-rw-r--r--tools/perf/util/symbol.h1
-rw-r--r--tools/perf/util/util.h1
5 files changed, 129 insertions, 1 deletions
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index a926ae4f5a16..43cf3ea9e088 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -4,6 +4,7 @@
4#include "../perf.h" 4#include "../perf.h"
5#include <linux/list.h> 5#include <linux/list.h>
6#include <linux/rbtree.h> 6#include <linux/rbtree.h>
7#include "util.h"
7#include "symbol.h" 8#include "symbol.h"
8 9
9enum chain_mode { 10enum chain_mode {
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 91e2fe589f27..d26dc887ce52 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -1,4 +1,8 @@
1#ifndef __PERF_EVENT_H
2#define __PERF_EVENT_H
1#include "../perf.h" 3#include "../perf.h"
4#include "util.h"
5#include <linux/list.h>
2 6
3struct ip_event { 7struct ip_event {
4 struct perf_event_header header; 8 struct perf_event_header header;
@@ -52,3 +56,29 @@ typedef union event_union {
52 struct lost_event lost; 56 struct lost_event lost;
53 struct read_event read; 57 struct read_event read;
54} event_t; 58} event_t;
59
60struct map {
61 struct list_head node;
62 u64 start;
63 u64 end;
64 u64 pgoff;
65 u64 (*map_ip)(struct map *, u64);
66 struct dso *dso;
67};
68
69static inline u64 map__map_ip(struct map *map, u64 ip)
70{
71 return ip - map->start + map->pgoff;
72}
73
74static inline u64 vdso__map_ip(struct map *map __used, u64 ip)
75{
76 return ip;
77}
78
79struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen);
80struct map *map__clone(struct map *self);
81int map__overlap(struct map *l, struct map *r);
82size_t map__fprintf(struct map *self, FILE *fp);
83
84#endif
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
new file mode 100644
index 000000000000..804e02382739
--- /dev/null
+++ b/tools/perf/util/map.c
@@ -0,0 +1,97 @@
1#include "event.h"
2#include "symbol.h"
3#include <stdlib.h>
4#include <string.h>
5#include <stdio.h>
6
7static inline int is_anon_memory(const char *filename)
8{
9 return strcmp(filename, "//anon") == 0;
10}
11
12static int strcommon(const char *pathname, char *cwd, int cwdlen)
13{
14 int n = 0;
15
16 while (n < cwdlen && pathname[n] == cwd[n])
17 ++n;
18
19 return n;
20}
21
22 struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
23{
24 struct map *self = malloc(sizeof(*self));
25
26 if (self != NULL) {
27 const char *filename = event->filename;
28 char newfilename[PATH_MAX];
29 int anon;
30
31 if (cwd) {
32 int n = strcommon(filename, cwd, cwdlen);
33
34 if (n == cwdlen) {
35 snprintf(newfilename, sizeof(newfilename),
36 ".%s", filename + n);
37 filename = newfilename;
38 }
39 }
40
41 anon = is_anon_memory(filename);
42
43 if (anon) {
44 snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid);
45 filename = newfilename;
46 }
47
48 self->start = event->start;
49 self->end = event->start + event->len;
50 self->pgoff = event->pgoff;
51
52 self->dso = dsos__findnew(filename);
53 if (self->dso == NULL)
54 goto out_delete;
55
56 if (self->dso == vdso || anon)
57 self->map_ip = vdso__map_ip;
58 else
59 self->map_ip = map__map_ip;
60 }
61 return self;
62out_delete:
63 free(self);
64 return NULL;
65}
66
67struct map *map__clone(struct map *self)
68{
69 struct map *map = malloc(sizeof(*self));
70
71 if (!map)
72 return NULL;
73
74 memcpy(map, self, sizeof(*self));
75
76 return map;
77}
78
79int map__overlap(struct map *l, struct map *r)
80{
81 if (l->start > r->start) {
82 struct map *t = l;
83 l = r;
84 r = t;
85 }
86
87 if (l->end > r->start)
88 return 1;
89
90 return 0;
91}
92
93size_t map__fprintf(struct map *self, FILE *fp)
94{
95 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
96 self->start, self->end, self->pgoff, self->dso->name);
97}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index f3490fcd40ee..50f723571241 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -6,6 +6,7 @@
6#include <linux/list.h> 6#include <linux/list.h>
7#include <linux/rbtree.h> 7#include <linux/rbtree.h>
8#include "module.h" 8#include "module.h"
9#include "event.h"
9 10
10struct symbol { 11struct symbol {
11 struct rb_node rb_node; 12 struct rb_node rb_node;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index be4b52cca2c3..d61a6f037631 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -83,7 +83,6 @@
83#include <inttypes.h> 83#include <inttypes.h>
84#include "../../../include/linux/magic.h" 84#include "../../../include/linux/magic.h"
85 85
86#include "event.h"
87 86
88#ifndef NO_ICONV 87#ifndef NO_ICONV
89#include <iconv.h> 88#include <iconv.h>