-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInstrumentationFilter.hpp
81 lines (67 loc) · 2.29 KB
/
InstrumentationFilter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef INSTRUMENTATION_FILTER_HPP
#define INSTRUMENTATION_FILTER_HPP
#include "json11.hpp"
#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
#include <fstream>
#include <map>
using namespace std;
using namespace json11;
typedef enum {FN_SIZE_LOC, FN_SIZE_IR, FN_SIZE_PATH} fn_size_metrics;
class InstrumentationFilter {
private:
Json filters;
bool loaded;
string fname;
map<string, int> functions;
bool globMatch(string glob, string s);
void testGlob();
bool checkFunctionBlacklist(string function_name);
bool checkFileBlacklist(string file_name);
string findBestFunctionMatch(string function_name);
public:
InstrumentationFilter() : loaded(false) {
string filename("function_sizes.json");
const char * val = ::getenv("DIN_MAPS");
string prefix = "./";
if ((val == 0) || (strcmp(val,"") == 0)) {
cerr << "DIN_MAPS not set, falling back to current directory" << endl;
} else {
prefix = val;
prefix += "/";
}
ifstream mapin;
fname = prefix + filename;
mapin.open(fname);
if (!mapin.is_open()) {
return;
}
stringstream ss;
string err;
ss << mapin.rdbuf();
json11::Json jsmap;
jsmap = json11::Json::parse(ss.str(), err);
for (auto entry : jsmap.object_items()) {
functions[entry.first] = entry.second.int_value();
}
};
~InstrumentationFilter() {
ofstream outfile;
outfile.open(fname, ofstream::trunc);
json11::Json jsmap(functions);
outfile << jsmap.dump();
outfile.flush();
outfile.close();
}
void loadFilterData(const char *filename);
void loadFilterDataEnv();
bool loopCheckEnabled();
bool checkFunctionFilter(string function_name, string event_type);
bool checkFunctionArgFilter(string function_name, int arg);
bool checkFileFilter(string file_name);
bool checkFunctionSize(string function_name, size_t size);
fn_size_metrics getFunctionSizeMetric();
};
#endif