Re: [PATCH 07/12] perf hists browser: Allow passing an initial hotkey
From: Jiri Olsa
Date: Wed Dec 18 2019 - 09:23:33 EST
On Wed, Dec 18, 2019 at 11:08:31AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Dec 18, 2019 at 09:08:18AM +0100, Jiri Olsa escreveu:
> > On Tue, Dec 17, 2019 at 11:48:23AM -0300, Arnaldo Carvalho de Melo wrote:
> >
> > SNIP
> >
> > > diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
> > > index 6dfdd8d5a743..3b7af5a8d101 100644
> > > --- a/tools/perf/ui/browsers/hists.c
> > > +++ b/tools/perf/ui/browsers/hists.c
> > > @@ -673,9 +673,8 @@ static int hist_browser__title(struct hist_browser *browser, char *bf, size_t si
> > > }
> > >
> > > int hist_browser__run(struct hist_browser *browser, const char *help,
> > > - bool warn_lost_event)
> > > + bool warn_lost_event, int key)
> > > {
> > > - int key;
> > > char title[160];
> > > struct hist_browser_timer *hbt = browser->hbt;
> > > int delay_secs = hbt ? hbt->refresh : 0;
> > > @@ -688,9 +687,12 @@ int hist_browser__run(struct hist_browser *browser, const char *help,
> > > if (ui_browser__show(&browser->b, title, "%s", help) < 0)
> > > return -1;
> > >
> > > + if (key)
> > > + goto do_hotkey;
> > > +
> > > while (1) {
> > > key = ui_browser__run(&browser->b, delay_secs);
> > > -
> > > +do_hotkey:
> >
> > or we could switch the 'swtich' and ui_browser__run, and get rid of the goto, like:
> >
> > while (1) {
> > switch (key) {
> > ...
> > }
> >
> > key = ui_browser__run(&browser->b, delay_secs);
> > }
>
> I think those are equivalent and having the test like I did is more
> clear, i.e. "has this key been provided" instead of going to the switch
> just to hit the default case for the zero in key and call
> ui_browser__run().
sure, I just don't like goto other than for error handling,
looks too hacky to me ;-) but of course it's your call
jirka