@@ -1151,9 +1151,20 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
1151
1151
struct branch_entry * entries = perf_sample__branch_entries (sample );
1152
1152
uint64_t i ;
1153
1153
1154
- printf ("%s: nr:%" PRIu64 "\n" ,
1155
- !callstack ? "... branch stack" : "... branch callstack" ,
1156
- sample -> branch_stack -> nr );
1154
+ if (!callstack ) {
1155
+ printf ("%s: nr:%" PRIu64 "\n" , "... branch stack" , sample -> branch_stack -> nr );
1156
+ } else {
1157
+ /* the reason of adding 1 to nr is because after expanding
1158
+ * branch stack it generates nr + 1 callstack records. e.g.,
1159
+ * B()->C()
1160
+ * A()->B()
1161
+ * the final callstack should be:
1162
+ * C()
1163
+ * B()
1164
+ * A()
1165
+ */
1166
+ printf ("%s: nr:%" PRIu64 "\n" , "... branch callstack" , sample -> branch_stack -> nr + 1 );
1167
+ }
1157
1168
1158
1169
for (i = 0 ; i < sample -> branch_stack -> nr ; i ++ ) {
1159
1170
struct branch_entry * e = & entries [i ];
@@ -1169,8 +1180,13 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
1169
1180
(unsigned )e -> flags .reserved ,
1170
1181
e -> flags .type ? branch_type_name (e -> flags .type ) : "" );
1171
1182
} else {
1172
- printf ("..... %2" PRIu64 ": %016" PRIx64 "\n" ,
1173
- i , i > 0 ? e -> from : e -> to );
1183
+ if (i == 0 ) {
1184
+ printf ("..... %2" PRIu64 ": %016" PRIx64 "\n"
1185
+ "..... %2" PRIu64 ": %016" PRIx64 "\n" ,
1186
+ i , e -> to , i + 1 , e -> from );
1187
+ } else {
1188
+ printf ("..... %2" PRIu64 ": %016" PRIx64 "\n" , i + 1 , e -> from );
1189
+ }
1174
1190
}
1175
1191
}
1176
1192
}
0 commit comments