forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobserver.cpp
43 lines (31 loc) · 1.09 KB
/
observer.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
// Demonstrates the use of observer to monitor worker activities
#include <taskflow/taskflow.hpp>
int main(){
tf::Executor executor;
// Create a taskflow of eight tasks
tf::Taskflow taskflow;
auto A = taskflow.emplace([] () { std::cout << "1\n"; });
auto B = taskflow.emplace([] () { std::cout << "2\n"; });
auto C = taskflow.emplace([] () { std::cout << "3\n"; });
auto D = taskflow.emplace([] () { std::cout << "4\n"; });
auto E = taskflow.emplace([] () { std::cout << "5\n"; });
auto F = taskflow.emplace([] () { std::cout << "6\n"; });
auto G = taskflow.emplace([] () { std::cout << "7\n"; });
auto H = taskflow.emplace([] () { std::cout << "8\n"; });
A.name("A");
B.name("B");
C.name("C");
D.name("D");
E.name("E");
F.name("F");
G.name("G");
H.name("H");
// create a default observer
auto observer = executor.make_observer<tf::ExecutorObserver>();
// run the taskflow
executor.run(taskflow).get();
// dump the execution timeline to json (view at chrome://tracing)
observer->dump(std::cout);
executor.remove_observer(observer);
return 0;
}