diff options
-rw-r--r-- | tools/perf/util/color.c | 53 | ||||
-rw-r--r-- | tools/perf/util/color.h | 4 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 54 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 7 | ||||
-rw-r--r-- | tools/perf/util/newt.c | 53 | ||||
-rw-r--r-- | tools/perf/util/sort.c | 88 | ||||
-rw-r--r-- | tools/perf/util/sort.h | 4 |
7 files changed, 149 insertions, 114 deletions
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index 9da01914e0af..e191eb9a667f 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 | ||
169 | static 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 | |||
169 | static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, | 194 | static 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 | ||
219 | int 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 | |||
194 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args) | 225 | int 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 | ||
230 | int 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 | ||
200 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) | 242 | int 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 | |||
320 | int 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 24e8809210bb..dea082b79602 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); | |||
32 | int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); | 32 | int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); |
33 | void color_parse(const char *value, const char *var, char *dst); | 33 | void color_parse(const char *value, const char *var, char *dst); |
34 | void color_parse_mem(const char *value, int len, const char *var, char *dst); | 34 | void color_parse_mem(const char *value, int len, const char *var, char *dst); |
35 | int color_vsnprintf(char *bf, size_t size, const char *color, | ||
36 | const char *fmt, va_list args); | ||
35 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); | 37 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); |
36 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); | 38 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); |
39 | int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...); | ||
37 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); | 40 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); |
38 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); | 41 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); |
42 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent); | ||
39 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); | 43 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); |
40 | const char *get_percent_color(double percent); | 44 | const char *get_percent_color(double percent); |
41 | 45 | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index a46d09332462..f0794913d575 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 | ||
458 | size_t hist_entry__fprintf(struct hist_entry *self, | 458 | int 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 | |||
545 | int 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 | ||
538 | static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp, | 558 | static 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 da6a8c1320fa..ad17f0ad798b 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); |
19 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | 19 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); |
20 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | 20 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); |
21 | size_t hist_entry__fprintf(struct hist_entry *self, | 21 | int 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); |
26 | int 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); | ||
26 | void hist_entry__free(struct hist_entry *); | 31 | void hist_entry__free(struct hist_entry *); |
27 | 32 | ||
28 | u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples); | 33 | u64 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 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 | */ | ||
300 | static char *skip_spaces(const char *str) | ||
301 | { | ||
302 | while (isspace(*str)) | ||
303 | ++str; | ||
304 | return (char *)str; | ||
305 | } | ||
306 | |||
307 | static 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 | |||
325 | static size_t hist_entry__append_browser(struct hist_entry *self, | 297 | static 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 | ||
363 | static void map_symbol__annotate_browser(const struct map_symbol *self) | 320 | static 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 9b80c13cae46..31329a1cd324 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -18,10 +18,21 @@ char * field_sep; | |||
18 | 18 | ||
19 | LIST_HEAD(hist_entry__sort_list); | 19 | LIST_HEAD(hist_entry__sort_list); |
20 | 20 | ||
21 | static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf, | ||
22 | size_t size, unsigned int width); | ||
23 | static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, | ||
24 | size_t size, unsigned int width); | ||
25 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, | ||
26 | size_t size, unsigned int width); | ||
27 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | ||
28 | size_t size, unsigned int width); | ||
29 | static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf, | ||
30 | size_t size, unsigned int width); | ||
31 | |||
21 | struct sort_entry sort_thread = { | 32 | struct 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 | ||
36 | struct sort_entry sort_dso = { | 47 | struct 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 | ||
43 | struct sort_entry sort_sym = { | 54 | struct 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 | ||
49 | struct sort_entry sort_parent = { | 60 | struct 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 | ||
88 | int repsep_fprintf(FILE *fp, const char *fmt, ...) | 99 | static 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 | ||
116 | size_t | 120 | static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf, |
117 | sort__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 | ||
123 | size_t | 127 | static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, |
124 | sort__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 | ||
152 | size_t | 156 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, |
153 | sort__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 | 184 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | |
181 | size_t | 185 | size_t size, unsigned int width __used) |
182 | sort__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 | ||
234 | size_t | 238 | static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf, |
235 | sort__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 598568696f97..439ec5fa0f5f 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 | ||
87 | void setup_sorting(const char * const usagestr[], const struct option *opts); | 88 | void setup_sorting(const char * const usagestr[], const struct option *opts); |
88 | 89 | ||
89 | extern int repsep_fprintf(FILE *fp, const char *fmt, ...); | ||
90 | extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); | 90 | extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); |
91 | extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); | 91 | extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); |
92 | extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); | 92 | extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); |