Skip to content

Commit 5cb456a

Browse files
Jin Yaoacmel
authored andcommitted
perf util: Move block TUI function to ui browsers
It would be nice if we could jump to the assembler/source view (like the normal perf report) from total cycles view. This patch moves the block_hists_tui_browse from block-info.c to ui/browsers/hists.c in order to reuse some browser codes (i.e do_annotate) for implementing new annotation view. v2: --- Fix the 'make NO_SLANG=1' error. (Change 'int block_hists_tui_browse()' to 'static inline int block_hists_tui_browse()') Signed-off-by: Jin Yao <yao.jin@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jin Yao <yao.jin@intel.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20191118140849.20714-1-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent bb1835a commit 5cb456a

3 files changed

Lines changed: 68 additions & 64 deletions

File tree

‎tools/perf/ui/browsers/hists.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,3 +3444,58 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
34443444
warn_lost_event,
34453445
annotation_opts);
34463446
}
3447+
3448+
static int block_hists_browser__title(struct hist_browser *browser, char *bf,
3449+
size_t size)
3450+
{
3451+
struct hists *hists = evsel__hists(browser->block_evsel);
3452+
const char *evname = perf_evsel__name(browser->block_evsel);
3453+
unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
3454+
int ret;
3455+
3456+
ret = scnprintf(bf, size, "# Samples: %lu", nr_samples);
3457+
if (evname)
3458+
scnprintf(bf + ret, size - ret, " of event '%s'", evname);
3459+
3460+
return 0;
3461+
}
3462+
3463+
int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
3464+
float min_percent)
3465+
{
3466+
struct hists *hists = &bh->block_hists;
3467+
struct hist_browser *browser;
3468+
int key = -1;
3469+
static const char help[] =
3470+
" q Quit \n";
3471+
3472+
browser = hist_browser__new(hists);
3473+
if (!browser)
3474+
return -1;
3475+
3476+
browser->block_evsel = evsel;
3477+
browser->title = block_hists_browser__title;
3478+
browser->min_pcnt = min_percent;
3479+
3480+
/* reset abort key so that it can get Ctrl-C as a key */
3481+
SLang_reset_tty();
3482+
SLang_init_tty(0, 0, 0);
3483+
3484+
while (1) {
3485+
key = hist_browser__run(browser, "? - help", true);
3486+
3487+
switch (key) {
3488+
case 'q':
3489+
goto out;
3490+
case '?':
3491+
ui_browser__help_window(&browser->b, help);
3492+
break;
3493+
default:
3494+
break;
3495+
}
3496+
}
3497+
3498+
out:
3499+
hist_browser__delete(browser);
3500+
return 0;
3501+
}

‎tools/perf/util/block-info.c‎

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "map.h"
1111
#include "srcline.h"
1212
#include "evlist.h"
13+
#include "hist.h"
1314
#include "ui/browsers/hists.h"
1415

1516
static struct block_header_column {
@@ -439,70 +440,6 @@ struct block_report *block_info__create_report(struct evlist *evlist,
439440
return block_reports;
440441
}
441442

442-
#ifdef HAVE_SLANG_SUPPORT
443-
static int block_hists_browser__title(struct hist_browser *browser, char *bf,
444-
size_t size)
445-
{
446-
struct hists *hists = evsel__hists(browser->block_evsel);
447-
const char *evname = perf_evsel__name(browser->block_evsel);
448-
unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
449-
int ret;
450-
451-
ret = scnprintf(bf, size, "# Samples: %lu", nr_samples);
452-
if (evname)
453-
scnprintf(bf + ret, size - ret, " of event '%s'", evname);
454-
455-
return 0;
456-
}
457-
458-
static int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
459-
float min_percent)
460-
{
461-
struct hists *hists = &bh->block_hists;
462-
struct hist_browser *browser;
463-
int key = -1;
464-
static const char help[] =
465-
" q Quit \n";
466-
467-
browser = hist_browser__new(hists);
468-
if (!browser)
469-
return -1;
470-
471-
browser->block_evsel = evsel;
472-
browser->title = block_hists_browser__title;
473-
browser->min_pcnt = min_percent;
474-
475-
/* reset abort key so that it can get Ctrl-C as a key */
476-
SLang_reset_tty();
477-
SLang_init_tty(0, 0, 0);
478-
479-
while (1) {
480-
key = hist_browser__run(browser, "? - help", true);
481-
482-
switch (key) {
483-
case 'q':
484-
goto out;
485-
case '?':
486-
ui_browser__help_window(&browser->b, help);
487-
break;
488-
default:
489-
break;
490-
}
491-
}
492-
493-
out:
494-
hist_browser__delete(browser);
495-
return 0;
496-
}
497-
#else
498-
static int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
499-
struct evsel *evsel __maybe_unused,
500-
float min_percent __maybe_unused)
501-
{
502-
return 0;
503-
}
504-
#endif
505-
506443
int report__browse_block_hists(struct block_hist *bh, float min_percent,
507444
struct evsel *evsel)
508445
{

‎tools/perf/util/hist.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ enum rstype {
449449
A_SOURCE
450450
};
451451

452+
struct block_hist;
453+
452454
#ifdef HAVE_SLANG_SUPPORT
453455
#include "../ui/keysyms.h"
454456
void attr_to_script(char *buf, struct perf_event_attr *attr);
@@ -474,6 +476,9 @@ void run_script(char *cmd);
474476
int res_sample_browse(struct res_sample *res_samples, int num_res,
475477
struct evsel *evsel, enum rstype rstype);
476478
void res_sample_init(void);
479+
480+
int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
481+
float min_percent);
477482
#else
478483
static inline
479484
int perf_evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,
@@ -518,6 +523,13 @@ static inline int res_sample_browse(struct res_sample *res_samples __maybe_unuse
518523

519524
static inline void res_sample_init(void) {}
520525

526+
static inline int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
527+
struct evsel *evsel __maybe_unused,
528+
float min_percent __maybe_unused)
529+
{
530+
return 0;
531+
}
532+
521533
#define K_LEFT -1000
522534
#define K_RIGHT -2000
523535
#define K_SWITCH_INPUT_DATA -3000

0 commit comments

Comments
 (0)