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)
16 while (n < cwdlen && pathname[n] == cwd[n])
22 struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
24 struct map *self = malloc(sizeof(*self));
27 const char *filename = event->filename;
28 char newfilename[PATH_MAX];
32 int n = strcommon(filename, cwd, cwdlen);
35 snprintf(newfilename, sizeof(newfilename),
37 filename = newfilename;
41 anon = is_anon_memory(filename);
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)
56 if (self->dso == vdso || anon)
57 self->map_ip = vdso__map_ip;
59 self->map_ip = map__map_ip;
67 struct map *map__clone(struct map *self)
69 struct map *map = malloc(sizeof(*self));
74 memcpy(map, self, sizeof(*self));
79 int map__overlap(struct map *l, struct map *r)
81 if (l->start > r->start) {
87 if (l->end > r->start)
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);