aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
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
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')
-rw-r--r--tools/perf/util/color.c53
-rw-r--r--tools/perf/util/color.h4
-rw-r--r--tools/perf/util/hist.c54
-rw-r--r--tools/perf/util/hist.h7
-rw-r--r--tools/perf/util/newt.c53
-rw-r--r--tools/perf/util/sort.c88
-rw-r--r--tools/perf/util/sort.h4
7 files changed, 149 insertions, 114 deletions
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index 9da01914e0a..e191eb9a667 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -166,6 +166,31 @@ int perf_color_default_config(const char *var, const char *value, void *cb)
166 return perf_default_config(var, value, cb); 166 return perf_default_config(var, value, cb);
167} 167}
168 168
169static int __color_vsnprintf(char *bf, size_t size, const char *color,
170 const char *fmt, va_list args, const char *trail)
171{
172 int r = 0;
173
174 /*
175 * Auto-detect:
176 */
177 if (perf_use_color_default < 0) {
178 if (isatty(1) || pager_in_use())
179 perf_use_color_default = 1;
180 else
181 perf_use_color_default = 0;
182 }
183
184 if (perf_use_color_default && *color)
185 r += snprintf(bf, size, "%s", color);
186 r += vsnprintf(bf + r, size - r, fmt, args);
187 if (perf_use_color_default && *color)
188 r += snprintf(bf + r, size - r, "%s", PERF_COLOR_RESET);
189 if (trail)
190 r += snprintf(bf + r, size - r, "%s", trail);
191 return r;
192}
193
169static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, 194static int __color_vfprintf(FILE *fp, const char *color, const char *fmt,
170 va_list args, const char *trail) 195 va_list args, const char *trail)
171{ 196{
@@ -191,11 +216,28 @@ static int __color_vfprintf(FILE *fp, const char *color, const char *fmt,
191 return r; 216 return r;
192} 217}
193 218
219int color_vsnprintf(char *bf, size_t size, const char *color,
220 const char *fmt, va_list args)
221{
222 return __color_vsnprintf(bf, size, color, fmt, args, NULL);
223}
224
194int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args) 225int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args)
195{ 226{
196 return __color_vfprintf(fp, color, fmt, args, NULL); 227 return __color_vfprintf(fp, color, fmt, args, NULL);
197} 228}
198 229
230int color_snprintf(char *bf, size_t size, const char *color,
231 const char *fmt, ...)
232{
233 va_list args;
234 int r;
235
236 va_start(args, fmt);
237 r = color_vsnprintf(bf, size, color, fmt, args);
238 va_end(args);
239 return r;
240}
199 241
200int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) 242int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
201{ 243{
@@ -203,10 +245,7 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
203 int r; 245 int r;
204 246
205 va_start(args, fmt); 247 va_start(args, fmt);
206 if (use_browser) 248 r = color_vfprintf(fp, color, fmt, args);
207 r = vfprintf(fp, fmt, args);
208 else
209 r = color_vfprintf(fp, color, fmt, args);
210 va_end(args); 249 va_end(args);
211 return r; 250 return r;
212} 251}
@@ -277,3 +316,9 @@ int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
277 316
278 return r; 317 return r;
279} 318}
319
320int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent)
321{
322 const char *color = get_percent_color(percent);
323 return color_snprintf(bf, size, color, fmt, percent);
324}
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h
index 24e8809210b..dea082b7960 100644
--- a/tools/perf/util/color.h
+++ b/tools/perf/util/color.h
@@ -32,10 +32,14 @@ int perf_color_default_config(const char *var, const char *value, void *cb);
32int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); 32int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty);
33void color_parse(const char *value, const char *var, char *dst); 33void color_parse(const char *value, const char *var, char *dst);
34void color_parse_mem(const char *value, int len, const char *var, char *dst); 34void color_parse_mem(const char *value, int len, const char *var, char *dst);
35int color_vsnprintf(char *bf, size_t size, const char *color,
36 const char *fmt, va_list args);
35int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); 37int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args);
36int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); 38int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
39int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...);
37int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); 40int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
38int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); 41int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
42int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent);
39int percent_color_fprintf(FILE *fp, const char *fmt, double percent); 43int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
40const char *get_percent_color(double percent); 44const char *get_percent_color(double percent);
41 45
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index a46d0933246..f0794913d57 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -455,16 +455,17 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
455 return ret; 455 return ret;
456} 456}
457 457
458size_t hist_entry__fprintf(struct hist_entry *self, 458int hist_entry__snprintf(struct hist_entry *self,
459 char *s, size_t size,
459 struct perf_session *pair_session, 460 struct perf_session *pair_session,
460 bool show_displacement, 461 bool show_displacement,
461 long displacement, FILE *fp, 462 long displacement, bool color,
462 u64 session_total) 463 u64 session_total)
463{ 464{
464 struct sort_entry *se; 465 struct sort_entry *se;
465 u64 count, total; 466 u64 count, total;
466 const char *sep = symbol_conf.field_sep; 467 const char *sep = symbol_conf.field_sep;
467 size_t ret; 468 int ret;
468 469
469 if (symbol_conf.exclude_other && !self->parent) 470 if (symbol_conf.exclude_other && !self->parent)
470 return 0; 471 return 0;
@@ -477,17 +478,22 @@ size_t hist_entry__fprintf(struct hist_entry *self,
477 total = session_total; 478 total = session_total;
478 } 479 }
479 480
480 if (total) 481 if (total) {
481 ret = percent_color_fprintf(fp, sep ? "%.2f" : " %6.2f%%", 482 if (color)
482 (count * 100.0) / total); 483 ret = percent_color_snprintf(s, size,
483 else 484 sep ? "%.2f" : " %6.2f%%",
484 ret = fprintf(fp, sep ? "%lld" : "%12lld ", count); 485 (count * 100.0) / total);
486 else
487 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
488 (count * 100.0) / total);
489 } else
490 ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count);
485 491
486 if (symbol_conf.show_nr_samples) { 492 if (symbol_conf.show_nr_samples) {
487 if (sep) 493 if (sep)
488 ret += fprintf(fp, "%c%lld", *sep, count); 494 ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count);
489 else 495 else
490 ret += fprintf(fp, "%11lld", count); 496 ret += snprintf(s + ret, size - ret, "%11lld", count);
491 } 497 }
492 498
493 if (pair_session) { 499 if (pair_session) {
@@ -507,9 +513,9 @@ size_t hist_entry__fprintf(struct hist_entry *self,
507 snprintf(bf, sizeof(bf), " "); 513 snprintf(bf, sizeof(bf), " ");
508 514
509 if (sep) 515 if (sep)
510 ret += fprintf(fp, "%c%s", *sep, bf); 516 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
511 else 517 else
512 ret += fprintf(fp, "%11.11s", bf); 518 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
513 519
514 if (show_displacement) { 520 if (show_displacement) {
515 if (displacement) 521 if (displacement)
@@ -518,9 +524,9 @@ size_t hist_entry__fprintf(struct hist_entry *self,
518 snprintf(bf, sizeof(bf), " "); 524 snprintf(bf, sizeof(bf), " ");
519 525
520 if (sep) 526 if (sep)
521 ret += fprintf(fp, "%c%s", *sep, bf); 527 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
522 else 528 else
523 ret += fprintf(fp, "%6.6s", bf); 529 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
524 } 530 }
525 } 531 }
526 532
@@ -528,11 +534,25 @@ size_t hist_entry__fprintf(struct hist_entry *self,
528 if (se->elide) 534 if (se->elide)
529 continue; 535 continue;
530 536
531 ret += fprintf(fp, "%s", sep ?: " "); 537 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
532 ret += se->print(fp, self, se->width ? *se->width : 0); 538 ret += se->snprintf(self, s + ret, size - ret,
539 se->width ? *se->width : 0);
533 } 540 }
534 541
535 return ret + fprintf(fp, "\n"); 542 return ret;
543}
544
545int hist_entry__fprintf(struct hist_entry *self,
546 struct perf_session *pair_session,
547 bool show_displacement,
548 long displacement, FILE *fp,
549 u64 session_total)
550{
551 char bf[512];
552 hist_entry__snprintf(self, bf, sizeof(bf), pair_session,
553 show_displacement, displacement,
554 true, session_total);
555 return fprintf(fp, "%s\n", bf);
536} 556}
537 557
538static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp, 558static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp,
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index da6a8c1320f..ad17f0ad798 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -18,11 +18,16 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
18 u64 count, bool *hit); 18 u64 count, bool *hit);
19extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); 19extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *);
20extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); 20extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *);
21size_t hist_entry__fprintf(struct hist_entry *self, 21int hist_entry__fprintf(struct hist_entry *self,
22 struct perf_session *pair_session, 22 struct perf_session *pair_session,
23 bool show_displacement, 23 bool show_displacement,
24 long displacement, FILE *fp, 24 long displacement, FILE *fp,
25 u64 session_total); 25 u64 session_total);
26int hist_entry__snprintf(struct hist_entry *self,
27 char *bf, size_t size,
28 struct perf_session *pair_session,
29 bool show_displacement, long displacement,
30 bool color, u64 session_total);
26void hist_entry__free(struct hist_entry *); 31void hist_entry__free(struct hist_entry *);
27 32
28u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples); 33u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples);
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c
index b0210ae5b93..edd628f5337 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)
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 9b80c13cae4..31329a1cd32 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -18,10 +18,21 @@ char * field_sep;
18 18
19LIST_HEAD(hist_entry__sort_list); 19LIST_HEAD(hist_entry__sort_list);
20 20
21static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf,
22 size_t size, unsigned int width);
23static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf,
24 size_t size, unsigned int width);
25static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf,
26 size_t size, unsigned int width);
27static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
28 size_t size, unsigned int width);
29static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf,
30 size_t size, unsigned int width);
31
21struct sort_entry sort_thread = { 32struct sort_entry sort_thread = {
22 .header = "Command: Pid", 33 .header = "Command: Pid",
23 .cmp = sort__thread_cmp, 34 .cmp = sort__thread_cmp,
24 .print = sort__thread_print, 35 .snprintf = hist_entry__thread_snprintf,
25 .width = &threads__col_width, 36 .width = &threads__col_width,
26}; 37};
27 38
@@ -29,27 +40,27 @@ struct sort_entry sort_comm = {
29 .header = "Command", 40 .header = "Command",
30 .cmp = sort__comm_cmp, 41 .cmp = sort__comm_cmp,
31 .collapse = sort__comm_collapse, 42 .collapse = sort__comm_collapse,
32 .print = sort__comm_print, 43 .snprintf = hist_entry__comm_snprintf,
33 .width = &comms__col_width, 44 .width = &comms__col_width,
34}; 45};
35 46
36struct sort_entry sort_dso = { 47struct sort_entry sort_dso = {
37 .header = "Shared Object", 48 .header = "Shared Object",
38 .cmp = sort__dso_cmp, 49 .cmp = sort__dso_cmp,
39 .print = sort__dso_print, 50 .snprintf = hist_entry__dso_snprintf,
40 .width = &dsos__col_width, 51 .width = &dsos__col_width,
41}; 52};
42 53
43struct sort_entry sort_sym = { 54struct sort_entry sort_sym = {
44 .header = "Symbol", 55 .header = "Symbol",
45 .cmp = sort__sym_cmp, 56 .cmp = sort__sym_cmp,
46 .print = sort__sym_print, 57 .snprintf = hist_entry__sym_snprintf,
47}; 58};
48 59
49struct sort_entry sort_parent = { 60struct sort_entry sort_parent = {
50 .header = "Parent symbol", 61 .header = "Parent symbol",
51 .cmp = sort__parent_cmp, 62 .cmp = sort__parent_cmp,
52 .print = sort__parent_print, 63 .snprintf = hist_entry__parent_snprintf,
53 .width = &parent_symbol__col_width, 64 .width = &parent_symbol__col_width,
54}; 65};
55 66
@@ -85,45 +96,38 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
85 return right->thread->pid - left->thread->pid; 96 return right->thread->pid - left->thread->pid;
86} 97}
87 98
88int repsep_fprintf(FILE *fp, const char *fmt, ...) 99static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
89{ 100{
90 int n; 101 int n;
91 va_list ap; 102 va_list ap;
92 103
93 va_start(ap, fmt); 104 va_start(ap, fmt);
94 if (!field_sep) 105 n = vsnprintf(bf, size, fmt, ap);
95 n = vfprintf(fp, fmt, ap); 106 if (field_sep && n > 0) {
96 else { 107 char *sep = bf;
97 char *bf = NULL; 108
98 n = vasprintf(&bf, fmt, ap); 109 while (1) {
99 if (n > 0) { 110 sep = strchr(sep, *field_sep);
100 char *sep = bf; 111 if (sep == NULL)
101 112 break;
102 while (1) { 113 *sep = '.';
103 sep = strchr(sep, *field_sep);
104 if (sep == NULL)
105 break;
106 *sep = '.';
107 }
108 } 114 }
109 fputs(bf, fp);
110 free(bf);
111 } 115 }
112 va_end(ap); 116 va_end(ap);
113 return n; 117 return n;
114} 118}
115 119
116size_t 120static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf,
117sort__thread_print(FILE *fp, struct hist_entry *self, unsigned int width) 121 size_t size, unsigned int width)
118{ 122{
119 return repsep_fprintf(fp, "%*s:%5d", width - 6, 123 return repsep_snprintf(bf, size, "%*s:%5d", width,
120 self->thread->comm ?: "", self->thread->pid); 124 self->thread->comm ?: "", self->thread->pid);
121} 125}
122 126
123size_t 127static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf,
124sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width) 128 size_t size, unsigned int width)
125{ 129{
126 return repsep_fprintf(fp, "%*s", width, self->thread->comm); 130 return repsep_snprintf(bf, size, "%*s", width, self->thread->comm);
127} 131}
128 132
129/* --sort dso */ 133/* --sort dso */
@@ -149,16 +153,16 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
149 return strcmp(dso_name_l, dso_name_r); 153 return strcmp(dso_name_l, dso_name_r);
150} 154}
151 155
152size_t 156static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf,
153sort__dso_print(FILE *fp, struct hist_entry *self, unsigned int width) 157 size_t size, unsigned int width)
154{ 158{
155 if (self->ms.map && self->ms.map->dso) { 159 if (self->ms.map && self->ms.map->dso) {
156 const char *dso_name = !verbose ? self->ms.map->dso->short_name : 160 const char *dso_name = !verbose ? self->ms.map->dso->short_name :
157 self->ms.map->dso->long_name; 161 self->ms.map->dso->long_name;
158 return repsep_fprintf(fp, "%-*s", width, dso_name); 162 return repsep_snprintf(bf, size, "%-*s", width, dso_name);
159 } 163 }
160 164
161 return repsep_fprintf(fp, "%*llx", width, (u64)self->ip); 165 return repsep_snprintf(bf, size, "%*Lx", width, self->ip);
162} 166}
163 167
164/* --sort symbol */ 168/* --sort symbol */
@@ -177,22 +181,22 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
177 return (int64_t)(ip_r - ip_l); 181 return (int64_t)(ip_r - ip_l);
178} 182}
179 183
180 184static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
181size_t 185 size_t size, unsigned int width __used)
182sort__sym_print(FILE *fp, struct hist_entry *self, unsigned int width __used)
183{ 186{
184 size_t ret = 0; 187 size_t ret = 0;
185 188
186 if (verbose) { 189 if (verbose) {
187 char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!'; 190 char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!';
188 ret += repsep_fprintf(fp, "%#018llx %c ", (u64)self->ip, o); 191 ret += repsep_snprintf(bf, size, "%#018llx %c ", self->ip, o);
189 } 192 }
190 193
191 ret += repsep_fprintf(fp, "[%c] ", self->level); 194 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level);
192 if (self->ms.sym) 195 if (self->ms.sym)
193 ret += repsep_fprintf(fp, "%s", self->ms.sym->name); 196 ret += repsep_snprintf(bf + ret, size - ret, "%s",
197 self->ms.sym->name);
194 else 198 else
195 ret += repsep_fprintf(fp, "%#016llx", (u64)self->ip); 199 ret += repsep_snprintf(bf + ret, size - ret, "%#016llx", self->ip);
196 200
197 return ret; 201 return ret;
198} 202}
@@ -231,10 +235,10 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
231 return strcmp(sym_l->name, sym_r->name); 235 return strcmp(sym_l->name, sym_r->name);
232} 236}
233 237
234size_t 238static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf,
235sort__parent_print(FILE *fp, struct hist_entry *self, unsigned int width) 239 size_t size, unsigned int width)
236{ 240{
237 return repsep_fprintf(fp, "%-*s", width, 241 return repsep_snprintf(bf, size, "%-*s", width,
238 self->parent ? self->parent->name : "[other]"); 242 self->parent ? self->parent->name : "[other]");
239} 243}
240 244
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 598568696f9..439ec5fa0f5 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -76,7 +76,8 @@ struct sort_entry {
76 76
77 int64_t (*cmp)(struct hist_entry *, struct hist_entry *); 77 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
78 int64_t (*collapse)(struct hist_entry *, struct hist_entry *); 78 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
79 size_t (*print)(FILE *fp, struct hist_entry *, unsigned int width); 79 int (*snprintf)(struct hist_entry *self, char *bf, size_t size,
80 unsigned int width);
80 unsigned int *width; 81 unsigned int *width;
81 bool elide; 82 bool elide;
82}; 83};
@@ -86,7 +87,6 @@ extern struct list_head hist_entry__sort_list;
86 87
87void setup_sorting(const char * const usagestr[], const struct option *opts); 88void setup_sorting(const char * const usagestr[], const struct option *opts);
88 89
89extern int repsep_fprintf(FILE *fp, const char *fmt, ...);
90extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); 90extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int);
91extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); 91extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int);
92extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); 92extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int);