-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_002.cpp
More file actions
59 lines (49 loc) · 1.19 KB
/
test_002.cpp
File metadata and controls
59 lines (49 loc) · 1.19 KB
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
#include "bttrack.h"
class JobFoo {
public:
void PrepareJob() {
bool ok = bttrack::GetBacktrace(prev_stack_);
prev_score_ = ok ? (-2 * id) : 0;
}
void RunJob() {
auto score = rand() % 0xfffff; // 0-1M
if (score > 0x7ffff) {
bttrack::Record(0, score);
bttrack::Record(1, prev_stack_, prev_score_); // 50%
} else {
bttrack::Record(0, score);
}
}
int id = 0;
private:
bttrack::FramePointers prev_stack_;
int64_t prev_score_ = 0;
};
void Run() {
JobFoo job[8];
for (int i = 0; i < 8; i++) {
job[i].id = i + 1;
}
const int kNumRuns = 1000;
for (int i = 0; i < kNumRuns; i++) {
size_t idx = rand() % 8;
job[idx].PrepareJob();
job[idx].RunJob();
}
// output
std::vector<bttrack::StackFrames> records;
std::string json;
const int json_indent = 2;
bttrack::Dump(0, records);
json = bttrack::StackFramesToJson(records, json_indent);
printf("Channel 0 JSON:\n%s\n\n", json.c_str());
bttrack::Dump(1, records);
json = bttrack::StackFramesToJson(records, json_indent);
// count(n) is about 50% of kNumRuns
printf("Channel 1 JSON:\n%s\n\n", json.c_str());
}
int main() {
srand(time(NULL));
Run();
return 0;
}