perf symbols: Add nr_events to symbol_conf

Since symbol__alloc_hists need it, to avoid passing it around in many
functions have it in the symbol_conf struct.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-cwv8ysvpywzjq4v3xtbd4zwv@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 18b55235
...@@ -43,10 +43,9 @@ static const char *sym_hist_filter; ...@@ -43,10 +43,9 @@ static const char *sym_hist_filter;
static const char *cpu_list; static const char *cpu_list;
static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
static int perf_evlist__add_sample(struct perf_evlist *evlist, static int perf_evsel__add_sample(struct perf_evsel *evsel,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct addr_location *al)
struct addr_location *al)
{ {
struct hist_entry *he; struct hist_entry *he;
int ret; int ret;
...@@ -69,8 +68,7 @@ static int perf_evlist__add_sample(struct perf_evlist *evlist, ...@@ -69,8 +68,7 @@ static int perf_evlist__add_sample(struct perf_evlist *evlist,
ret = 0; ret = 0;
if (he->ms.sym != NULL) { if (he->ms.sym != NULL) {
struct annotation *notes = symbol__annotation(he->ms.sym); struct annotation *notes = symbol__annotation(he->ms.sym);
if (notes->src == NULL && if (notes->src == NULL && symbol__alloc_hist(he->ms.sym) < 0)
symbol__alloc_hist(he->ms.sym, evlist->nr_entries) < 0)
return -ENOMEM; return -ENOMEM;
ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
...@@ -98,8 +96,7 @@ static int process_sample_event(union perf_event *event, ...@@ -98,8 +96,7 @@ static int process_sample_event(union perf_event *event,
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
return 0; return 0;
if (!al.filtered && if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al)) {
perf_evlist__add_sample(session->evlist, sample, evsel, &al)) {
pr_warning("problem incrementing symbol count, " pr_warning("problem incrementing symbol count, "
"skipping event\n"); "skipping event\n");
return -1; return -1;
...@@ -114,8 +111,7 @@ static int hist_entry__tty_annotate(struct hist_entry *he, int evidx) ...@@ -114,8 +111,7 @@ static int hist_entry__tty_annotate(struct hist_entry *he, int evidx)
print_line, full_paths, 0, 0); print_line, full_paths, 0, 0);
} }
static void hists__find_annotations(struct hists *self, int evidx, static void hists__find_annotations(struct hists *self, int evidx)
int nr_events)
{ {
struct rb_node *nd = rb_first(&self->entries), *next; struct rb_node *nd = rb_first(&self->entries), *next;
int key = K_RIGHT; int key = K_RIGHT;
...@@ -138,8 +134,7 @@ static void hists__find_annotations(struct hists *self, int evidx, ...@@ -138,8 +134,7 @@ static void hists__find_annotations(struct hists *self, int evidx,
} }
if (use_browser > 0) { if (use_browser > 0) {
key = hist_entry__tui_annotate(he, evidx, nr_events, key = hist_entry__tui_annotate(he, evidx, NULL, NULL, 0);
NULL, NULL, 0);
switch (key) { switch (key) {
case K_RIGHT: case K_RIGHT:
next = rb_next(nd); next = rb_next(nd);
...@@ -217,8 +212,7 @@ static int __cmd_annotate(void) ...@@ -217,8 +212,7 @@ static int __cmd_annotate(void)
total_nr_samples += nr_samples; total_nr_samples += nr_samples;
hists__collapse_resort(hists); hists__collapse_resort(hists);
hists__output_resort(hists); hists__output_resort(hists);
hists__find_annotations(hists, pos->idx, hists__find_annotations(hists, pos->idx);
session->evlist->nr_entries);
} }
} }
......
...@@ -92,8 +92,7 @@ static int perf_session__add_hist_entry(struct perf_session *session, ...@@ -92,8 +92,7 @@ static int perf_session__add_hist_entry(struct perf_session *session,
assert(evsel != NULL); assert(evsel != NULL);
err = -ENOMEM; err = -ENOMEM;
if (notes->src == NULL && if (notes->src == NULL && symbol__alloc_hist(he->ms.sym) < 0)
symbol__alloc_hist(he->ms.sym, session->evlist->nr_entries) < 0)
goto out; goto out;
err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
......
...@@ -170,7 +170,7 @@ static int parse_source(struct hist_entry *he) ...@@ -170,7 +170,7 @@ static int parse_source(struct hist_entry *he)
pthread_mutex_lock(&notes->lock); pthread_mutex_lock(&notes->lock);
if (symbol__alloc_hist(sym, top.evlist->nr_entries) < 0) { if (symbol__alloc_hist(sym) < 0) {
pthread_mutex_unlock(&notes->lock); pthread_mutex_unlock(&notes->lock);
pr_err("Not enough memory for annotating '%s' symbol!\n", pr_err("Not enough memory for annotating '%s' symbol!\n",
sym->name); sym->name);
...@@ -210,8 +210,7 @@ static void record_precise_ip(struct hist_entry *he, int counter, u64 ip) ...@@ -210,8 +210,7 @@ static void record_precise_ip(struct hist_entry *he, int counter, u64 ip)
if (pthread_mutex_trylock(&notes->lock)) if (pthread_mutex_trylock(&notes->lock))
return; return;
if (notes->src == NULL && if (notes->src == NULL && symbol__alloc_hist(sym) < 0) {
symbol__alloc_hist(sym, top.evlist->nr_entries) < 0) {
pthread_mutex_unlock(&notes->lock); pthread_mutex_unlock(&notes->lock);
pr_err("Not enough memory for annotating '%s' symbol!\n", pr_err("Not enough memory for annotating '%s' symbol!\n",
sym->name); sym->name);
...@@ -1215,6 +1214,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) ...@@ -1215,6 +1214,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
return -ENOMEM; return -ENOMEM;
} }
symbol_conf.nr_events = top.evlist->nr_entries;
if (top.delay_secs < 1) if (top.delay_secs < 1)
top.delay_secs = 1; top.delay_secs = 1;
......
...@@ -25,17 +25,17 @@ int symbol__annotate_init(struct map *map __used, struct symbol *sym) ...@@ -25,17 +25,17 @@ int symbol__annotate_init(struct map *map __used, struct symbol *sym)
return 0; return 0;
} }
int symbol__alloc_hist(struct symbol *sym, int nevents) int symbol__alloc_hist(struct symbol *sym)
{ {
struct annotation *notes = symbol__annotation(sym); struct annotation *notes = symbol__annotation(sym);
size_t sizeof_sym_hist = (sizeof(struct sym_hist) + size_t sizeof_sym_hist = (sizeof(struct sym_hist) +
(sym->end - sym->start) * sizeof(u64)); (sym->end - sym->start) * sizeof(u64));
notes->src = zalloc(sizeof(*notes->src) + nevents * sizeof_sym_hist); notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist);
if (notes->src == NULL) if (notes->src == NULL)
return -1; return -1;
notes->src->sizeof_sym_hist = sizeof_sym_hist; notes->src->sizeof_sym_hist = sizeof_sym_hist;
notes->src->nr_histograms = nevents; notes->src->nr_histograms = symbol_conf.nr_events;
INIT_LIST_HEAD(&notes->src->source); INIT_LIST_HEAD(&notes->src->source);
return 0; return 0;
} }
......
...@@ -72,7 +72,7 @@ static inline struct annotation *symbol__annotation(struct symbol *sym) ...@@ -72,7 +72,7 @@ static inline struct annotation *symbol__annotation(struct symbol *sym)
int symbol__inc_addr_samples(struct symbol *sym, struct map *map, int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
int evidx, u64 addr); int evidx, u64 addr);
int symbol__alloc_hist(struct symbol *sym, int nevents); int symbol__alloc_hist(struct symbol *sym);
void symbol__annotate_zero_histograms(struct symbol *sym); void symbol__annotate_zero_histograms(struct symbol *sym);
int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize); int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
...@@ -99,8 +99,7 @@ static inline int symbol__tui_annotate(struct symbol *sym __used, ...@@ -99,8 +99,7 @@ static inline int symbol__tui_annotate(struct symbol *sym __used,
} }
#else #else
int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
int nr_events, void(*timer)(void *arg), void *arg, void(*timer)(void *arg), void *arg, int delay_secs);
int delay_secs);
#endif #endif
extern const char *disassembler_style; extern const char *disassembler_style;
......
...@@ -2041,6 +2041,8 @@ int perf_session__read_header(struct perf_session *session, int fd) ...@@ -2041,6 +2041,8 @@ int perf_session__read_header(struct perf_session *session, int fd)
lseek(fd, tmp, SEEK_SET); lseek(fd, tmp, SEEK_SET);
} }
symbol_conf.nr_events = nr_attrs;
if (f_header.event_types.size) { if (f_header.event_types.size) {
lseek(fd, f_header.event_types.offset, SEEK_SET); lseek(fd, f_header.event_types.offset, SEEK_SET);
events = malloc(f_header.event_types.size); events = malloc(f_header.event_types.size);
......
...@@ -119,7 +119,6 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __used, ...@@ -119,7 +119,6 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __used,
static inline int hist_entry__tui_annotate(struct hist_entry *self __used, static inline int hist_entry__tui_annotate(struct hist_entry *self __used,
int evidx __used, int evidx __used,
int nr_events __used,
void(*timer)(void *arg) __used, void(*timer)(void *arg) __used,
void *arg __used, void *arg __used,
int delay_secs __used) int delay_secs __used)
...@@ -130,7 +129,7 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self __used, ...@@ -130,7 +129,7 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self __used,
#define K_RIGHT -2 #define K_RIGHT -2
#else #else
#include "ui/keysyms.h" #include "ui/keysyms.h"
int hist_entry__tui_annotate(struct hist_entry *he, int evidx, int nr_events, int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
void(*timer)(void *arg), void *arg, int delay_secs); void(*timer)(void *arg), void *arg, int delay_secs);
int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
......
...@@ -68,6 +68,7 @@ struct strlist; ...@@ -68,6 +68,7 @@ struct strlist;
struct symbol_conf { struct symbol_conf {
unsigned short priv_size; unsigned short priv_size;
unsigned short nr_events;
bool try_vmlinux_path, bool try_vmlinux_path,
use_modules, use_modules,
sort_by_name, sort_by_name,
......
...@@ -224,7 +224,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) ...@@ -224,7 +224,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
} }
static int annotate_browser__run(struct annotate_browser *self, int evidx, static int annotate_browser__run(struct annotate_browser *self, int evidx,
int nr_events, void(*timer)(void *arg), void(*timer)(void *arg),
void *arg, int delay_secs) void *arg, int delay_secs)
{ {
struct rb_node *nd = NULL; struct rb_node *nd = NULL;
...@@ -328,8 +328,7 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, ...@@ -328,8 +328,7 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
notes = symbol__annotation(target); notes = symbol__annotation(target);
pthread_mutex_lock(&notes->lock); pthread_mutex_lock(&notes->lock);
if (notes->src == NULL && if (notes->src == NULL && symbol__alloc_hist(target) < 0) {
symbol__alloc_hist(target, nr_events) < 0) {
pthread_mutex_unlock(&notes->lock); pthread_mutex_unlock(&notes->lock);
ui__warning("Not enough memory for annotating '%s' symbol!\n", ui__warning("Not enough memory for annotating '%s' symbol!\n",
target->name); target->name);
...@@ -337,7 +336,7 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, ...@@ -337,7 +336,7 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
} }
pthread_mutex_unlock(&notes->lock); pthread_mutex_unlock(&notes->lock);
symbol__tui_annotate(target, ms->map, evidx, nr_events, symbol__tui_annotate(target, ms->map, evidx,
timer, arg, delay_secs); timer, arg, delay_secs);
} }
continue; continue;
...@@ -358,15 +357,15 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, ...@@ -358,15 +357,15 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
return key; return key;
} }
int hist_entry__tui_annotate(struct hist_entry *he, int evidx, int nr_events, int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
void(*timer)(void *arg), void *arg, int delay_secs) void(*timer)(void *arg), void *arg, int delay_secs)
{ {
return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, nr_events, return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx,
timer, arg, delay_secs); timer, arg, delay_secs);
} }
int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
int nr_events, void(*timer)(void *arg), void *arg, void(*timer)(void *arg), void *arg,
int delay_secs) int delay_secs)
{ {
struct objdump_line *pos, *n; struct objdump_line *pos, *n;
...@@ -419,8 +418,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, ...@@ -419,8 +418,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
browser.b.nr_entries = browser.nr_entries; browser.b.nr_entries = browser.nr_entries;
browser.b.entries = &notes->src->source, browser.b.entries = &notes->src->source,
browser.b.width += 18; /* Percentage */ browser.b.width += 18; /* Percentage */
ret = annotate_browser__run(&browser, evidx, nr_events, ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs);
timer, arg, delay_secs);
list_for_each_entry_safe(pos, n, &notes->src->source, node) { list_for_each_entry_safe(pos, n, &notes->src->source, node) {
list_del(&pos->node); list_del(&pos->node);
objdump_line__free(pos); objdump_line__free(pos);
......
...@@ -1020,7 +1020,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -1020,7 +1020,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
* Don't let this be freed, say, by hists__decay_entry. * Don't let this be freed, say, by hists__decay_entry.
*/ */
he->used = true; he->used = true;
err = hist_entry__tui_annotate(he, evsel->idx, nr_events, err = hist_entry__tui_annotate(he, evsel->idx,
timer, arg, delay_secs); timer, arg, delay_secs);
he->used = false; he->used = false;
ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment