Skip to content

Commit

Permalink
perf browsers: Add live mode to the hists, annotate browsers
Browse files Browse the repository at this point in the history
This allows passing a timer to be run periodically, which will update
the hists tree that then gers refreshed on the screen, just like the
Live mode (symbol entries, annotation) we already have in 'perf top
--tui'.

Will be used by the new hist_entry/hists based 'top' tool.

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-2r44qd8oe4sagzcgoikl8qzc@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Oct 7, 2011
1 parent 1980c2e commit 81cce8d
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 56 deletions.
2 changes: 1 addition & 1 deletion tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void hists__find_annotations(struct hists *self, int evidx)
}

if (use_browser > 0) {
key = hist_entry__tui_annotate(he, evidx);
key = hist_entry__tui_annotate(he, evidx, NULL, NULL, 0);
switch (key) {
case KEY_RIGHT:
next = rb_next(nd);
Expand Down
7 changes: 4 additions & 3 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,10 @@ static int __cmd_report(void)
goto out_delete;
}

if (use_browser > 0)
perf_evlist__tui_browse_hists(session->evlist, help);
else
if (use_browser > 0) {
perf_evlist__tui_browse_hists(session->evlist, help,
NULL, NULL, 0);
} else
perf_evlist__tty_browse_hists(session->evlist, help);

out_delete:
Expand Down
7 changes: 5 additions & 2 deletions tools/perf/util/annotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
#ifdef NO_NEWT_SUPPORT
static inline int symbol__tui_annotate(struct symbol *sym __used,
struct map *map __used,
int evidx __used, int refresh __used)
int evidx __used,
void(*timer)(void *arg) __used,
void *arg __used, int delay_secs __used)
{
return 0;
}
#else
int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
int refresh);
void(*timer)(void *arg), void *arg,
int delay_secs);
#endif

extern const char *disassembler_style;
Expand Down
6 changes: 6 additions & 0 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,9 @@ bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
first = list_entry(evlist->entries.next, struct perf_evsel, node);
return first->attr.sample_id_all;
}

void perf_evlist__set_selected(struct perf_evlist *evlist,
struct perf_evsel *evsel)
{
evlist->selected = evsel;
}
4 changes: 4 additions & 0 deletions tools/perf/util/evlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct perf_evlist {
struct pollfd *pollfd;
struct thread_map *threads;
struct cpu_map *cpus;
struct perf_evsel *selected;
};

struct perf_evsel;
Expand Down Expand Up @@ -56,6 +57,9 @@ void perf_evlist__munmap(struct perf_evlist *evlist);
void perf_evlist__disable(struct perf_evlist *evlist);
void perf_evlist__enable(struct perf_evlist *evlist);

void perf_evlist__set_selected(struct perf_evlist *evlist,
struct perf_evsel *evsel);

static inline void perf_evlist__set_maps(struct perf_evlist *evlist,
struct cpu_map *cpus,
struct thread_map *threads)
Expand Down
14 changes: 10 additions & 4 deletions tools/perf/util/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,32 @@ struct perf_evlist;
#ifdef NO_NEWT_SUPPORT
static inline
int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __used,
const char *help __used)
const char *help __used, void(*timer)(void *arg) __used, void *arg,
int refresh __used)
{
return 0;
}

static inline int hist_entry__tui_annotate(struct hist_entry *self __used,
int evidx __used)
int evidx __used,
void(*timer)(void *arg) __used,
void *arg __used, int delay_secs __used);
{
return 0;
}
#define KEY_LEFT -1
#define KEY_RIGHT -2
#else
#include <newt.h>
int hist_entry__tui_annotate(struct hist_entry *self, int evidx);
int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
void(*timer)(void *arg), void *arg, int delay_secs);

#define KEY_LEFT NEWT_KEY_LEFT
#define KEY_RIGHT NEWT_KEY_RIGHT

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,
void(*timer)(void *arg), void *arg,
int refresh);
#endif

unsigned int hists__sort_list_width(struct hists *self);
Expand Down
25 changes: 16 additions & 9 deletions tools/perf/util/ui/browsers/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
}

static int annotate_browser__run(struct annotate_browser *self, int evidx,
int refresh)
void(*timer)(void *arg) __used, void *arg __used,
int delay_secs)
{
struct rb_node *nd = NULL;
struct symbol *sym = self->b.priv;
Expand All @@ -189,13 +190,13 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,

nd = self->curr_hot;

if (refresh != 0)
newtFormSetTimer(self->b.form, refresh);
if (delay_secs != 0)
newtFormSetTimer(self->b.form, delay_secs * 1000);

while (1) {
key = ui_browser__run(&self->b);

if (refresh != 0) {
if (delay_secs != 0) {
annotate_browser__calc_percent(self, evidx);
/*
* Current line focus got out of the list of most active
Expand All @@ -212,7 +213,10 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
* FIXME we need to check if it was
* es.reason == NEWT_EXIT_TIMER
*/
if (refresh != 0)
if (timer != NULL)
timer(arg);

if (delay_secs != 0)
symbol__annotate_decay_histogram(sym, evidx);
continue;
case NEWT_KEY_TAB:
Expand Down Expand Up @@ -246,13 +250,16 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
return key;
}

int hist_entry__tui_annotate(struct hist_entry *he, int evidx)
int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
void(*timer)(void *arg), void *arg, int delay_secs)
{
return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, 0);
return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx,
timer, arg, delay_secs);
}

int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
int refresh)
void(*timer)(void *arg), void *arg,
int delay_secs)
{
struct objdump_line *pos, *n;
struct annotation *notes;
Expand Down Expand Up @@ -293,7 +300,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,

browser.b.entries = &notes->src->source,
browser.b.width += 18; /* Percentage */
ret = annotate_browser__run(&browser, evidx, refresh);
ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs);
list_for_each_entry_safe(pos, n, &notes->src->source, node) {
list_del(&pos->node);
objdump_line__free(pos);
Expand Down
Loading

0 comments on commit 81cce8d

Please sign in to comment.