perf tools: Factor out the map initialization
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 30 Oct 2009 18:28:23 +0000 (16:28 -0200)
committerIngo Molnar <mingo@elte.hu>
Mon, 2 Nov 2009 15:52:11 +0000 (16:52 +0100)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <1256927305-4628-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/util/event.h
tools/perf/util/map.c
tools/perf/util/symbol.c

index 3064a05f0f522cdc3c66884a5a14ad77a4271cb2..4a158a01bb97b83fd7377d2132d14ace79f4b491 100644 (file)
@@ -105,6 +105,8 @@ struct symbol;
 
 typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
 
+void map__init(struct map *self, u64 start, u64 end, u64 pgoff,
+              struct dso *dso);
 struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
                     unsigned int sym_priv_size);
 struct map *map__clone(struct map *self);
index d302e513e0622b486ecfc55d343d064cada24ac2..3b7ce1bf9f8e8e8cacf54c616631fcdccfa42a4c 100644 (file)
@@ -20,6 +20,18 @@ static int strcommon(const char *pathname, char *cwd, int cwdlen)
        return n;
 }
 
+void map__init(struct map *self, u64 start, u64 end, u64 pgoff,
+              struct dso *dso)
+{
+       self->start    = start;
+       self->end      = end;
+       self->pgoff    = pgoff;
+       self->dso      = dso;
+       self->map_ip   = map__map_ip;
+       self->unmap_ip = map__unmap_ip;
+       RB_CLEAR_NODE(&self->rb_node);
+}
+
 struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
                     unsigned int sym_priv_size)
 {
@@ -28,6 +40,7 @@ struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
        if (self != NULL) {
                const char *filename = event->filename;
                char newfilename[PATH_MAX];
+               struct dso *dso;
                int anon;
 
                if (cwd) {
@@ -47,20 +60,15 @@ struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
                        filename = newfilename;
                }
 
-               self->start = event->start;
-               self->end   = event->start + event->len;
-               self->pgoff = event->pgoff;
-
-               self->dso = dsos__findnew(filename, sym_priv_size);
-               if (self->dso == NULL)
+               dso = dsos__findnew(filename, sym_priv_size);
+               if (dso == NULL)
                        goto out_delete;
 
+               map__init(self, event->start, event->start + event->len,
+                         event->pgoff, dso);
+
                if (self->dso == vdso || anon)
                        self->map_ip = self->unmap_ip = identity__map_ip;
-               else {
-                       self->map_ip = map__map_ip;
-                       self->unmap_ip = map__unmap_ip;
-               }
        }
        return self;
 out_delete:
index 0273d83f728f6645052b6200486dca2f3ec6b9aa..13677b5dbe5ec365738993e90f1d5178bda6ad69 100644 (file)
@@ -1132,18 +1132,12 @@ static struct map *map__new2(u64 start, struct dso *dso)
        struct map *self = malloc(sizeof(*self));
 
        if (self != NULL) {
-               self->start = start;
                /*
-                * Will be filled after we load all the symbols
+                * ->end will be filled after we load all the symbols
                 */
-               self->end = 0;
-
-               self->pgoff = 0;
-               self->dso = dso;
-               self->map_ip = map__map_ip;
-               self->unmap_ip = map__unmap_ip;
-               RB_CLEAR_NODE(&self->rb_node);
+               map__init(self, start, 0, 0, dso);
        }
+
        return self;
 }