diff --git a/src/stacktrace.cc b/src/stacktrace.cc index 23b7f03..04c5740 100644 --- a/src/stacktrace.cc +++ b/src/stacktrace.cc @@ -314,21 +314,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) << "/" @@ -337,7 +334,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; @@ -361,8 +364,14 @@ print_dump_stackmap_flamegraph(std::vector