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>
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c
index b0210ae..edd628f 100644
--- a/tools/perf/util/newt.c
+++ b/tools/perf/util/newt.c
@@ -294,60 +294,17 @@
}
}
-/*
- * FIXME: get lib/string.c linked with perf somehow
- */
-static char *skip_spaces(const char *str)
-{
- while (isspace(*str))
- ++str;
- return (char *)str;
-}
-
-static char *strim(char *s)
-{
- size_t size;
- char *end;
-
- s = skip_spaces(s);
- size = strlen(s);
- if (!size)
- return s;
-
- end = s + size - 1;
- while (end >= s && isspace(*end))
- end--;
- *(end + 1) = '\0';
-
- return s;
-}
-
static size_t hist_entry__append_browser(struct hist_entry *self,
newtComponent tree, u64 total)
{
- char bf[1024], *s;
- FILE *fp;
+ char s[256];
+ size_t ret;
if (symbol_conf.exclude_other && !self->parent)
return 0;
- fp = fmemopen(bf, sizeof(bf), "w");
- if (fp == NULL)
- return 0;
-
- hist_entry__fprintf(self, NULL, false, 0, fp, total);
- fclose(fp);
-
- /*
- * FIXME: We shouldn't need to trim, as the printing routines shouldn't
- * add spaces it in the first place, the stdio output routines should
- * call a __snprintf method instead of the current __print (that
- * actually is a __fprintf) one, but get the raw string and _then_ add
- * the newline, as this is a detail of stdio printing, not needed in
- * other UIs, e.g. newt.
- */
- s = strim(bf);
-
+ ret = hist_entry__snprintf(self, s, sizeof(s), NULL,
+ false, 0, false, total);
if (symbol_conf.use_callchain) {
int indexes[2];
@@ -357,7 +314,7 @@
} else
newtListboxAppendEntry(tree, s, &self->ms);
- return strlen(s);
+ return ret;
}
static void map_symbol__annotate_browser(const struct map_symbol *self)