diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-03-31 10:33:40 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-04-02 15:28:15 -0400 |
commit | a4e3b956a820162b7c1d616117b4f23b6017f504 (patch) | |
tree | 370116b6f6f4f8d3410a14831d394cf4993d04d8 /tools/perf/util/hist.c | |
parent | 70162138c91b040da3162fe1f34fe8aaf6506f10 (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/hist.c')
-rw-r--r-- | tools/perf/util/hist.c | 54 |
1 files changed, 37 insertions, 17 deletions
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, |