aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Yao <yao.jin@linux.intel.com>2016-10-30 21:19:51 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-11-14 11:25:58 -0500
commit3dd029ef94018dfa499c05778dd67d03c00b637c (patch)
treefd9bb6986c7adfe58ba6d5a453f7e3fb6347a15e
parentf9a7be7c024319423623f58f5233234cad714e6b (diff)
perf report: Calculate and return the branch flag counting
Create some branch counters in per callchain list entry. Each counter is for a branch flag. For example, predicted_count counts all the *predicted* branches. The counters get updated by processing the callchain cursor nodes. It also provides functions to retrieve or print the values of counters in callchain list. Besides the counting for branch flags, it also counts and returns the average number of iterations. Signed-off-by: Yao Jin <yao.jin@linux.intel.com> Acked-by: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@intel.com> Cc: Linux-kernel@vger.kernel.org Cc: Yao Jin <yao.jin@linux.intel.com> Link: http://lkml.kernel.org/r/1477876794-30749-4-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/callchain.c189
-rw-r--r--tools/perf/util/callchain.h14
2 files changed, 202 insertions, 1 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 138a415fad0d..823befd8209a 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -438,6 +438,21 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
438 call->ip = cursor_node->ip; 438 call->ip = cursor_node->ip;
439 call->ms.sym = cursor_node->sym; 439 call->ms.sym = cursor_node->sym;
440 call->ms.map = cursor_node->map; 440 call->ms.map = cursor_node->map;
441
442 if (cursor_node->branch) {
443 call->branch_count = 1;
444
445 if (cursor_node->branch_flags.predicted)
446 call->predicted_count = 1;
447
448 if (cursor_node->branch_flags.abort)
449 call->abort_count = 1;
450
451 call->cycles_count = cursor_node->branch_flags.cycles;
452 call->iter_count = cursor_node->nr_loop_iter;
453 call->samples_count = cursor_node->samples;
454 }
455
441 list_add_tail(&call->list, &node->val); 456 list_add_tail(&call->list, &node->val);
442 457
443 callchain_cursor_advance(cursor); 458 callchain_cursor_advance(cursor);
@@ -497,8 +512,23 @@ static enum match_result match_chain(struct callchain_cursor_node *node,
497 right = node->ip; 512 right = node->ip;
498 } 513 }
499 514
500 if (left == right) 515 if (left == right) {
516 if (node->branch) {
517 cnode->branch_count++;
518
519 if (node->branch_flags.predicted)
520 cnode->predicted_count++;
521
522 if (node->branch_flags.abort)
523 cnode->abort_count++;
524
525 cnode->cycles_count += node->branch_flags.cycles;
526 cnode->iter_count += node->nr_loop_iter;
527 cnode->samples_count += node->samples;
528 }
529
501 return MATCH_EQ; 530 return MATCH_EQ;
531 }
502 532
503 return left > right ? MATCH_GT : MATCH_LT; 533 return left > right ? MATCH_GT : MATCH_LT;
504} 534}
@@ -947,6 +977,163 @@ int callchain_node__fprintf_value(struct callchain_node *node,
947 return 0; 977 return 0;
948} 978}
949 979
980static void callchain_counts_value(struct callchain_node *node,
981 u64 *branch_count, u64 *predicted_count,
982 u64 *abort_count, u64 *cycles_count)
983{
984 struct callchain_list *clist;
985
986 list_for_each_entry(clist, &node->val, list) {
987 if (branch_count)
988 *branch_count += clist->branch_count;
989
990 if (predicted_count)
991 *predicted_count += clist->predicted_count;
992
993 if (abort_count)
994 *abort_count += clist->abort_count;
995
996 if (cycles_count)
997 *cycles_count += clist->cycles_count;
998 }
999}
1000
1001static int callchain_node_branch_counts_cumul(struct callchain_node *node,
1002 u64 *branch_count,
1003 u64 *predicted_count,
1004 u64 *abort_count,
1005 u64 *cycles_count)
1006{
1007 struct callchain_node *child;
1008 struct rb_node *n;
1009
1010 n = rb_first(&node->rb_root_in);
1011 while (n) {
1012 child = rb_entry(n, struct callchain_node, rb_node_in);
1013 n = rb_next(n);
1014
1015 callchain_node_branch_counts_cumul(child, branch_count,
1016 predicted_count,
1017 abort_count,
1018 cycles_count);
1019
1020 callchain_counts_value(child, branch_count,
1021 predicted_count, abort_count,
1022 cycles_count);
1023 }
1024
1025 return 0;
1026}
1027
1028int callchain_branch_counts(struct callchain_root *root,
1029 u64 *branch_count, u64 *predicted_count,
1030 u64 *abort_count, u64 *cycles_count)
1031{
1032 if (branch_count)
1033 *branch_count = 0;
1034
1035 if (predicted_count)
1036 *predicted_count = 0;
1037
1038 if (abort_count)
1039 *abort_count = 0;
1040
1041 if (cycles_count)
1042 *cycles_count = 0;
1043
1044 return callchain_node_branch_counts_cumul(&root->node,
1045 branch_count,
1046 predicted_count,
1047 abort_count,
1048 cycles_count);
1049}
1050
1051static int callchain_counts_printf(FILE *fp, char *bf, int bfsize,
1052 u64 branch_count, u64 predicted_count,
1053 u64 abort_count, u64 cycles_count,
1054 u64 iter_count, u64 samples_count)
1055{
1056 double predicted_percent = 0.0;
1057 const char *null_str = "";
1058 char iter_str[32];
1059 char *str;
1060 u64 cycles = 0;
1061
1062 if (branch_count == 0) {
1063 if (fp)
1064 return fprintf(fp, " (calltrace)");
1065
1066 return scnprintf(bf, bfsize, " (calltrace)");
1067 }
1068
1069 if (iter_count && samples_count) {
1070 scnprintf(iter_str, sizeof(iter_str),
1071 ", iterations:%" PRId64 "",
1072 iter_count / samples_count);
1073 str = iter_str;
1074 } else
1075 str = (char *)null_str;
1076
1077 predicted_percent = predicted_count * 100.0 / branch_count;
1078 cycles = cycles_count / branch_count;
1079
1080 if ((predicted_percent >= 100.0) && (abort_count == 0)) {
1081 if (fp)
1082 return fprintf(fp, " (cycles:%" PRId64 "%s)",
1083 cycles, str);
1084
1085 return scnprintf(bf, bfsize, " (cycles:%" PRId64 "%s)",
1086 cycles, str);
1087 }
1088
1089 if ((predicted_percent < 100.0) && (abort_count == 0)) {
1090 if (fp)
1091 return fprintf(fp,
1092 " (predicted:%.1f%%, cycles:%" PRId64 "%s)",
1093 predicted_percent, cycles, str);
1094
1095 return scnprintf(bf, bfsize,
1096 " (predicted:%.1f%%, cycles:%" PRId64 "%s)",
1097 predicted_percent, cycles, str);
1098 }
1099
1100 if (fp)
1101 return fprintf(fp,
1102 " (predicted:%.1f%%, abort:%" PRId64 ", cycles:%" PRId64 "%s)",
1103 predicted_percent, abort_count, cycles, str);
1104
1105 return scnprintf(bf, bfsize,
1106 " (predicted:%.1f%%, abort:%" PRId64 ", cycles:%" PRId64 "%s)",
1107 predicted_percent, abort_count, cycles, str);
1108}
1109
1110int callchain_list_counts__printf_value(struct callchain_node *node,
1111 struct callchain_list *clist,
1112 FILE *fp, char *bf, int bfsize)
1113{
1114 u64 branch_count, predicted_count;
1115 u64 abort_count, cycles_count;
1116 u64 iter_count = 0, samples_count = 0;
1117
1118 branch_count = clist->branch_count;
1119 predicted_count = clist->predicted_count;
1120 abort_count = clist->abort_count;
1121 cycles_count = clist->cycles_count;
1122
1123 if (node) {
1124 struct callchain_list *call;
1125
1126 list_for_each_entry(call, &node->val, list) {
1127 iter_count += call->iter_count;
1128 samples_count += call->samples_count;
1129 }
1130 }
1131
1132 return callchain_counts_printf(fp, bf, bfsize, branch_count,
1133 predicted_count, abort_count,
1134 cycles_count, iter_count, samples_count);
1135}
1136
950static void free_callchain_node(struct callchain_node *node) 1137static void free_callchain_node(struct callchain_node *node)
951{ 1138{
952 struct callchain_list *list, *tmp; 1139 struct callchain_list *list, *tmp;
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index df6329d1c350..d9c70dccf06a 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -111,6 +111,12 @@ struct callchain_list {
111 bool unfolded; 111 bool unfolded;
112 bool has_children; 112 bool has_children;
113 }; 113 };
114 u64 branch_count;
115 u64 predicted_count;
116 u64 abort_count;
117 u64 cycles_count;
118 u64 iter_count;
119 u64 samples_count;
114 char *srcline; 120 char *srcline;
115 struct list_head list; 121 struct list_head list;
116}; 122};
@@ -263,8 +269,16 @@ char *callchain_node__scnprintf_value(struct callchain_node *node,
263int callchain_node__fprintf_value(struct callchain_node *node, 269int callchain_node__fprintf_value(struct callchain_node *node,
264 FILE *fp, u64 total); 270 FILE *fp, u64 total);
265 271
272int callchain_list_counts__printf_value(struct callchain_node *node,
273 struct callchain_list *clist,
274 FILE *fp, char *bf, int bfsize);
275
266void free_callchain(struct callchain_root *root); 276void free_callchain(struct callchain_root *root);
267void decay_callchain(struct callchain_root *root); 277void decay_callchain(struct callchain_root *root);
268int callchain_node__make_parent_list(struct callchain_node *node); 278int callchain_node__make_parent_list(struct callchain_node *node);
269 279
280int callchain_branch_counts(struct callchain_root *root,
281 u64 *branch_count, u64 *predicted_count,
282 u64 *abort_count, u64 *cycles_count);
283
270#endif /* __PERF_CALLCHAIN_H */ 284#endif /* __PERF_CALLCHAIN_H */