Skip to content

Commit 748618d

Browse files
committed
stacktrace: Implement is_ignored function
is_ignored function can be used to check whether the input `report` contains any ignore string. Ignore string can be read from the given file. Each line of the file is considered as ignore string. Ignore string could be function name, library name as well as something you want. Ignore file example: $ cat ignore.txt libfoo bar baz Signed-off-by: Bojun Seo <bojun.seo.0@gmail.com>
1 parent 5155231 commit 748618d

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/stacktrace.cc

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <map>
1818
#include <sstream>
1919
#include <vector>
20-
2120
#include <mutex>
2221

2322
#include "compiler.h"
@@ -33,9 +32,40 @@
3332

3433
std::map<stack_trace_t, stack_info_t> stackmap;
3534
std::map<addr_t, object_info_t> addrmap;
35+
std::vector<std::string> ignorevec;
36+
bool ignorevec_initialized = false;
3637

3738
std::recursive_mutex container_mutex;
3839

40+
static void lazyinit_ignorevec()
41+
{
42+
if (ignorevec_initialized)
43+
return;
44+
45+
opts.ignore = getenv("HEAPTRACE_IGNORE");
46+
if (opts.ignore) {
47+
std::ifstream file(opts.ignore);
48+
if (file.is_open()) {
49+
std::string line;
50+
while (std::getline(file, line)) {
51+
ignorevec.push_back(line);
52+
}
53+
file.close();
54+
}
55+
else {
56+
pr_out("Failed to open file %s\n", opts.ignore);
57+
}
58+
}
59+
ignorevec_initialized = true;
60+
}
61+
62+
static bool is_ignored(const std::string &report)
63+
{
64+
lazyinit_ignorevec();
65+
return std::any_of(ignorevec.begin(), ignorevec.end(), [&report](const std::string& s)
66+
{ return report.find(s) != std::string::npos; });
67+
}
68+
3969
// record_backtrace() is defined in stacktrace.h as an inline function.
4070
void __record_backtrace(size_t size, void *addr, stack_trace_t &stack_trace, int nptrs)
4171
{

0 commit comments

Comments
 (0)