aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-annotate.c
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/builtin-annotate.c
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/builtin-annotate.c')
-rw-r--r--tools/perf/builtin-annotate.c79
1 files changed, 1 insertions, 78 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index fee663adeea2..543c4524f8c2 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -51,83 +51,6 @@ struct sym_ext {
51 char *path; 51 char *path;
52}; 52};
53 53
54struct map {
55 struct list_head node;
56 u64 start;
57 u64 end;
58 u64 pgoff;
59 u64 (*map_ip)(struct map *, u64);
60 struct dso *dso;
61};
62
63static u64 map__map_ip(struct map *map, u64 ip)
64{
65 return ip - map->start + map->pgoff;
66}
67
68static u64 vdso__map_ip(struct map *map __used, u64 ip)
69{
70 return ip;
71}
72
73static struct map *map__new(struct mmap_event *event)
74{
75 struct map *self = malloc(sizeof(*self));
76
77 if (self != NULL) {
78 const char *filename = event->filename;
79
80 self->start = event->start;
81 self->end = event->start + event->len;
82 self->pgoff = event->pgoff;
83
84 self->dso = dsos__findnew(filename);
85 if (self->dso == NULL)
86 goto out_delete;
87
88 if (self->dso == vdso)
89 self->map_ip = vdso__map_ip;
90 else
91 self->map_ip = map__map_ip;
92 }
93 return self;
94out_delete:
95 free(self);
96 return NULL;
97}
98
99static struct map *map__clone(struct map *self)
100{
101 struct map *map = malloc(sizeof(*self));
102
103 if (!map)
104 return NULL;
105
106 memcpy(map, self, sizeof(*self));
107
108 return map;
109}
110
111static int map__overlap(struct map *l, struct map *r)
112{
113 if (l->start > r->start) {
114 struct map *t = l;
115 l = r;
116 r = t;
117 }
118
119 if (l->end > r->start)
120 return 1;
121
122 return 0;
123}
124
125static size_t map__fprintf(struct map *self, FILE *fp)
126{
127 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
128 self->start, self->end, self->pgoff, self->dso->name);
129}
130
131 54
132struct thread { 55struct thread {
133 struct rb_node rb_node; 56 struct rb_node rb_node;
@@ -797,7 +720,7 @@ static int
797process_mmap_event(event_t *event, unsigned long offset, unsigned long head) 720process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
798{ 721{
799 struct thread *thread = threads__findnew(event->mmap.pid); 722 struct thread *thread = threads__findnew(event->mmap.pid);
800 struct map *map = map__new(&event->mmap); 723 struct map *map = map__new(&event->mmap, NULL, 0);
801 724
802 dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", 725 dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
803 (void *)(offset + head), 726 (void *)(offset + head),