Skip to content

Commit

Permalink
perf tools: Simplify the symbol priv area mechanism
Browse files Browse the repository at this point in the history
Before we were storing this in the DSO, but in fact this is a
property of the 'symbol' class, not something that will vary
among DSOs, so move it to a global variable and initialize it
using the existing symbol__init routine.

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-2-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Nov 2, 2009
1 parent afb7b4f commit 00a192b
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 80 deletions.
21 changes: 10 additions & 11 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ struct sym_priv {

static const char *sym_hist_filter;

static int symbol_filter(struct map *map, struct symbol *sym)
static int symbol_filter(struct map *map __used, struct symbol *sym)
{
if (sym_hist_filter == NULL ||
strcmp(sym->name, sym_hist_filter) == 0) {
struct sym_priv *priv = dso__sym_priv(map->dso, sym);
struct sym_priv *priv = symbol__priv(sym);
const int size = (sizeof(*priv->hist) +
(sym->end - sym->start) * sizeof(u64));

Expand Down Expand Up @@ -92,7 +92,7 @@ static void hist_hit(struct hist_entry *he, u64 ip)
if (!sym || !he->map)
return;

priv = dso__sym_priv(he->map->dso, sym);
priv = symbol__priv(sym);
if (!priv->hist)
return;

Expand Down Expand Up @@ -202,8 +202,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
static int
process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
{
struct map *map = map__new(&event->mmap, NULL, 0,
sizeof(struct sym_priv));
struct map *map = map__new(&event->mmap, NULL, 0);
struct thread *thread = threads__findnew(event->mmap.pid);

dump_printf("%p [%p]: PERF_RECORD_MMAP %d: [%p(%p) @ %p]: %s\n",
Expand Down Expand Up @@ -355,7 +354,7 @@ static int parse_line(FILE *file, struct hist_entry *he, u64 len)
unsigned int hits = 0;
double percent = 0.0;
const char *color;
struct sym_priv *priv = dso__sym_priv(he->map->dso, sym);
struct sym_priv *priv = symbol__priv(sym);
struct sym_ext *sym_ext = priv->ext;
struct sym_hist *h = priv->hist;

Expand Down Expand Up @@ -422,7 +421,7 @@ static void insert_source_line(struct sym_ext *sym_ext)

static void free_source_line(struct hist_entry *he, int len)
{
struct sym_priv *priv = dso__sym_priv(he->map->dso, he->sym);
struct sym_priv *priv = symbol__priv(he->sym);
struct sym_ext *sym_ext = priv->ext;
int i;

Expand All @@ -446,7 +445,7 @@ get_source_line(struct hist_entry *he, int len, const char *filename)
int i;
char cmd[PATH_MAX * 2];
struct sym_ext *sym_ext;
struct sym_priv *priv = dso__sym_priv(he->map->dso, sym);
struct sym_priv *priv = symbol__priv(sym);
struct sym_hist *h = priv->hist;

if (!h->sum)
Expand Down Expand Up @@ -589,7 +588,7 @@ static void find_annotations(void)
if (he->sym == NULL)
continue;

priv = dso__sym_priv(he->map->dso, he->sym);
priv = symbol__priv(he->sym);
if (priv->hist == NULL)
continue;

Expand Down Expand Up @@ -637,7 +636,7 @@ static int __cmd_annotate(void)
exit(0);
}

if (load_kernel(sizeof(struct sym_priv), symbol_filter) < 0) {
if (load_kernel(symbol_filter) < 0) {
perror("failed to load kernel symbols");
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -769,7 +768,7 @@ static void setup_sorting(void)

int cmd_annotate(int argc, const char **argv, const char *prefix __used)
{
symbol__init();
symbol__init(sizeof(struct sym_priv));

page_size = getpagesize();

Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
static int
process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
{
struct map *map = map__new(&event->mmap, cwd, cwdlen, 0);
struct map *map = map__new(&event->mmap, cwd, cwdlen);
struct thread *thread = threads__findnew(event->mmap.pid);

dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
Expand Down Expand Up @@ -1093,7 +1093,7 @@ static void setup_list(struct strlist **list, const char *list_str,

int cmd_report(int argc, const char **argv, const char *prefix __used)
{
symbol__init();
symbol__init(0);

argc = parse_options(argc, argv, options, report_usage, 0);

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ static int __cmd_record(int argc, const char **argv)

int cmd_sched(int argc, const char **argv, const char *prefix __used)
{
symbol__init();
symbol__init(0);

argc = parse_options(argc, argv, sched_options, sched_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ static const struct option options[] = {

int cmd_timechart(int argc, const char **argv, const char *prefix __used)
{
symbol__init();
symbol__init(0);

page_size = getpagesize();

Expand Down
12 changes: 5 additions & 7 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ static int symbol_filter(struct map *map, struct symbol *sym)
strstr(name, "_text_end"))
return 1;

syme = dso__sym_priv(map->dso, sym);
syme = symbol__priv(sym);
syme->map = map;
pthread_mutex_init(&syme->source_lock, NULL);
if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter))
Expand All @@ -807,8 +807,7 @@ static int symbol_filter(struct map *map, struct symbol *sym)

static int parse_symbols(void)
{
if (dsos__load_kernel(vmlinux_name, sizeof(struct sym_entry),
symbol_filter, 1) <= 0)
if (dsos__load_kernel(vmlinux_name, symbol_filter, 1) <= 0)
return -1;

if (dump_symtab)
Expand Down Expand Up @@ -859,7 +858,7 @@ static void event__process_sample(const event_t *self, int counter)
return;
}

syme = dso__sym_priv(map->dso, sym);
syme = symbol__priv(sym);

if (!syme->skip) {
syme->count[counter]++;
Expand All @@ -878,8 +877,7 @@ static void event__process_mmap(event_t *self)
struct thread *thread = threads__findnew(self->mmap.pid);

if (thread != NULL) {
struct map *map = map__new(&self->mmap, NULL, 0,
sizeof(struct sym_entry));
struct map *map = map__new(&self->mmap, NULL, 0);
if (map != NULL)
thread__insert_map(thread, map);
}
Expand Down Expand Up @@ -1176,7 +1174,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
{
int counter;

symbol__init();
symbol__init(sizeof(struct sym_entry));

page_size = sysconf(_SC_PAGE_SIZE);

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static const struct option options[] = {

int cmd_trace(int argc, const char **argv, const char *prefix __used)
{
symbol__init();
symbol__init(0);

argc = parse_options(argc, argv, options, annotate_usage, 0);
if (argc) {
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/data_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int mmap_dispatch_perf_file(struct perf_header **pheader,
if (curr_handler->sample_type_check(sample_type) < 0)
exit(-1);

if (load_kernel(0, NULL) < 0) {
if (load_kernel(NULL) < 0) {
perror("failed to load kernel symbols");
return EXIT_FAILURE;
}
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ 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__new(struct mmap_event *event, char *cwd, int cwdlen);
struct map *map__clone(struct map *self);
int map__overlap(struct map *l, struct map *r);
size_t map__fprintf(struct map *self, FILE *fp);
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/util/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ void map__init(struct map *self, u64 start, u64 end, u64 pgoff,
RB_CLEAR_NODE(&self->rb_node);
}

struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
unsigned int sym_priv_size)
struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
{
struct map *self = malloc(sizeof(*self));

Expand All @@ -60,7 +59,7 @@ struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
filename = newfilename;
}

dso = dsos__findnew(filename, sym_priv_size);
dso = dsos__findnew(filename);
if (dso == NULL)
goto out_delete;

Expand Down
Loading

0 comments on commit 00a192b

Please sign in to comment.