aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/newt.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-03-31 10:33:40 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-04-02 15:28:15 -0400
commita4e3b956a820162b7c1d616117b4f23b6017f504 (patch)
tree370116b6f6f4f8d3410a14831d394cf4993d04d8 /tools/perf/util/newt.c
parent70162138c91b040da3162fe1f34fe8aaf6506f10 (diff)
perf hist: Replace ->print() routines by ->snprintf() equivalents
Then hist_entry__fprintf will just us the newly introduced hist_entry__snprintf, add the newline and fprintf it to the supplied FILE descriptor. This allows us to remove the use_browser checking in the color_printf routines, that now got color_snprintf variants too. The newt TUI browser (and other GUIs that may come in the future) don't have to worry about stdio specific stuff in the strings they get from the se->snprintf routines and instead use whatever means to do the equivalent. Also the newt TUI browser don't have to use the fmemopen() hack, instead it can use the se->snprintf routines directly. For now tho use the hist_entry__snprintf routine to reduce the patch size. Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/newt.c')
-rw-r--r--tools/perf/util/newt.c53
1 files changed, 5 insertions, 48 deletions
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c
index b0210ae5b93c..edd628f5337b 100644
--- a/tools/perf/util/newt.c
+++ b/tools/perf/util/newt.c
@@ -294,60 +294,17 @@ static void hist_entry__append_callchain_browser(struct hist_entry *self,
294 } 294 }
295} 295}
296 296
297/*
298 * FIXME: get lib/string.c linked with perf somehow
299 */
300static char *skip_spaces(const char *str)
301{
302 while (isspace(*str))
303 ++str;
304 return (char *)str;
305}
306
307static char *strim(char *s)
308{
309 size_t size;
310 char *end;
311
312 s = skip_spaces(s);
313 size = strlen(s);
314 if (!size)
315 return s;
316
317 end = s + size - 1;
318 while (end >= s && isspace(*end))
319 end--;
320 *(end + 1) = '\0';
321
322 return s;
323}
324
325static size_t hist_entry__append_browser(struct hist_entry *self, 297static size_t hist_entry__append_browser(struct hist_entry *self,
326 newtComponent tree, u64 total) 298 newtComponent tree, u64 total)
327{ 299{
328 char bf[1024], *s; 300 char s[256];
329 FILE *fp; 301 size_t ret;
330 302
331 if (symbol_conf.exclude_other && !self->parent) 303 if (symbol_conf.exclude_other && !self->parent)
332 return 0; 304 return 0;
333 305
334 fp = fmemopen(bf, sizeof(bf), "w"); 306 ret = hist_entry__snprintf(self, s, sizeof(s), NULL,
335 if (fp == NULL) 307 false, 0, false, total);
336 return 0;
337
338 hist_entry__fprintf(self, NULL, false, 0, fp, total);
339 fclose(fp);
340
341 /*
342 * FIXME: We shouldn't need to trim, as the printing routines shouldn't
343 * add spaces it in the first place, the stdio output routines should
344 * call a __snprintf method instead of the current __print (that
345 * actually is a __fprintf) one, but get the raw string and _then_ add
346 * the newline, as this is a detail of stdio printing, not needed in
347 * other UIs, e.g. newt.
348 */
349 s = strim(bf);
350
351 if (symbol_conf.use_callchain) { 308 if (symbol_conf.use_callchain) {
352 int indexes[2]; 309 int indexes[2];
353 310
@@ -357,7 +314,7 @@ static size_t hist_entry__append_browser(struct hist_entry *self,
357 } else 314 } else
358 newtListboxAppendEntry(tree, s, &self->ms); 315 newtListboxAppendEntry(tree, s, &self->ms);
359 316
360 return strlen(s); 317 return ret;
361} 318}
362 319
363static void map_symbol__annotate_browser(const struct map_symbol *self) 320static void map_symbol__annotate_browser(const struct map_symbol *self)