aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r--tools/perf/builtin-stat.c134
1 files changed, 43 insertions, 91 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 955930e0a5c..f5d2a63eba6 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() */
582enum grc_type {
583 GRC_STALLED_CYCLES_FE,
584 GRC_STALLED_CYCLES_BE,
585 GRC_CACHE_MISSES,
586 GRC_MAX_NR
587};
588
589static 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
581static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __used, double avg) 608static 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);
@@ -1108,22 +1087,13 @@ static const struct option options[] = {
1108 */ 1087 */
1109static int add_default_attributes(void) 1088static int add_default_attributes(void)
1110{ 1089{
1111 struct perf_evsel *pos;
1112 size_t attr_nr = 0;
1113 size_t c;
1114
1115 /* Set attrs if no event is selected and !null_run: */ 1090 /* Set attrs if no event is selected and !null_run: */
1116 if (null_run) 1091 if (null_run)
1117 return 0; 1092 return 0;
1118 1093
1119 if (!evsel_list->nr_entries) { 1094 if (!evsel_list->nr_entries) {
1120 for (c = 0; c < ARRAY_SIZE(default_attrs); c++) { 1095 if (perf_evlist__add_attrs_array(evsel_list, default_attrs) < 0)
1121 pos = perf_evsel__new(default_attrs + c, c + attr_nr); 1096 return -1;
1122 if (pos == NULL)
1123 return -1;
1124 perf_evlist__add(evsel_list, pos);
1125 }
1126 attr_nr += c;
1127 } 1097 }
1128 1098
1129 /* Detailed events get appended to the event list: */ 1099 /* Detailed events get appended to the event list: */
@@ -1132,38 +1102,21 @@ static int add_default_attributes(void)
1132 return 0; 1102 return 0;
1133 1103
1134 /* Append detailed run extra attributes: */ 1104 /* Append detailed run extra attributes: */
1135 for (c = 0; c < ARRAY_SIZE(detailed_attrs); c++) { 1105 if (perf_evlist__add_attrs_array(evsel_list, detailed_attrs) < 0)
1136 pos = perf_evsel__new(detailed_attrs + c, c + attr_nr); 1106 return -1;
1137 if (pos == NULL)
1138 return -1;
1139 perf_evlist__add(evsel_list, pos);
1140 }
1141 attr_nr += c;
1142 1107
1143 if (detailed_run < 2) 1108 if (detailed_run < 2)
1144 return 0; 1109 return 0;
1145 1110
1146 /* Append very detailed run extra attributes: */ 1111 /* Append very detailed run extra attributes: */
1147 for (c = 0; c < ARRAY_SIZE(very_detailed_attrs); c++) { 1112 if (perf_evlist__add_attrs_array(evsel_list, very_detailed_attrs) < 0)
1148 pos = perf_evsel__new(very_detailed_attrs + c, c + attr_nr); 1113 return -1;
1149 if (pos == NULL)
1150 return -1;
1151 perf_evlist__add(evsel_list, pos);
1152 }
1153 1114
1154 if (detailed_run < 3) 1115 if (detailed_run < 3)
1155 return 0; 1116 return 0;
1156 1117
1157 /* Append very, very detailed run extra attributes: */ 1118 /* Append very, very detailed run extra attributes: */
1158 for (c = 0; c < ARRAY_SIZE(very_very_detailed_attrs); c++) { 1119 return perf_evlist__add_attrs_array(evsel_list, very_very_detailed_attrs);
1159 pos = perf_evsel__new(very_very_detailed_attrs + c, c + attr_nr);
1160 if (pos == NULL)
1161 return -1;
1162 perf_evlist__add(evsel_list, pos);
1163 }
1164
1165
1166 return 0;
1167} 1120}
1168 1121
1169int cmd_stat(int argc, const char **argv, const char *prefix __used) 1122int cmd_stat(int argc, const char **argv, const char *prefix __used)
@@ -1267,8 +1220,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
1267 1220
1268 list_for_each_entry(pos, &evsel_list->entries, node) { 1221 list_for_each_entry(pos, &evsel_list->entries, node) {
1269 if (perf_evsel__alloc_stat_priv(pos) < 0 || 1222 if (perf_evsel__alloc_stat_priv(pos) < 0 ||
1270 perf_evsel__alloc_counts(pos, evsel_list->cpus->nr) < 0 || 1223 perf_evsel__alloc_counts(pos, evsel_list->cpus->nr) < 0)
1271 perf_evsel__alloc_fd(pos, evsel_list->cpus->nr, evsel_list->threads->nr) < 0)
1272 goto out_free_fd; 1224 goto out_free_fd;
1273 } 1225 }
1274 1226