-
Notifications
You must be signed in to change notification settings - Fork 63
/
minitrace_test.cpp
70 lines (58 loc) · 1.33 KB
/
minitrace_test.cpp
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
#include "minitrace.h"
#ifdef _WIN32
#include <windows.h>
#define usleep(x) Sleep(x/1000)
#else
#include <unistd.h>
#endif
void c() {
MTR_SCOPE("c++", "c()");
usleep(10000);
}
void b() {
MTR_SCOPE("c++", "b()");
usleep(20000);
c();
usleep(10000);
}
void a() {
MTR_SCOPE("c++", "a()");
usleep(20000);
b();
usleep(10000);
}
int main() {
int i;
mtr_init("trace.json");
mtr_register_sigint_handler();
MTR_META_PROCESS_NAME("minitrace_test");
MTR_META_THREAD_NAME("main thread");
int long_running_thing_1;
int long_running_thing_2;
MTR_START("background", "long_running", &long_running_thing_1);
MTR_START("background", "long_running", &long_running_thing_2);
MTR_COUNTER("main", "greebles", 3);
MTR_BEGIN("main", "outer");
usleep(80000);
for (i = 0; i < 3; i++) {
MTR_BEGIN("main", "inner");
usleep(40000);
MTR_END("main", "inner");
usleep(10000);
MTR_COUNTER("main", "greebles", 3 * i + 10);
}
MTR_STEP("background", "long_running", &long_running_thing_1, "middle step");
usleep(80000);
MTR_END("main", "outer");
MTR_COUNTER("main", "greebles", 0);
usleep(10000);
a();
usleep(50000);
MTR_INSTANT("main", "the end");
usleep(10000);
MTR_FINISH("background", "long_running", &long_running_thing_1);
MTR_FINISH("background", "long_running", &long_running_thing_2);
mtr_flush();
mtr_shutdown();
return 0;
}