Skip to content

Commit

Permalink
perf top: Allocate space only for the number of counters used
Browse files Browse the repository at this point in the history
Reducing memory consumption on a typical desktop machine:

From:

32710 root      20   0  172m 142m 1056 S  0.0  4.7   0:00.37
perf

To:

  420 root      20   0 47528  16m 1056 R  0.3  0.5   0:00.24 perf

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
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>
LKML-Reference: <1258490282-1821-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 19, 2009
1 parent 51a472d commit 5a8e5a3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ static int display_weighted = -1;
struct sym_entry {
struct rb_node rb_node;
struct list_head node;
unsigned long count[MAX_COUNTERS];
unsigned long snap_count;
double weight;
int skip;
Expand All @@ -122,6 +121,7 @@ struct sym_entry {
struct source_line *lines;
struct source_line **lines_tail;
pthread_mutex_t source_lock;
unsigned long count[0];
};

/*
Expand All @@ -130,7 +130,7 @@ struct sym_entry {

static inline struct symbol *sym_entry__symbol(struct sym_entry *self)
{
return (struct symbol *)(self + 1);
return ((void *)self) + symbol__priv_size;
}

static void get_term_dimensions(struct winsize *ws)
Expand Down Expand Up @@ -1314,8 +1314,6 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
{
int counter;

symbol__init(sizeof(struct sym_entry));

page_size = sysconf(_SC_PAGE_SIZE);

argc = parse_options(argc, argv, options, top_usage, 0);
Expand All @@ -1332,6 +1330,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
if (!nr_counters)
nr_counters = 1;

symbol__init(sizeof(struct sym_entry) +
(nr_counters + 1) * sizeof(unsigned long));

if (delay_secs < 1)
delay_secs = 1;

Expand Down

0 comments on commit 5a8e5a3

Please sign in to comment.