Skip to content

Commit

Permalink
perf symbols: Move more map_groups methods to map.c
Browse files Browse the repository at this point in the history
While writing a standalone test app that uses the symbol system to
find kernel space symbols I noticed these also need to be moved.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Apr 2, 2010
1 parent 11164cd commit c6e718f
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 170 deletions.
2 changes: 1 addition & 1 deletion tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ size_t perf_session__fprintf_hists(struct rb_root *hists,

if (h->ms.map == NULL && verbose > 1) {
__map_groups__fprintf_maps(&h->thread->mg,
MAP__FUNCTION, fp);
MAP__FUNCTION, verbose, fp);
fprintf(fp, "%.10s end\n", graph_dotted_line);
}
}
Expand Down
168 changes: 168 additions & 0 deletions tools/perf/util/map.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "symbol.h"
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -234,6 +235,37 @@ u64 map__objdump_2ip(struct map *map, u64 addr)
return ip;
}

void map_groups__init(struct map_groups *self)
{
int i;
for (i = 0; i < MAP__NR_TYPES; ++i) {
self->maps[i] = RB_ROOT;
INIT_LIST_HEAD(&self->removed_maps[i]);
}
}

void map_groups__flush(struct map_groups *self)
{
int type;

for (type = 0; type < MAP__NR_TYPES; type++) {
struct rb_root *root = &self->maps[type];
struct rb_node *next = rb_first(root);

while (next) {
struct map *pos = rb_entry(next, struct map, rb_node);
next = rb_next(&pos->rb_node);
rb_erase(&pos->rb_node, root);
/*
* We may have references to this map, for
* instance in some hist_entry instances, so
* just move them to a separate list.
*/
list_add_tail(&pos->node, &self->removed_maps[pos->type]);
}
}
}

struct symbol *map_groups__find_symbol(struct map_groups *self,
enum map_type type, u64 addr,
symbol_filter_t filter)
Expand All @@ -246,6 +278,142 @@ struct symbol *map_groups__find_symbol(struct map_groups *self,
return NULL;
}

size_t __map_groups__fprintf_maps(struct map_groups *self,
enum map_type type, int verbose, FILE *fp)
{
size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
struct rb_node *nd;

for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
struct map *pos = rb_entry(nd, struct map, rb_node);
printed += fprintf(fp, "Map:");
printed += map__fprintf(pos, fp);
if (verbose > 2) {
printed += dso__fprintf(pos->dso, type, fp);
printed += fprintf(fp, "--\n");
}
}

return printed;
}

size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp)
{
size_t printed = 0, i;
for (i = 0; i < MAP__NR_TYPES; ++i)
printed += __map_groups__fprintf_maps(self, i, verbose, fp);
return printed;
}

static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
enum map_type type,
int verbose, FILE *fp)
{
struct map *pos;
size_t printed = 0;

list_for_each_entry(pos, &self->removed_maps[type], node) {
printed += fprintf(fp, "Map:");
printed += map__fprintf(pos, fp);
if (verbose > 1) {
printed += dso__fprintf(pos->dso, type, fp);
printed += fprintf(fp, "--\n");
}
}
return printed;
}

static size_t map_groups__fprintf_removed_maps(struct map_groups *self,
int verbose, FILE *fp)
{
size_t printed = 0, i;
for (i = 0; i < MAP__NR_TYPES; ++i)
printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp);
return printed;
}

size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp)
{
size_t printed = map_groups__fprintf_maps(self, verbose, fp);
printed += fprintf(fp, "Removed maps:\n");
return printed + map_groups__fprintf_removed_maps(self, verbose, fp);
}

int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
int verbose, FILE *fp)
{
struct rb_root *root = &self->maps[map->type];
struct rb_node *next = rb_first(root);

while (next) {
struct map *pos = rb_entry(next, struct map, rb_node);
next = rb_next(&pos->rb_node);

if (!map__overlap(pos, map))
continue;

if (verbose >= 2) {
fputs("overlapping maps:\n", fp);
map__fprintf(map, fp);
map__fprintf(pos, fp);
}

rb_erase(&pos->rb_node, root);
/*
* We may have references to this map, for instance in some
* hist_entry instances, so just move them to a separate
* list.
*/
list_add_tail(&pos->node, &self->removed_maps[map->type]);
/*
* Now check if we need to create new maps for areas not
* overlapped by the new map:
*/
if (map->start > pos->start) {
struct map *before = map__clone(pos);

if (before == NULL)
return -ENOMEM;

before->end = map->start - 1;
map_groups__insert(self, before);
if (verbose >= 2)
map__fprintf(before, fp);
}

if (map->end < pos->end) {
struct map *after = map__clone(pos);

if (after == NULL)
return -ENOMEM;

after->start = map->end + 1;
map_groups__insert(self, after);
if (verbose >= 2)
map__fprintf(after, fp);
}
}

return 0;
}

/*
* XXX This should not really _copy_ te maps, but refcount them.
*/
int map_groups__clone(struct map_groups *self,
struct map_groups *parent, enum map_type type)
{
struct rb_node *nd;
for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) {
struct map *map = rb_entry(nd, struct map, rb_node);
struct map *new = map__clone(map);
if (new == NULL)
return -ENOMEM;
map_groups__insert(self, new);
}
return 0;
}

static u64 map__reloc_map_ip(struct map *map, u64 ip)
{
return ip + (s64)map->pgoff;
Expand Down
11 changes: 9 additions & 2 deletions tools/perf/util/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ struct map_groups {
};

size_t __map_groups__fprintf_maps(struct map_groups *self,
enum map_type type, FILE *fp);
enum map_type type, int verbose, FILE *fp);
void maps__insert(struct rb_root *maps, struct map *map);
struct map *maps__find(struct rb_root *maps, u64 addr);
void map_groups__init(struct map_groups *self);
size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp);
int map_groups__clone(struct map_groups *self,
struct map_groups *parent, enum map_type type);
size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp);
size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp);

static inline void map_groups__insert(struct map_groups *self, struct map *map)
{
Expand All @@ -125,6 +128,9 @@ static inline struct symbol *map_groups__find_function(struct map_groups *self,
return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter);
}

int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
int verbose, FILE *fp);

struct map *map_groups__find_by_name(struct map_groups *self,
enum map_type type, const char *name);
int __map_groups__create_kernel_maps(struct map_groups *self,
Expand All @@ -134,5 +140,6 @@ int map_groups__create_kernel_maps(struct map_groups *self,
struct map *vmlinux_maps[MAP__NR_TYPES]);
struct map *map_groups__new_module(struct map_groups *self, u64 start,
const char *filename);
void map_groups__flush(struct map_groups *self);

#endif /* __PERF_MAP_H */
Loading

0 comments on commit c6e718f

Please sign in to comment.