forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
observer.cpp
43 lines (32 loc) · 935 Bytes
/
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, B, C, D, E, F, G, H] = taskflow.emplace(
[] () { std::cout << "1\n"; },
[] () { std::cout << "2\n"; },
[] () { std::cout << "3\n"; },
[] () { std::cout << "4\n"; },
[] () { std::cout << "5\n"; },
[] () { std::cout << "6\n"; },
[] () { std::cout << "7\n"; },
[] () { 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);
return 0;
}