aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/hist.c2
-rw-r--r--tools/perf/util/map.c168
-rw-r--r--tools/perf/util/map.h11
-rw-r--r--tools/perf/util/thread.c169
4 files changed, 180 insertions, 170 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 09e09e78cb62..de3190102cc8 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -658,7 +658,7 @@ print_entries:
658 658
659 if (h->ms.map == NULL && verbose > 1) { 659 if (h->ms.map == NULL && verbose > 1) {
660 __map_groups__fprintf_maps(&h->thread->mg, 660 __map_groups__fprintf_maps(&h->thread->mg,
661 MAP__FUNCTION, fp); 661 MAP__FUNCTION, verbose, fp);
662 fprintf(fp, "%.10s end\n", graph_dotted_line); 662 fprintf(fp, "%.10s end\n", graph_dotted_line);
663 } 663 }
664 } 664 }
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 9f2963f9ee9a..e21f98001734 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -1,4 +1,5 @@
1#include "symbol.h" 1#include "symbol.h"
2#include <errno.h>
2#include <limits.h> 3#include <limits.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <string.h> 5#include <string.h>
@@ -234,6 +235,37 @@ u64 map__objdump_2ip(struct map *map, u64 addr)
234 return ip; 235 return ip;
235} 236}
236 237
238void map_groups__init(struct map_groups *self)
239{
240 int i;
241 for (i = 0; i < MAP__NR_TYPES; ++i) {
242 self->maps[i] = RB_ROOT;
243 INIT_LIST_HEAD(&self->removed_maps[i]);
244 }
245}
246
247void map_groups__flush(struct map_groups *self)
248{
249 int type;
250
251 for (type = 0; type < MAP__NR_TYPES; type++) {
252 struct rb_root *root = &self->maps[type];
253 struct rb_node *next = rb_first(root);
254
255 while (next) {
256 struct map *pos = rb_entry(next, struct map, rb_node);
257 next = rb_next(&pos->rb_node);
258 rb_erase(&pos->rb_node, root);
259 /*
260 * We may have references to this map, for
261 * instance in some hist_entry instances, so
262 * just move them to a separate list.
263 */
264 list_add_tail(&pos->node, &self->removed_maps[pos->type]);
265 }
266 }
267}
268
237struct symbol *map_groups__find_symbol(struct map_groups *self, 269struct symbol *map_groups__find_symbol(struct map_groups *self,
238 enum map_type type, u64 addr, 270 enum map_type type, u64 addr,
239 symbol_filter_t filter) 271 symbol_filter_t filter)
@@ -246,6 +278,142 @@ struct symbol *map_groups__find_symbol(struct map_groups *self,
246 return NULL; 278 return NULL;
247} 279}
248 280
281size_t __map_groups__fprintf_maps(struct map_groups *self,
282 enum map_type type, int verbose, FILE *fp)
283{
284 size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
285 struct rb_node *nd;
286
287 for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
288 struct map *pos = rb_entry(nd, struct map, rb_node);
289 printed += fprintf(fp, "Map:");
290 printed += map__fprintf(pos, fp);
291 if (verbose > 2) {
292 printed += dso__fprintf(pos->dso, type, fp);
293 printed += fprintf(fp, "--\n");
294 }
295 }
296
297 return printed;
298}
299
300size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp)
301{
302 size_t printed = 0, i;
303 for (i = 0; i < MAP__NR_TYPES; ++i)
304 printed += __map_groups__fprintf_maps(self, i, verbose, fp);
305 return printed;
306}
307
308static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
309 enum map_type type,
310 int verbose, FILE *fp)
311{
312 struct map *pos;
313 size_t printed = 0;
314
315 list_for_each_entry(pos, &self->removed_maps[type], node) {
316 printed += fprintf(fp, "Map:");
317 printed += map__fprintf(pos, fp);
318 if (verbose > 1) {
319 printed += dso__fprintf(pos->dso, type, fp);
320 printed += fprintf(fp, "--\n");
321 }
322 }
323 return printed;
324}
325
326static size_t map_groups__fprintf_removed_maps(struct map_groups *self,
327 int verbose, FILE *fp)
328{
329 size_t printed = 0, i;
330 for (i = 0; i < MAP__NR_TYPES; ++i)
331 printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp);
332 return printed;
333}
334
335size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp)
336{
337 size_t printed = map_groups__fprintf_maps(self, verbose, fp);
338 printed += fprintf(fp, "Removed maps:\n");
339 return printed + map_groups__fprintf_removed_maps(self, verbose, fp);
340}
341
342int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
343 int verbose, FILE *fp)
344{
345 struct rb_root *root = &self->maps[map->type];
346 struct rb_node *next = rb_first(root);
347
348 while (next) {
349 struct map *pos = rb_entry(next, struct map, rb_node);
350 next = rb_next(&pos->rb_node);
351
352 if (!map__overlap(pos, map))
353 continue;
354
355 if (verbose >= 2) {
356 fputs("overlapping maps:\n", fp);
357 map__fprintf(map, fp);
358 map__fprintf(pos, fp);
359 }
360
361 rb_erase(&pos->rb_node, root);
362 /*
363 * We may have references to this map, for instance in some
364 * hist_entry instances, so just move them to a separate
365 * list.
366 */
367 list_add_tail(&pos->node, &self->removed_maps[map->type]);
368 /*
369 * Now check if we need to create new maps for areas not
370 * overlapped by the new map:
371 */
372 if (map->start > pos->start) {
373 struct map *before = map__clone(pos);
374
375 if (before == NULL)
376 return -ENOMEM;
377
378 before->end = map->start - 1;
379 map_groups__insert(self, before);
380 if (verbose >= 2)
381 map__fprintf(before, fp);
382 }
383
384 if (map->end < pos->end) {
385 struct map *after = map__clone(pos);
386
387 if (after == NULL)
388 return -ENOMEM;
389
390 after->start = map->end + 1;
391 map_groups__insert(self, after);
392 if (verbose >= 2)
393 map__fprintf(after, fp);
394 }
395 }
396
397 return 0;
398}
399
400/*
401 * XXX This should not really _copy_ te maps, but refcount them.
402 */
403int map_groups__clone(struct map_groups *self,
404 struct map_groups *parent, enum map_type type)
405{
406 struct rb_node *nd;
407 for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) {
408 struct map *map = rb_entry(nd, struct map, rb_node);
409 struct map *new = map__clone(map);
410 if (new == NULL)
411 return -ENOMEM;
412 map_groups__insert(self, new);
413 }
414 return 0;
415}
416
249static u64 map__reloc_map_ip(struct map *map, u64 ip) 417static u64 map__reloc_map_ip(struct map *map, u64 ip)
250{ 418{
251 return ip + (s64)map->pgoff; 419 return ip + (s64)map->pgoff;
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 6a703fa74707..4e7a11da8ffe 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -97,11 +97,14 @@ struct map_groups {
97}; 97};
98 98
99size_t __map_groups__fprintf_maps(struct map_groups *self, 99size_t __map_groups__fprintf_maps(struct map_groups *self,
100 enum map_type type, FILE *fp); 100 enum map_type type, int verbose, FILE *fp);
101void maps__insert(struct rb_root *maps, struct map *map); 101void maps__insert(struct rb_root *maps, struct map *map);
102struct map *maps__find(struct rb_root *maps, u64 addr); 102struct map *maps__find(struct rb_root *maps, u64 addr);
103void map_groups__init(struct map_groups *self); 103void map_groups__init(struct map_groups *self);
104size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp); 104int map_groups__clone(struct map_groups *self,
105 struct map_groups *parent, enum map_type type);
106size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp);
107size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp);
105 108
106static inline void map_groups__insert(struct map_groups *self, struct map *map) 109static inline void map_groups__insert(struct map_groups *self, struct map *map)
107{ 110{
@@ -125,6 +128,9 @@ static inline struct symbol *map_groups__find_function(struct map_groups *self,
125 return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter); 128 return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter);
126} 129}
127 130
131int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
132 int verbose, FILE *fp);
133
128struct map *map_groups__find_by_name(struct map_groups *self, 134struct map *map_groups__find_by_name(struct map_groups *self,
129 enum map_type type, const char *name); 135 enum map_type type, const char *name);
130int __map_groups__create_kernel_maps(struct map_groups *self, 136int __map_groups__create_kernel_maps(struct map_groups *self,
@@ -134,5 +140,6 @@ int map_groups__create_kernel_maps(struct map_groups *self,
134 struct map *vmlinux_maps[MAP__NR_TYPES]); 140 struct map *vmlinux_maps[MAP__NR_TYPES]);
135struct map *map_groups__new_module(struct map_groups *self, u64 start, 141struct map *map_groups__new_module(struct map_groups *self, u64 start,
136 const char *filename); 142 const char *filename);
143void map_groups__flush(struct map_groups *self);
137 144
138#endif /* __PERF_MAP_H */ 145#endif /* __PERF_MAP_H */
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 9bbe27d75306..1f7ecd47f499 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -38,15 +38,6 @@ failure:
38 return ret; 38 return ret;
39} 39}
40 40
41void map_groups__init(struct map_groups *self)
42{
43 int i;
44 for (i = 0; i < MAP__NR_TYPES; ++i) {
45 self->maps[i] = RB_ROOT;
46 INIT_LIST_HEAD(&self->removed_maps[i]);
47 }
48}
49
50static struct thread *thread__new(pid_t pid) 41static struct thread *thread__new(pid_t pid)
51{ 42{
52 struct thread *self = zalloc(sizeof(*self)); 43 struct thread *self = zalloc(sizeof(*self));
@@ -62,28 +53,6 @@ static struct thread *thread__new(pid_t pid)
62 return self; 53 return self;
63} 54}
64 55
65static void map_groups__flush(struct map_groups *self)
66{
67 int type;
68
69 for (type = 0; type < MAP__NR_TYPES; type++) {
70 struct rb_root *root = &self->maps[type];
71 struct rb_node *next = rb_first(root);
72
73 while (next) {
74 struct map *pos = rb_entry(next, struct map, rb_node);
75 next = rb_next(&pos->rb_node);
76 rb_erase(&pos->rb_node, root);
77 /*
78 * We may have references to this map, for
79 * instance in some hist_entry instances, so
80 * just move them to a separate list.
81 */
82 list_add_tail(&pos->node, &self->removed_maps[pos->type]);
83 }
84 }
85}
86
87int thread__set_comm(struct thread *self, const char *comm) 56int thread__set_comm(struct thread *self, const char *comm)
88{ 57{
89 int err; 58 int err;
@@ -110,69 +79,10 @@ int thread__comm_len(struct thread *self)
110 return self->comm_len; 79 return self->comm_len;
111} 80}
112 81
113size_t __map_groups__fprintf_maps(struct map_groups *self,
114 enum map_type type, FILE *fp)
115{
116 size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
117 struct rb_node *nd;
118
119 for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
120 struct map *pos = rb_entry(nd, struct map, rb_node);
121 printed += fprintf(fp, "Map:");
122 printed += map__fprintf(pos, fp);
123 if (verbose > 2) {
124 printed += dso__fprintf(pos->dso, type, fp);
125 printed += fprintf(fp, "--\n");
126 }
127 }
128
129 return printed;
130}
131
132size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp)
133{
134 size_t printed = 0, i;
135 for (i = 0; i < MAP__NR_TYPES; ++i)
136 printed += __map_groups__fprintf_maps(self, i, fp);
137 return printed;
138}
139
140static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
141 enum map_type type, FILE *fp)
142{
143 struct map *pos;
144 size_t printed = 0;
145
146 list_for_each_entry(pos, &self->removed_maps[type], node) {
147 printed += fprintf(fp, "Map:");
148 printed += map__fprintf(pos, fp);
149 if (verbose > 1) {
150 printed += dso__fprintf(pos->dso, type, fp);
151 printed += fprintf(fp, "--\n");
152 }
153 }
154 return printed;
155}
156
157static size_t map_groups__fprintf_removed_maps(struct map_groups *self, FILE *fp)
158{
159 size_t printed = 0, i;
160 for (i = 0; i < MAP__NR_TYPES; ++i)
161 printed += __map_groups__fprintf_removed_maps(self, i, fp);
162 return printed;
163}
164
165static size_t map_groups__fprintf(struct map_groups *self, FILE *fp)
166{
167 size_t printed = map_groups__fprintf_maps(self, fp);
168 printed += fprintf(fp, "Removed maps:\n");
169 return printed + map_groups__fprintf_removed_maps(self, fp);
170}
171
172static size_t thread__fprintf(struct thread *self, FILE *fp) 82static size_t thread__fprintf(struct thread *self, FILE *fp)
173{ 83{
174 return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) + 84 return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) +
175 map_groups__fprintf(&self->mg, fp); 85 map_groups__fprintf(&self->mg, verbose, fp);
176} 86}
177 87
178struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) 88struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
@@ -214,87 +124,12 @@ struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
214 return th; 124 return th;
215} 125}
216 126
217static int map_groups__fixup_overlappings(struct map_groups *self,
218 struct map *map)
219{
220 struct rb_root *root = &self->maps[map->type];
221 struct rb_node *next = rb_first(root);
222
223 while (next) {
224 struct map *pos = rb_entry(next, struct map, rb_node);
225 next = rb_next(&pos->rb_node);
226
227 if (!map__overlap(pos, map))
228 continue;
229
230 if (verbose >= 2) {
231 fputs("overlapping maps:\n", stderr);
232 map__fprintf(map, stderr);
233 map__fprintf(pos, stderr);
234 }
235
236 rb_erase(&pos->rb_node, root);
237 /*
238 * We may have references to this map, for instance in some
239 * hist_entry instances, so just move them to a separate
240 * list.
241 */
242 list_add_tail(&pos->node, &self->removed_maps[map->type]);
243 /*
244 * Now check if we need to create new maps for areas not
245 * overlapped by the new map:
246 */
247 if (map->start > pos->start) {
248 struct map *before = map__clone(pos);
249
250 if (before == NULL)
251 return -ENOMEM;
252
253 before->end = map->start - 1;
254 map_groups__insert(self, before);
255 if (verbose >= 2)
256 map__fprintf(before, stderr);
257 }
258
259 if (map->end < pos->end) {
260 struct map *after = map__clone(pos);
261
262 if (after == NULL)
263 return -ENOMEM;
264
265 after->start = map->end + 1;
266 map_groups__insert(self, after);
267 if (verbose >= 2)
268 map__fprintf(after, stderr);
269 }
270 }
271
272 return 0;
273}
274
275void thread__insert_map(struct thread *self, struct map *map) 127void thread__insert_map(struct thread *self, struct map *map)
276{ 128{
277 map_groups__fixup_overlappings(&self->mg, map); 129 map_groups__fixup_overlappings(&self->mg, map, verbose, stderr);
278 map_groups__insert(&self->mg, map); 130 map_groups__insert(&self->mg, map);
279} 131}
280 132
281/*
282 * XXX This should not really _copy_ te maps, but refcount them.
283 */
284static int map_groups__clone(struct map_groups *self,
285 struct map_groups *parent, enum map_type type)
286{
287 struct rb_node *nd;
288 for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) {
289 struct map *map = rb_entry(nd, struct map, rb_node);
290 struct map *new = map__clone(map);
291 if (new == NULL)
292 return -ENOMEM;
293 map_groups__insert(self, new);
294 }
295 return 0;
296}
297
298int thread__fork(struct thread *self, struct thread *parent) 133int thread__fork(struct thread *self, struct thread *parent)
299{ 134{
300 int i; 135 int i;