perf hists browser: Allow passing an initial hotkey

Sometimes we're in an outer code, like the main hists browser popup menu
and the user follows a suggestion about using some hotkey, and that
hotkey is really handled by hists_browser__run(), so allow for calling
it with that hotkey, making it handle it instead of waiting for the user
to press one.

Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-xv2l7i6o4urn37nv1h40ryfs@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-12-12 15:31:40 -03:00
Родитель 209f4e70a2
Коммит d10ec006dc
3 изменённых файлов: 83 добавлений и 78 удалений

Просмотреть файл

@ -2384,7 +2384,7 @@ static int perf_c2c__browse_cacheline(struct hist_entry *he)
c2c_browser__update_nr_entries(browser);
while (1) {
key = hist_browser__run(browser, "? - help", true);
key = hist_browser__run(browser, "? - help", true, 0);
switch (key) {
case 's':
@ -2453,7 +2453,7 @@ static int perf_c2c__hists_browse(struct hists *hists)
c2c_browser__update_nr_entries(browser);
while (1) {
key = hist_browser__run(browser, "? - help", true);
key = hist_browser__run(browser, "? - help", true, 0);
switch (key) {
case 'q':

Просмотреть файл

@ -672,27 +672,11 @@ static int hist_browser__title(struct hist_browser *browser, char *bf, size_t si
return browser->title ? browser->title(browser, bf, size) : 0;
}
int hist_browser__run(struct hist_browser *browser, const char *help,
bool warn_lost_event)
static int hist_browser__handle_hotkey(struct hist_browser *browser, bool warn_lost_event, char *title, int key)
{
int key;
char title[160];
struct hist_browser_timer *hbt = browser->hbt;
int delay_secs = hbt ? hbt->refresh : 0;
browser->b.entries = &browser->hists->entries;
browser->b.nr_entries = hist_browser__nr_entries(browser);
hist_browser__title(browser, title, sizeof(title));
if (ui_browser__show(&browser->b, title, "%s", help) < 0)
return -1;
while (1) {
key = ui_browser__run(&browser->b, delay_secs);
switch (key) {
case K_TIMER: {
struct hist_browser_timer *hbt = browser->hbt;
u64 nr_entries;
WARN_ON_ONCE(!hbt);
@ -700,8 +684,7 @@ int hist_browser__run(struct hist_browser *browser, const char *help,
if (hbt)
hbt->timer(hbt->arg);
if (hist_browser__has_filter(browser) ||
symbol_conf.report_hierarchy)
if (hist_browser__has_filter(browser) || symbol_conf.report_hierarchy)
hist_browser__update_nr_entries(browser);
nr_entries = hist_browser__nr_entries(browser);
@ -717,21 +700,17 @@ int hist_browser__run(struct hist_browser *browser, const char *help,
hist_browser__title(browser, title, sizeof(title));
ui_browser__show_title(&browser->b, title);
continue;
break;
}
case 'D': { /* Debug */
struct hist_entry *h = rb_entry(browser->b.top, struct hist_entry, rb_node);
static int seq;
struct hist_entry *h = rb_entry(browser->b.top,
struct hist_entry, rb_node);
ui_helpline__pop();
ui_helpline__fpush("%d: nr_ent=(%d,%d), etl: %d, rows=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d",
seq++, browser->b.nr_entries,
browser->hists->nr_entries,
browser->b.extra_title_lines,
browser->b.rows,
browser->b.index,
browser->b.top_idx,
h->row_offset, h->nr_rows);
seq++, browser->b.nr_entries, browser->hists->nr_entries,
browser->b.extra_title_lines, browser->b.rows,
browser->b.index, browser->b.top_idx, h->row_offset, h->nr_rows);
}
break;
case 'C':
@ -759,8 +738,35 @@ int hist_browser__run(struct hist_browser *browser, const char *help,
break;
/* fall thru */
default:
goto out;
return -1;
}
return 0;
}
int hist_browser__run(struct hist_browser *browser, const char *help,
bool warn_lost_event, int key)
{
char title[160];
struct hist_browser_timer *hbt = browser->hbt;
int delay_secs = hbt ? hbt->refresh : 0;
browser->b.entries = &browser->hists->entries;
browser->b.nr_entries = hist_browser__nr_entries(browser);
hist_browser__title(browser, title, sizeof(title));
if (ui_browser__show(&browser->b, title, "%s", help) < 0)
return -1;
if (key && hist_browser__handle_hotkey(browser, warn_lost_event, title, key))
goto out;
while (1) {
key = ui_browser__run(&browser->b, delay_secs);
if (hist_browser__handle_hotkey(browser, warn_lost_event, title, key))
break;
}
out:
ui_browser__hide(&browser->b);
@ -2994,8 +3000,7 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
nr_options = 0;
key = hist_browser__run(browser, helpline,
warn_lost_event);
key = hist_browser__run(browser, helpline, warn_lost_event, 0);
if (browser->he_selection != NULL) {
thread = hist_browser__selected_thread(browser);
@ -3573,7 +3578,7 @@ int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
memset(&action, 0, sizeof(action));
while (1) {
key = hist_browser__run(browser, "? - help", true);
key = hist_browser__run(browser, "? - help", true, 0);
switch (key) {
case 'q':

Просмотреть файл

@ -34,7 +34,7 @@ struct hist_browser {
struct hist_browser *hist_browser__new(struct hists *hists);
void hist_browser__delete(struct hist_browser *browser);
int hist_browser__run(struct hist_browser *browser, const char *help,
bool warn_lost_event);
bool warn_lost_event, int key);
void hist_browser__init(struct hist_browser *browser,
struct hists *hists);
#endif /* _PERF_UI_BROWSER_HISTS_H_ */