diff options
author | Namhyung Kim <namhyung@gmail.com> | 2011-12-27 10:35:49 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-01-03 11:36:32 -0500 |
commit | 15e6392feec311f1e409d77e1ccfe51c1d940365 (patch) | |
tree | f05f7251d39ae656c3157ac97716033c369e247a /tools/perf/builtin-stat.c | |
parent | 29c9862f1b818bf4caa4c48a30dbe5f25c84ee08 (diff) |
perf stat: Introduce get_ratio_color() helper
The get_ratio_color() returns appropriate color string based on @ratio.
It helps reducing code duplication.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1325000151-4463-2-git-send-email-namhyung@gmail.com
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r-- | tools/perf/builtin-stat.c | 91 |
1 files changed, 35 insertions, 56 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index cc53de335ced..f5d2a63eba66 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -578,6 +578,33 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg) | |||
578 | avg / avg_stats(&walltime_nsecs_stats)); | 578 | avg / avg_stats(&walltime_nsecs_stats)); |
579 | } | 579 | } |
580 | 580 | ||
581 | /* used for get_ratio_color() */ | ||
582 | enum grc_type { | ||
583 | GRC_STALLED_CYCLES_FE, | ||
584 | GRC_STALLED_CYCLES_BE, | ||
585 | GRC_CACHE_MISSES, | ||
586 | GRC_MAX_NR | ||
587 | }; | ||
588 | |||
589 | static const char *get_ratio_color(enum grc_type type, double ratio) | ||
590 | { | ||
591 | static const double grc_table[GRC_MAX_NR][3] = { | ||
592 | [GRC_STALLED_CYCLES_FE] = { 50.0, 30.0, 10.0 }, | ||
593 | [GRC_STALLED_CYCLES_BE] = { 75.0, 50.0, 20.0 }, | ||
594 | [GRC_CACHE_MISSES] = { 20.0, 10.0, 5.0 }, | ||
595 | }; | ||
596 | const char *color = PERF_COLOR_NORMAL; | ||
597 | |||
598 | if (ratio > grc_table[type][0]) | ||
599 | color = PERF_COLOR_RED; | ||
600 | else if (ratio > grc_table[type][1]) | ||
601 | color = PERF_COLOR_MAGENTA; | ||
602 | else if (ratio > grc_table[type][2]) | ||
603 | color = PERF_COLOR_YELLOW; | ||
604 | |||
605 | return color; | ||
606 | } | ||
607 | |||
581 | static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __used, double avg) | 608 | static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __used, double avg) |
582 | { | 609 | { |
583 | double total, ratio = 0.0; | 610 | double total, ratio = 0.0; |
@@ -588,13 +615,7 @@ static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __us | |||
588 | if (total) | 615 | if (total) |
589 | ratio = avg / total * 100.0; | 616 | ratio = avg / total * 100.0; |
590 | 617 | ||
591 | color = PERF_COLOR_NORMAL; | 618 | color = get_ratio_color(GRC_STALLED_CYCLES_FE, ratio); |
592 | if (ratio > 50.0) | ||
593 | color = PERF_COLOR_RED; | ||
594 | else if (ratio > 30.0) | ||
595 | color = PERF_COLOR_MAGENTA; | ||
596 | else if (ratio > 10.0) | ||
597 | color = PERF_COLOR_YELLOW; | ||
598 | 619 | ||
599 | fprintf(output, " # "); | 620 | fprintf(output, " # "); |
600 | color_fprintf(output, color, "%6.2f%%", ratio); | 621 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -611,13 +632,7 @@ static void print_stalled_cycles_backend(int cpu, struct perf_evsel *evsel __use | |||
611 | if (total) | 632 | if (total) |
612 | ratio = avg / total * 100.0; | 633 | ratio = avg / total * 100.0; |
613 | 634 | ||
614 | color = PERF_COLOR_NORMAL; | 635 | color = get_ratio_color(GRC_STALLED_CYCLES_BE, ratio); |
615 | if (ratio > 75.0) | ||
616 | color = PERF_COLOR_RED; | ||
617 | else if (ratio > 50.0) | ||
618 | color = PERF_COLOR_MAGENTA; | ||
619 | else if (ratio > 20.0) | ||
620 | color = PERF_COLOR_YELLOW; | ||
621 | 636 | ||
622 | fprintf(output, " # "); | 637 | fprintf(output, " # "); |
623 | color_fprintf(output, color, "%6.2f%%", ratio); | 638 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -634,13 +649,7 @@ static void print_branch_misses(int cpu, struct perf_evsel *evsel __used, double | |||
634 | if (total) | 649 | if (total) |
635 | ratio = avg / total * 100.0; | 650 | ratio = avg / total * 100.0; |
636 | 651 | ||
637 | color = PERF_COLOR_NORMAL; | 652 | color = get_ratio_color(GRC_CACHE_MISSES, ratio); |
638 | if (ratio > 20.0) | ||
639 | color = PERF_COLOR_RED; | ||
640 | else if (ratio > 10.0) | ||
641 | color = PERF_COLOR_MAGENTA; | ||
642 | else if (ratio > 5.0) | ||
643 | color = PERF_COLOR_YELLOW; | ||
644 | 653 | ||
645 | fprintf(output, " # "); | 654 | fprintf(output, " # "); |
646 | color_fprintf(output, color, "%6.2f%%", ratio); | 655 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -657,13 +666,7 @@ static void print_l1_dcache_misses(int cpu, struct perf_evsel *evsel __used, dou | |||
657 | if (total) | 666 | if (total) |
658 | ratio = avg / total * 100.0; | 667 | ratio = avg / total * 100.0; |
659 | 668 | ||
660 | color = PERF_COLOR_NORMAL; | 669 | color = get_ratio_color(GRC_CACHE_MISSES, ratio); |
661 | if (ratio > 20.0) | ||
662 | color = PERF_COLOR_RED; | ||
663 | else if (ratio > 10.0) | ||
664 | color = PERF_COLOR_MAGENTA; | ||
665 | else if (ratio > 5.0) | ||
666 | color = PERF_COLOR_YELLOW; | ||
667 | 670 | ||
668 | fprintf(output, " # "); | 671 | fprintf(output, " # "); |
669 | color_fprintf(output, color, "%6.2f%%", ratio); | 672 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -680,13 +683,7 @@ static void print_l1_icache_misses(int cpu, struct perf_evsel *evsel __used, dou | |||
680 | if (total) | 683 | if (total) |
681 | ratio = avg / total * 100.0; | 684 | ratio = avg / total * 100.0; |
682 | 685 | ||
683 | color = PERF_COLOR_NORMAL; | 686 | color = get_ratio_color(GRC_CACHE_MISSES, ratio); |
684 | if (ratio > 20.0) | ||
685 | color = PERF_COLOR_RED; | ||
686 | else if (ratio > 10.0) | ||
687 | color = PERF_COLOR_MAGENTA; | ||
688 | else if (ratio > 5.0) | ||
689 | color = PERF_COLOR_YELLOW; | ||
690 | 687 | ||
691 | fprintf(output, " # "); | 688 | fprintf(output, " # "); |
692 | color_fprintf(output, color, "%6.2f%%", ratio); | 689 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -703,13 +700,7 @@ static void print_dtlb_cache_misses(int cpu, struct perf_evsel *evsel __used, do | |||
703 | if (total) | 700 | if (total) |
704 | ratio = avg / total * 100.0; | 701 | ratio = avg / total * 100.0; |
705 | 702 | ||
706 | color = PERF_COLOR_NORMAL; | 703 | color = get_ratio_color(GRC_CACHE_MISSES, ratio); |
707 | if (ratio > 20.0) | ||
708 | color = PERF_COLOR_RED; | ||
709 | else if (ratio > 10.0) | ||
710 | color = PERF_COLOR_MAGENTA; | ||
711 | else if (ratio > 5.0) | ||
712 | color = PERF_COLOR_YELLOW; | ||
713 | 704 | ||
714 | fprintf(output, " # "); | 705 | fprintf(output, " # "); |
715 | color_fprintf(output, color, "%6.2f%%", ratio); | 706 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -726,13 +717,7 @@ static void print_itlb_cache_misses(int cpu, struct perf_evsel *evsel __used, do | |||
726 | if (total) | 717 | if (total) |
727 | ratio = avg / total * 100.0; | 718 | ratio = avg / total * 100.0; |
728 | 719 | ||
729 | color = PERF_COLOR_NORMAL; | 720 | color = get_ratio_color(GRC_CACHE_MISSES, ratio); |
730 | if (ratio > 20.0) | ||
731 | color = PERF_COLOR_RED; | ||
732 | else if (ratio > 10.0) | ||
733 | color = PERF_COLOR_MAGENTA; | ||
734 | else if (ratio > 5.0) | ||
735 | color = PERF_COLOR_YELLOW; | ||
736 | 721 | ||
737 | fprintf(output, " # "); | 722 | fprintf(output, " # "); |
738 | color_fprintf(output, color, "%6.2f%%", ratio); | 723 | color_fprintf(output, color, "%6.2f%%", ratio); |
@@ -749,13 +734,7 @@ static void print_ll_cache_misses(int cpu, struct perf_evsel *evsel __used, doub | |||
749 | if (total) | 734 | if (total) |
750 | ratio = avg / total * 100.0; | 735 | ratio = avg / total * 100.0; |
751 | 736 | ||
752 | color = PERF_COLOR_NORMAL; | 737 | color = get_ratio_color(GRC_CACHE_MISSES, ratio); |
753 | if (ratio > 20.0) | ||
754 | color = PERF_COLOR_RED; | ||
755 | else if (ratio > 10.0) | ||
756 | color = PERF_COLOR_MAGENTA; | ||
757 | else if (ratio > 5.0) | ||
758 | color = PERF_COLOR_YELLOW; | ||
759 | 738 | ||
760 | fprintf(output, " # "); | 739 | fprintf(output, " # "); |
761 | color_fprintf(output, color, "%6.2f%%", ratio); | 740 | color_fprintf(output, color, "%6.2f%%", ratio); |