OMAP3 SRF: Update OMAP-PM layer
[linux-ginger.git] / tools / perf / util / map.c
blob804e023827391f2ada3dfcac8a280a2d5d085aed
1 #include "event.h"
2 #include "symbol.h"
3 #include <stdlib.h>
4 #include <string.h>
5 #include <stdio.h>
7 static inline int is_anon_memory(const char *filename)
9 return strcmp(filename, "//anon") == 0;
12 static int strcommon(const char *pathname, char *cwd, int cwdlen)
14 int n = 0;
16 while (n < cwdlen && pathname[n] == cwd[n])
17 ++n;
19 return n;
22 struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
24 struct map *self = malloc(sizeof(*self));
26 if (self != NULL) {
27 const char *filename = event->filename;
28 char newfilename[PATH_MAX];
29 int anon;
31 if (cwd) {
32 int n = strcommon(filename, cwd, cwdlen);
34 if (n == cwdlen) {
35 snprintf(newfilename, sizeof(newfilename),
36 ".%s", filename + n);
37 filename = newfilename;
41 anon = is_anon_memory(filename);
43 if (anon) {
44 snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid);
45 filename = newfilename;
48 self->start = event->start;
49 self->end = event->start + event->len;
50 self->pgoff = event->pgoff;
52 self->dso = dsos__findnew(filename);
53 if (self->dso == NULL)
54 goto out_delete;
56 if (self->dso == vdso || anon)
57 self->map_ip = vdso__map_ip;
58 else
59 self->map_ip = map__map_ip;
61 return self;
62 out_delete:
63 free(self);
64 return NULL;
67 struct map *map__clone(struct map *self)
69 struct map *map = malloc(sizeof(*self));
71 if (!map)
72 return NULL;
74 memcpy(map, self, sizeof(*self));
76 return map;
79 int map__overlap(struct map *l, struct map *r)
81 if (l->start > r->start) {
82 struct map *t = l;
83 l = r;
84 r = t;
87 if (l->end > r->start)
88 return 1;
90 return 0;
93 size_t map__fprintf(struct map *self, FILE *fp)
95 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
96 self->start, self->end, self->pgoff, self->dso->name);