Commit 9783adf7 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf tools: Introduce struct hist_browser_timer

Currently various hist browser functions receive 3 arguments for
refreshing histogram but only used from a few places.  Also it's only
for perf top command so that it can be NULL for other (and probably
most) cases.  Pack them into a struct in order to reduce number of those
unused arguments.

This is a mechanical change and does not intend a functional change.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarDavid Ahern <dsahern@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Irina Tirdea <irina.tirdea@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1351835406-15208-2-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 48ed0ece
...@@ -139,7 +139,7 @@ static void hists__find_annotations(struct hists *self, int evidx, ...@@ -139,7 +139,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, NULL, NULL, 0); key = hist_entry__tui_annotate(he, evidx, NULL);
switch (key) { switch (key) {
case K_RIGHT: case K_RIGHT:
next = rb_next(nd); next = rb_next(nd);
......
...@@ -428,10 +428,10 @@ static int __cmd_report(struct perf_report *rep) ...@@ -428,10 +428,10 @@ static int __cmd_report(struct perf_report *rep)
if (use_browser > 0) { if (use_browser > 0) {
if (use_browser == 1) { if (use_browser == 1) {
perf_evlist__tui_browse_hists(session->evlist, help, perf_evlist__tui_browse_hists(session->evlist, help,
NULL, NULL, 0); NULL);
} else if (use_browser == 2) { } else if (use_browser == 2) {
perf_evlist__gtk_browse_hists(session->evlist, help, perf_evlist__gtk_browse_hists(session->evlist, help,
NULL, NULL, 0); NULL);
} }
} else } else
perf_evlist__tty_browse_hists(session->evlist, rep, help); perf_evlist__tty_browse_hists(session->evlist, rep, help);
......
...@@ -582,6 +582,11 @@ static void *display_thread_tui(void *arg) ...@@ -582,6 +582,11 @@ static void *display_thread_tui(void *arg)
struct perf_evsel *pos; struct perf_evsel *pos;
struct perf_top *top = arg; struct perf_top *top = arg;
const char *help = "For a higher level overview, try: perf top --sort comm,dso"; const char *help = "For a higher level overview, try: perf top --sort comm,dso";
struct hist_browser_timer hbt = {
.timer = perf_top__sort_new_samples,
.arg = top,
.refresh = top->delay_secs,
};
perf_top__sort_new_samples(top); perf_top__sort_new_samples(top);
...@@ -593,9 +598,7 @@ static void *display_thread_tui(void *arg) ...@@ -593,9 +598,7 @@ static void *display_thread_tui(void *arg)
list_for_each_entry(pos, &top->evlist->entries, node) list_for_each_entry(pos, &top->evlist->entries, node)
pos->hists.uid_filter_str = top->target.uid_str; pos->hists.uid_filter_str = top->target.uid_str;
perf_evlist__tui_browse_hists(top->evlist, help, perf_evlist__tui_browse_hists(top->evlist, help, &hbt);
perf_top__sort_new_samples,
top, top->delay_secs);
exit_browser(0); exit_browser(0);
exit(0); exit(0);
......
...@@ -386,9 +386,8 @@ static void annotate_browser__init_asm_mode(struct annotate_browser *browser) ...@@ -386,9 +386,8 @@ static void annotate_browser__init_asm_mode(struct annotate_browser *browser)
browser->b.nr_entries = browser->nr_asm_entries; browser->b.nr_entries = browser->nr_asm_entries;
} }
static bool annotate_browser__callq(struct annotate_browser *browser, static bool annotate_browser__callq(struct annotate_browser *browser, int evidx,
int evidx, void (*timer)(void *arg), struct hist_browser_timer *hbt)
void *arg, int delay_secs)
{ {
struct map_symbol *ms = browser->b.priv; struct map_symbol *ms = browser->b.priv;
struct disasm_line *dl = browser->selection; struct disasm_line *dl = browser->selection;
...@@ -418,7 +417,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser, ...@@ -418,7 +417,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
} }
pthread_mutex_unlock(&notes->lock); pthread_mutex_unlock(&notes->lock);
symbol__tui_annotate(target, ms->map, evidx, timer, arg, delay_secs); symbol__tui_annotate(target, ms->map, evidx, hbt);
ui_browser__show_title(&browser->b, sym->name); ui_browser__show_title(&browser->b, sym->name);
return true; return true;
} }
...@@ -602,13 +601,13 @@ static void annotate_browser__update_addr_width(struct annotate_browser *browser ...@@ -602,13 +601,13 @@ static void annotate_browser__update_addr_width(struct annotate_browser *browser
} }
static int annotate_browser__run(struct annotate_browser *browser, int evidx, static int annotate_browser__run(struct annotate_browser *browser, int evidx,
void(*timer)(void *arg), struct hist_browser_timer *hbt)
void *arg, int delay_secs)
{ {
struct rb_node *nd = NULL; struct rb_node *nd = NULL;
struct map_symbol *ms = browser->b.priv; struct map_symbol *ms = browser->b.priv;
struct symbol *sym = ms->sym; struct symbol *sym = ms->sym;
const char *help = "Press 'h' for help on key bindings"; const char *help = "Press 'h' for help on key bindings";
int delay_secs = hbt ? hbt->refresh : 0;
int key; int key;
if (ui_browser__show(&browser->b, sym->name, help) < 0) if (ui_browser__show(&browser->b, sym->name, help) < 0)
...@@ -639,8 +638,8 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx, ...@@ -639,8 +638,8 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx,
switch (key) { switch (key) {
case K_TIMER: case K_TIMER:
if (timer != NULL) if (hbt)
timer(arg); hbt->timer(hbt->arg);
if (delay_secs != 0) if (delay_secs != 0)
symbol__annotate_decay_histogram(sym, evidx); symbol__annotate_decay_histogram(sym, evidx);
...@@ -740,7 +739,7 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx, ...@@ -740,7 +739,7 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx,
goto show_sup_ins; goto show_sup_ins;
goto out; goto out;
} else if (!(annotate_browser__jump(browser) || } else if (!(annotate_browser__jump(browser) ||
annotate_browser__callq(browser, evidx, timer, arg, delay_secs))) { annotate_browser__callq(browser, evidx, hbt))) {
show_sup_ins: show_sup_ins:
ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions.");
} }
...@@ -763,10 +762,9 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx, ...@@ -763,10 +762,9 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx,
} }
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) struct hist_browser_timer *hbt)
{ {
return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, hbt);
timer, arg, delay_secs);
} }
static void annotate_browser__mark_jump_targets(struct annotate_browser *browser, static void annotate_browser__mark_jump_targets(struct annotate_browser *browser,
...@@ -816,8 +814,7 @@ static inline int width_jumps(int n) ...@@ -816,8 +814,7 @@ static inline int width_jumps(int n)
} }
int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
void(*timer)(void *arg), void *arg, struct hist_browser_timer *hbt)
int delay_secs)
{ {
struct disasm_line *pos, *n; struct disasm_line *pos, *n;
struct annotation *notes; struct annotation *notes;
...@@ -899,7 +896,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, ...@@ -899,7 +896,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
annotate_browser__update_addr_width(&browser); annotate_browser__update_addr_width(&browser);
ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs); ret = annotate_browser__run(&browser, evidx, hbt);
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);
disasm_line__free(pos); disasm_line__free(pos);
......
...@@ -310,10 +310,11 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser) ...@@ -310,10 +310,11 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser)
} }
static int hist_browser__run(struct hist_browser *browser, const char *ev_name, static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
void(*timer)(void *arg), void *arg, int delay_secs) struct hist_browser_timer *hbt)
{ {
int key; int key;
char title[160]; char title[160];
int delay_secs = hbt ? hbt->refresh : 0;
browser->b.entries = &browser->hists->entries; browser->b.entries = &browser->hists->entries;
browser->b.nr_entries = browser->hists->nr_entries; browser->b.nr_entries = browser->hists->nr_entries;
...@@ -330,7 +331,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name, ...@@ -330,7 +331,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
switch (key) { switch (key) {
case K_TIMER: case K_TIMER:
timer(arg); hbt->timer(hbt->arg);
ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries);
if (browser->hists->stats.nr_lost_warned != if (browser->hists->stats.nr_lost_warned !=
...@@ -1136,8 +1137,7 @@ static inline bool is_report_browser(void *timer) ...@@ -1136,8 +1137,7 @@ static inline bool is_report_browser(void *timer)
static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
const char *helpline, const char *ev_name, const char *helpline, const char *ev_name,
bool left_exits, bool left_exits,
void(*timer)(void *arg), void *arg, struct hist_browser_timer *hbt)
int delay_secs)
{ {
struct hists *hists = &evsel->hists; struct hists *hists = &evsel->hists;
struct hist_browser *browser = hist_browser__new(hists); struct hist_browser *browser = hist_browser__new(hists);
...@@ -1148,6 +1148,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -1148,6 +1148,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
int key = -1; int key = -1;
char buf[64]; char buf[64];
char script_opt[64]; char script_opt[64];
int delay_secs = hbt ? hbt->refresh : 0;
if (browser == NULL) if (browser == NULL)
return -1; return -1;
...@@ -1170,7 +1171,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -1170,7 +1171,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
nr_options = 0; nr_options = 0;
key = hist_browser__run(browser, ev_name, timer, arg, delay_secs); key = hist_browser__run(browser, ev_name, hbt);
if (browser->he_selection != NULL) { if (browser->he_selection != NULL) {
thread = hist_browser__selected_thread(browser); thread = hist_browser__selected_thread(browser);
...@@ -1220,7 +1221,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -1220,7 +1221,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
} }
continue; continue;
case 'r': case 'r':
if (is_report_browser(timer)) if (is_report_browser(hbt))
goto do_scripts; goto do_scripts;
continue; continue;
case K_F1: case K_F1:
...@@ -1388,8 +1389,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -1388,8 +1389,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, err = hist_entry__tui_annotate(he, evsel->idx, hbt);
timer, arg, delay_secs);
he->used = false; he->used = false;
/* /*
* offer option to annotate the other branch source or target * offer option to annotate the other branch source or target
...@@ -1512,11 +1512,12 @@ static void perf_evsel_menu__write(struct ui_browser *browser, ...@@ -1512,11 +1512,12 @@ static void perf_evsel_menu__write(struct ui_browser *browser,
static int perf_evsel_menu__run(struct perf_evsel_menu *menu, static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
int nr_events, const char *help, int nr_events, const char *help,
void(*timer)(void *arg), void *arg, int delay_secs) struct hist_browser_timer *hbt)
{ {
struct perf_evlist *evlist = menu->b.priv; struct perf_evlist *evlist = menu->b.priv;
struct perf_evsel *pos; struct perf_evsel *pos;
const char *ev_name, *title = "Available samples"; const char *ev_name, *title = "Available samples";
int delay_secs = hbt ? hbt->refresh : 0;
int key; int key;
if (ui_browser__show(&menu->b, title, if (ui_browser__show(&menu->b, title,
...@@ -1528,7 +1529,7 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, ...@@ -1528,7 +1529,7 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
switch (key) { switch (key) {
case K_TIMER: case K_TIMER:
timer(arg); hbt->timer(hbt->arg);
if (!menu->lost_events_warned && menu->lost_events) { if (!menu->lost_events_warned && menu->lost_events) {
ui_browser__warn_lost_events(&menu->b); ui_browser__warn_lost_events(&menu->b);
...@@ -1546,12 +1547,11 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, ...@@ -1546,12 +1547,11 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
* Give the calling tool a chance to populate the non * Give the calling tool a chance to populate the non
* default evsel resorted hists tree. * default evsel resorted hists tree.
*/ */
if (timer) if (hbt)
timer(arg); hbt->timer(hbt->arg);
ev_name = perf_evsel__name(pos); ev_name = perf_evsel__name(pos);
key = perf_evsel__hists_browse(pos, nr_events, help, key = perf_evsel__hists_browse(pos, nr_events, help,
ev_name, true, timer, ev_name, true, hbt);
arg, delay_secs);
ui_browser__show_title(&menu->b, title); ui_browser__show_title(&menu->b, title);
switch (key) { switch (key) {
case K_TAB: case K_TAB:
...@@ -1599,8 +1599,7 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, ...@@ -1599,8 +1599,7 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
const char *help, const char *help,
void(*timer)(void *arg), void *arg, struct hist_browser_timer *hbt)
int delay_secs)
{ {
struct perf_evsel *pos; struct perf_evsel *pos;
struct perf_evsel_menu menu = { struct perf_evsel_menu menu = {
...@@ -1624,23 +1623,19 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, ...@@ -1624,23 +1623,19 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
menu.b.width = line_len; menu.b.width = line_len;
} }
return perf_evsel_menu__run(&menu, evlist->nr_entries, help, timer, return perf_evsel_menu__run(&menu, evlist->nr_entries, help, hbt);
arg, 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,
void(*timer)(void *arg), void *arg, struct hist_browser_timer *hbt)
int delay_secs)
{ {
if (evlist->nr_entries == 1) { if (evlist->nr_entries == 1) {
struct perf_evsel *first = list_entry(evlist->entries.next, struct perf_evsel *first = list_entry(evlist->entries.next,
struct perf_evsel, node); struct perf_evsel, node);
const char *ev_name = perf_evsel__name(first); const char *ev_name = perf_evsel__name(first);
return perf_evsel__hists_browse(first, evlist->nr_entries, help, return perf_evsel__hists_browse(first, evlist->nr_entries, help,
ev_name, false, timer, arg, ev_name, false, hbt);
delay_secs);
} }
return __perf_evlist__tui_browse_hists(evlist, help, return __perf_evlist__tui_browse_hists(evlist, help, hbt);
timer, arg, delay_secs);
} }
...@@ -237,9 +237,7 @@ static GtkWidget *perf_gtk__setup_statusbar(void) ...@@ -237,9 +237,7 @@ static GtkWidget *perf_gtk__setup_statusbar(void)
int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
const char *help, const char *help,
void (*timer) (void *arg)__maybe_unused, struct hist_browser_timer *hbt __maybe_unused)
void *arg __maybe_unused,
int delay_secs __maybe_unused)
{ {
struct perf_evsel *pos; struct perf_evsel *pos;
GtkWidget *vbox; GtkWidget *vbox;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include "types.h" #include "types.h"
#include "symbol.h" #include "symbol.h"
#include "hist.h"
#include <linux/list.h> #include <linux/list.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <pthread.h> #include <pthread.h>
...@@ -140,14 +141,13 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx, ...@@ -140,14 +141,13 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
#ifdef NEWT_SUPPORT #ifdef NEWT_SUPPORT
int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
void(*timer)(void *arg), void *arg, int delay_secs); struct hist_browser_timer *hbt);
#else #else
static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
struct map *map __maybe_unused, struct map *map __maybe_unused,
int evidx __maybe_unused, int evidx __maybe_unused,
void(*timer)(void *arg) __maybe_unused, struct hist_browser_timer *hbt
void *arg __maybe_unused, __maybe_unused)
int delay_secs __maybe_unused)
{ {
return 0; return 0;
} }
......
...@@ -157,22 +157,25 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, ...@@ -157,22 +157,25 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
struct perf_evlist; struct perf_evlist;
struct hist_browser_timer {
void (*timer)(void *arg);
void *arg;
int refresh;
};
#ifdef NEWT_SUPPORT #ifdef NEWT_SUPPORT
#include "../ui/keysyms.h" #include "../ui/keysyms.h"
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); struct hist_browser_timer *hbt);
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, struct hist_browser_timer *hbt);
int refresh);
int script_browse(const char *script_opt); int script_browse(const char *script_opt);
#else #else
static inline static inline
int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
const char *help __maybe_unused, const char *help __maybe_unused,
void(*timer)(void *arg) __maybe_unused, struct hist_browser_timer *hbt __maybe_unused)
void *arg __maybe_unused,
int refresh __maybe_unused)
{ {
return 0; return 0;
} }
...@@ -180,10 +183,8 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, ...@@ -180,10 +183,8 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
static inline int hist_entry__tui_annotate(struct hist_entry *self static inline int hist_entry__tui_annotate(struct hist_entry *self
__maybe_unused, __maybe_unused,
int evidx __maybe_unused, int evidx __maybe_unused,
void(*timer)(void *arg) struct hist_browser_timer *hbt
__maybe_unused, __maybe_unused)
void *arg __maybe_unused,
int delay_secs __maybe_unused)
{ {
return 0; return 0;
} }
...@@ -199,15 +200,12 @@ static inline int script_browse(const char *script_opt) ...@@ -199,15 +200,12 @@ static inline int script_browse(const char *script_opt)
#ifdef GTK2_SUPPORT #ifdef GTK2_SUPPORT
int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help, int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help,
void(*timer)(void *arg), void *arg, struct hist_browser_timer *hbt __maybe_unused);
int refresh);
#else #else
static inline static inline
int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused, int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused,
const char *help __maybe_unused, const char *help __maybe_unused,
void(*timer)(void *arg) __maybe_unused, struct hist_browser_timer *hbt __maybe_unused)
void *arg __maybe_unused,
int refresh __maybe_unused)
{ {
return 0; return 0;
} }
......
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