Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf ui browser: Add ui_browser__show counterpart: __hide

So that the common tasks of providing a helpline at __run entry and
destroying the window and releasing resourses at exit can be abstracted
away, reducing a bit more the coupling with libnewt.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+33 -15
+17 -1
tools/perf/util/ui/browser.c
··· 16 16 #include <stdlib.h> 17 17 #include <sys/ttydefaults.h> 18 18 #include "browser.h" 19 + #include "helpline.h" 19 20 #include "../color.h" 20 21 #include "../util.h" 21 22 ··· 146 145 self->seek(self, 0, SEEK_SET); 147 146 } 148 147 149 - int ui_browser__show(struct ui_browser *self, const char *title) 148 + int ui_browser__show(struct ui_browser *self, const char *title, 149 + const char *helpline, ...) 150 150 { 151 + va_list ap; 152 + 151 153 if (self->form != NULL) { 152 154 newtFormDestroy(self->form); 153 155 newtPopWindow(); ··· 175 171 newtFormAddHotKey(self->form, NEWT_KEY_END); 176 172 newtFormAddHotKey(self->form, ' '); 177 173 newtFormAddComponent(self->form, self->sb); 174 + 175 + va_start(ap, helpline); 176 + ui_helpline__vpush(helpline, ap); 177 + va_end(ap); 178 178 return 0; 179 + } 180 + 181 + void ui_browser__hide(struct ui_browser *self) 182 + { 183 + newtFormDestroy(self->form); 184 + newtPopWindow(); 185 + self->form = NULL; 186 + ui_helpline__pop(); 179 187 } 180 188 181 189 int ui_browser__refresh(struct ui_browser *self)
+3 -1
tools/perf/util/ui/browser.h
··· 30 30 void ui_browser__refresh_dimensions(struct ui_browser *self); 31 31 void ui_browser__reset_index(struct ui_browser *self); 32 32 33 - int ui_browser__show(struct ui_browser *self, const char *title); 33 + int ui_browser__show(struct ui_browser *self, const char *title, 34 + const char *helpline, ...); 35 + void ui_browser__hide(struct ui_browser *self); 34 36 int ui_browser__refresh(struct ui_browser *self); 35 37 int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es); 36 38
+3 -5
tools/perf/util/ui/browsers/annotate.c
··· 141 141 struct rb_node *nd; 142 142 struct hist_entry *he = self->b.priv; 143 143 144 - if (ui_browser__show(&self->b, he->ms.sym->name) < 0) 144 + if (ui_browser__show(&self->b, he->ms.sym->name, 145 + "<- or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0) 145 146 return -1; 146 147 147 - ui_helpline__fpush("<- or ESC: exit, TAB/shift+TAB: cycle thru samples"); 148 148 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 149 149 150 150 nd = self->curr_hot; ··· 177 177 } 178 178 } 179 179 out: 180 - newtFormDestroy(self->b.form); 181 - newtPopWindow(); 182 - ui_helpline__pop(); 180 + ui_browser__hide(&self->b); 183 181 return 0; 184 182 } 185 183
+4 -1
tools/perf/util/ui/browsers/hists.c
··· 211 211 nr_events, unit); 212 212 newtDrawRootText(0, 0, str); 213 213 214 - if (ui_browser__show(&self->b, title) < 0) 214 + if (ui_browser__show(&self->b, title, 215 + "Press '?' for help on key bindings") < 0) 215 216 return -1; 216 217 217 218 newtFormAddHotKey(self->b.form, 'A'); ··· 254 253 return 0; 255 254 } 256 255 } 256 + 257 + ui_browser__hide(&self->b); 257 258 return 0; 258 259 } 259 260
+4 -6
tools/perf/util/ui/browsers/map.c
··· 100 100 101 101 static int map_browser__run(struct map_browser *self, struct newtExitStruct *es) 102 102 { 103 - if (ui_browser__show(&self->b, self->map->dso->long_name) < 0) 103 + if (ui_browser__show(&self->b, self->map->dso->long_name, 104 + "Press <- or ESC to exit, %s / to search", 105 + verbose ? "" : "restart with -v to use") < 0) 104 106 return -1; 105 107 106 - ui_helpline__fpush("Press <- or ESC to exit, %s / to search", 107 - verbose ? "" : "restart with -v to use"); 108 108 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 109 109 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER); 110 110 if (verbose) ··· 121 121 break; 122 122 } 123 123 124 - newtFormDestroy(self->b.form); 125 - newtPopWindow(); 126 - ui_helpline__pop(); 124 + ui_browser__hide(&self->b); 127 125 return 0; 128 126 } 129 127
+1 -1
tools/perf/util/ui/helpline.c
··· 16 16 newtPushHelpLine(msg); 17 17 } 18 18 19 - static void ui_helpline__vpush(const char *fmt, va_list ap) 19 + void ui_helpline__vpush(const char *fmt, va_list ap) 20 20 { 21 21 char *s; 22 22
+1
tools/perf/util/ui/helpline.h
··· 4 4 void ui_helpline__init(void); 5 5 void ui_helpline__pop(void); 6 6 void ui_helpline__push(const char *msg); 7 + void ui_helpline__vpush(const char *fmt, va_list ap); 7 8 void ui_helpline__fpush(const char *fmt, ...); 8 9 void ui_helpline__puts(const char *msg); 9 10