Skip to content

Commit

Permalink
stacktrace: Implement ignore
Browse files Browse the repository at this point in the history
If user want to ignore certain report, it could be filtered out.
The filtering list can be given with the file, each line is used
on filtering. The usage is as follows:

  $ ./heaptrace --ignore=ignore.txt samples/factorial.out
  [heaptrace] initialized for /proc/227960/maps (factorial.out)
  [heaptrace]   finalized for /proc/227960/maps (factorial.out)
  =================================================================
  [heaptrace] dump allocation sorted by 'size' for /proc/227960/maps (factorial.out)
  [heaptrace] heap traced num of backtrace : 9
  [heaptrace] heap traced allocation size  : 48 bytes
  [heaptrace] allocator info (virtual)     : 135.168 KB
  [heaptrace] allocator info (resident)    : 89.904 KB
  [heaptrace] statm info (VSS/RSS/shared)  : 6.270 MB / 3.932 MB / 3.801 MB
  =================================================================

  $ cat ignore.txt
  libfoo
  bar
  fac
  baz

The original execution of samples/factorial.out is like followings:

  $ ./heaptrace samples/factorial.out
  [heaptrace] initialized for /proc/227946/maps (factorial.out)
  [heaptrace]   finalized for /proc/227946/maps (factorial.out)
  =================================================================
  [heaptrace] dump allocation sorted by 'size' for /proc/227946/maps (factorial.out)
  === backtrace #1 === [count/peak: 1/1] [size/peak: 10 bytes/10 bytes] [age: 325.674 us]
  0 [0x7f71089b8b6f] malloc +0x1f (./libheaptrace.so +0x4b6f)
  1 [0x557ebd3191c4] fac +0xe (samples/factorial.out +0x11c4)
  2 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  3 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  4 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  5 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  6 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  7 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)

  --- snip ---

  === backtrace #9 === [count/peak: 2/2] [size/peak: 1 bytes/1 bytes] [age: 330.780 us]
  0 [0x7f71089b8b6f] malloc +0x1f (./libheaptrace.so +0x4b6f)
  1 [0x557ebd3191a5] fac +0x7 (samples/factorial.out +0x11a5)
  2 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  3 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  4 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  5 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  6 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)
  7 [0x557ebd3191d8] fac +0x13 (samples/factorial.out +0x11d8)

  [heaptrace] heap traced num of backtrace : 9
  [heaptrace] heap traced allocation size  : 48 bytes
  [heaptrace] allocator info (virtual)     : 135.168 KB
  [heaptrace] allocator info (resident)    : 89.776 KB
  [heaptrace] statm info (VSS/RSS/shared)  : 6.270 MB / 3.932 MB / 3.801 MB
  =================================================================

Signed-off-by: Bojun Seo <[email protected]>
  • Loading branch information
Bojun-Seo committed Nov 24, 2024
1 parent 748618d commit 351e444
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,18 @@ print_dump_stackmap_footer(const std::vector<std::pair<stack_trace_t, stack_info
static void print_dump_stackmap(std::vector<std::pair<stack_trace_t, stack_info_t>> &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) << "/"
Expand All @@ -346,22 +343,28 @@ static void print_dump_stackmap(std::vector<std::pair<stack_trace_t, stack_info_
for (int j = 0; j < info.stack_depth; j++)
get_backtrace_string(j, stack_trace[j], ss_bt);

pr_out("%s%s\n", ss_intro.str().c_str(), ss_bt.str().c_str());
if (is_ignored(ss_bt.str())) {
++top;
}
else {
pr_out("%s%s\n", ss_intro.str().c_str(), ss_bt.str().c_str());
++cnt;
}
++i;
}
}

static void
print_dump_stackmap_flamegraph(std::vector<std::pair<stack_trace_t, stack_info_t>> &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;

Expand All @@ -371,8 +374,14 @@ print_dump_stackmap_flamegraph(std::vector<std::pair<stack_trace_t, stack_info_t
semicolon, ss_bt);
semicolon = ";";
}
pr_out("%s", ss_bt.str().c_str());
pr_out(" %" PRIu64 "\n", size);
if (is_ignored(ss_bt.str())) {
++top;
}
else {
pr_out("%s", ss_bt.str().c_str());
pr_out(" %" PRIu64 "\n", size);
}
++i;
}

fflush(outfp);
Expand Down

0 comments on commit 351e444

Please sign in to comment.