-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample-flow.main.cpp
65 lines (59 loc) · 1.76 KB
/
example-flow.main.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
/**
* @file example-flow.main.cpp
* @author ottojo
* @date 12/11/21
* @brief Example for using flow events
*/
#include <thread>
#include <ProfilerLib/Profiler.hpp>
#include <ProfilerLib/ScopeEvent.hpp>
using namespace std;
using namespace chrono_literals;
Profiler p{"Flow Example", "flow.json"};
void t1Func() {
ScopeEvent t1e(p, "t1Func()");
p.setThreadName("t1");
{
ScopeEvent e(p, "part 1");
p.submitFlowStartEvent("t1 -> t2", "exampleCategory", "1");
this_thread::sleep_for(5ms);
p.submitFlowStartEvent("t1 -> t2", "exampleCategory", "2");
this_thread::sleep_for(10ms);
}
this_thread::sleep_for(20ms);
{
ScopeEvent e(p, "part 2");
this_thread::sleep_for(3ms);
p.submitFlowEndEvent("t2 -> t1", "exampleCategory", "1");
this_thread::sleep_for(5ms);
p.submitFlowEndEvent("t2 -> t1", "exampleCategory", "2");
this_thread::sleep_for(10ms);
}
}
void t2Func() {
ScopeEvent t2e(p, "t2Func()");
p.setThreadName("t2");
this_thread::sleep_for(5ms);
{
ScopeEvent e(p, "part 1");
p.submitFlowEndEvent("t1 -> t2", "exampleCategory", "1");
this_thread::sleep_for(7ms);
p.submitFlowEndEvent("t1 -> t2", "exampleCategory", "2");
this_thread::sleep_for(10ms);
}
this_thread::sleep_for(10ms);
{
ScopeEvent e(p, "part 2");
p.submitFlowStartEvent("t2 -> t1", "exampleCategory", "1");
this_thread::sleep_for(5ms);
p.submitFlowStartEvent("t2 -> t1", "exampleCategory", "2");
this_thread::sleep_for(10ms);
}
}
int main() {
p.setProcessName("Flow Example");
p.setThreadName("main thread");
ScopeEvent event(p, "main()");
jthread t1(t1Func);
jthread t2(t2Func);
}