diff options
-rw-r--r-- | tools/perf/util/callchain.c | 111 |
1 files changed, 74 insertions, 37 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index d78776a20e80..3cea1fb5404b 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -1105,63 +1105,100 @@ int callchain_branch_counts(struct callchain_root *root, | |||
1105 | cycles_count); | 1105 | cycles_count); |
1106 | } | 1106 | } |
1107 | 1107 | ||
1108 | static int callchain_counts_printf(FILE *fp, char *bf, int bfsize, | 1108 | static int counts_str_build(char *bf, int bfsize, |
1109 | u64 branch_count, u64 predicted_count, | 1109 | u64 branch_count, u64 predicted_count, |
1110 | u64 abort_count, u64 cycles_count, | 1110 | u64 abort_count, u64 cycles_count, |
1111 | u64 iter_count, u64 samples_count) | 1111 | u64 iter_count, u64 samples_count) |
1112 | { | 1112 | { |
1113 | double predicted_percent = 0.0; | 1113 | double predicted_percent = 0.0; |
1114 | const char *null_str = ""; | 1114 | const char *null_str = ""; |
1115 | char iter_str[32]; | 1115 | char iter_str[32]; |
1116 | char *str; | 1116 | char cycle_str[32]; |
1117 | u64 cycles = 0; | 1117 | char *istr, *cstr; |
1118 | 1118 | u64 cycles; | |
1119 | if (branch_count == 0) { | ||
1120 | if (fp) | ||
1121 | return fprintf(fp, " (calltrace)"); | ||
1122 | 1119 | ||
1120 | if (branch_count == 0) | ||
1123 | return scnprintf(bf, bfsize, " (calltrace)"); | 1121 | return scnprintf(bf, bfsize, " (calltrace)"); |
1124 | } | 1122 | |
1123 | cycles = cycles_count / branch_count; | ||
1125 | 1124 | ||
1126 | if (iter_count && samples_count) { | 1125 | if (iter_count && samples_count) { |
1127 | scnprintf(iter_str, sizeof(iter_str), | 1126 | if (cycles > 0) |
1128 | ", iterations:%" PRId64 "", | 1127 | scnprintf(iter_str, sizeof(iter_str), |
1129 | iter_count / samples_count); | 1128 | " iterations:%" PRId64 "", |
1130 | str = iter_str; | 1129 | iter_count / samples_count); |
1130 | else | ||
1131 | scnprintf(iter_str, sizeof(iter_str), | ||
1132 | "iterations:%" PRId64 "", | ||
1133 | iter_count / samples_count); | ||
1134 | istr = iter_str; | ||
1135 | } else | ||
1136 | istr = (char *)null_str; | ||
1137 | |||
1138 | if (cycles > 0) { | ||
1139 | scnprintf(cycle_str, sizeof(cycle_str), | ||
1140 | "cycles:%" PRId64 "", cycles); | ||
1141 | cstr = cycle_str; | ||
1131 | } else | 1142 | } else |
1132 | str = (char *)null_str; | 1143 | cstr = (char *)null_str; |
1133 | 1144 | ||
1134 | predicted_percent = predicted_count * 100.0 / branch_count; | 1145 | predicted_percent = predicted_count * 100.0 / branch_count; |
1135 | cycles = cycles_count / branch_count; | ||
1136 | 1146 | ||
1137 | if ((predicted_percent >= 100.0) && (abort_count == 0)) { | 1147 | if ((predicted_count == branch_count) && (abort_count == 0)) { |
1138 | if (fp) | 1148 | if ((cycles > 0) || (istr != (char *)null_str)) |
1139 | return fprintf(fp, " (cycles:%" PRId64 "%s)", | 1149 | return scnprintf(bf, bfsize, " (%s%s)", cstr, istr); |
1140 | cycles, str); | 1150 | else |
1151 | return scnprintf(bf, bfsize, "%s", (char *)null_str); | ||
1152 | } | ||
1141 | 1153 | ||
1142 | return scnprintf(bf, bfsize, " (cycles:%" PRId64 "%s)", | 1154 | if ((predicted_count < branch_count) && (abort_count == 0)) { |
1143 | cycles, str); | 1155 | if ((cycles > 0) || (istr != (char *)null_str)) |
1156 | return scnprintf(bf, bfsize, | ||
1157 | " (predicted:%.1f%% %s%s)", | ||
1158 | predicted_percent, cstr, istr); | ||
1159 | else { | ||
1160 | return scnprintf(bf, bfsize, | ||
1161 | " (predicted:%.1f%%)", | ||
1162 | predicted_percent); | ||
1163 | } | ||
1144 | } | 1164 | } |
1145 | 1165 | ||
1146 | if ((predicted_percent < 100.0) && (abort_count == 0)) { | 1166 | if ((predicted_count == branch_count) && (abort_count > 0)) { |
1147 | if (fp) | 1167 | if ((cycles > 0) || (istr != (char *)null_str)) |
1148 | return fprintf(fp, | 1168 | return scnprintf(bf, bfsize, |
1149 | " (predicted:%.1f%%, cycles:%" PRId64 "%s)", | 1169 | " (abort:%" PRId64 " %s%s)", |
1150 | predicted_percent, cycles, str); | 1170 | abort_count, cstr, istr); |
1171 | else | ||
1172 | return scnprintf(bf, bfsize, | ||
1173 | " (abort:%" PRId64 ")", | ||
1174 | abort_count); | ||
1175 | } | ||
1151 | 1176 | ||
1177 | if ((cycles > 0) || (istr != (char *)null_str)) | ||
1152 | return scnprintf(bf, bfsize, | 1178 | return scnprintf(bf, bfsize, |
1153 | " (predicted:%.1f%%, cycles:%" PRId64 "%s)", | 1179 | " (predicted:%.1f%% abort:%" PRId64 " %s%s)", |
1154 | predicted_percent, cycles, str); | 1180 | predicted_percent, abort_count, cstr, istr); |
1155 | } | 1181 | |
1182 | return scnprintf(bf, bfsize, | ||
1183 | " (predicted:%.1f%% abort:%" PRId64 ")", | ||
1184 | predicted_percent, abort_count); | ||
1185 | } | ||
1186 | |||
1187 | static int callchain_counts_printf(FILE *fp, char *bf, int bfsize, | ||
1188 | u64 branch_count, u64 predicted_count, | ||
1189 | u64 abort_count, u64 cycles_count, | ||
1190 | u64 iter_count, u64 samples_count) | ||
1191 | { | ||
1192 | char str[128]; | ||
1193 | |||
1194 | counts_str_build(str, sizeof(str), branch_count, | ||
1195 | predicted_count, abort_count, cycles_count, | ||
1196 | iter_count, samples_count); | ||
1156 | 1197 | ||
1157 | if (fp) | 1198 | if (fp) |
1158 | return fprintf(fp, | 1199 | return fprintf(fp, "%s", str); |
1159 | " (predicted:%.1f%%, abort:%" PRId64 ", cycles:%" PRId64 "%s)", | ||
1160 | predicted_percent, abort_count, cycles, str); | ||
1161 | 1200 | ||
1162 | return scnprintf(bf, bfsize, | 1201 | return scnprintf(bf, bfsize, "%s", str); |
1163 | " (predicted:%.1f%%, abort:%" PRId64 ", cycles:%" PRId64 "%s)", | ||
1164 | predicted_percent, abort_count, cycles, str); | ||
1165 | } | 1202 | } |
1166 | 1203 | ||
1167 | int callchain_list_counts__printf_value(struct callchain_node *node, | 1204 | int callchain_list_counts__printf_value(struct callchain_node *node, |