diff --git a/src/stacktrace.cc b/src/stacktrace.cc index 1b6309c..4af28cc 100644 --- a/src/stacktrace.cc +++ b/src/stacktrace.cc @@ -323,21 +323,18 @@ print_dump_stackmap_footer(const std::vector> &sorted_stack) { const time_point_t current = std::chrono::steady_clock::now(); - int cnt = 0; + int cnt = 1; + int top = opts.top; + int i = 0; size_t stack_size = sorted_stack.size(); - for (int i = 0; i < stack_size; i++) { + while (i < stack_size && i < top) { const stack_info_t &info = sorted_stack[i].second; - - if (i >= opts.top) - break; - const stack_trace_t &stack_trace = sorted_stack[i].first; std::string age = get_delta_time_unit(current - info.birth_time); std::stringstream ss_intro; std::stringstream ss_bt; - ++cnt; ss_intro << "=== backtrace #" << cnt << " === [count/peak: " << info.count << "/" << info.peak_count << "] " << "[size/peak: " << get_byte_unit(info.total_size) << "/" @@ -346,7 +343,14 @@ static void print_dump_stackmap(std::vector> &sorted_stack) { size_t stack_size = sorted_stack.size(); - for (int i = 0; i < stack_size; i++) { + int i = 0; + int top = opts.top; + + while (i < stack_size && i < top) { const stack_info_t &info = sorted_stack[i].second; uint64_t size = info.total_size; const char *semicolon = ""; - - if (i >= opts.top) - break; - const stack_trace_t &stack_trace = sorted_stack[i].first; std::stringstream ss_bt; @@ -371,8 +374,14 @@ print_dump_stackmap_flamegraph(std::vector