-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring_main.cpp
69 lines (49 loc) · 1.49 KB
/
monitoring_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
66
67
68
69
#include "include/monitoring/api.hpp"
#include "monitoring/api.hpp"
#include "monitoring/macros.hpp"
#include <chrono>
#include <iostream>
#include <thread>
// using namespace monitor;
using namespace std::chrono_literals;
void handler(monitor::checkpoint &check) {
(void)check;
std::cout << "HANDLER CALLED" << std::endl;
}
void work1() {
monitor::start_this_thread_monitoring();
monitor::set_this_thread_handler(handler);
// NOTE: deadlines are monotonic (reasonable assumption?)
monitor::expect_progress_in(2000ms, 42, THIS_SOURCE_LOCATION);
monitor::expect_progress_in(1000ms, 73, THIS_SOURCE_LOCATION);
monitor::expect_progress_in(100ms, 21, THIS_SOURCE_LOCATION);
std::this_thread::sleep_for(3s);
std::this_thread::sleep_for(1ms);
monitor::confirm_progress(THIS_SOURCE_LOCATION);
monitor::confirm_progress(THIS_SOURCE_LOCATION);
monitor::confirm_progress(THIS_SOURCE_LOCATION);
monitor::stop_this_thread_monitoring();
}
void work2() {
START_THIS_THREAD_MONITORING;
SET_MONITORING_HANDLER(handler);
UNSET_MONITORING_HANDLER;
EXPECT_PROGRESS_IN(500ms, 66);
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(1ms);
CONFIRM_PROGRESS;
STOP_THIS_THREAD_MONITORING;
}
int main(void) {
START_ACTIVE_MONITORING(50ms);
std::this_thread::sleep_for(100ms);
std::thread t1(&work1);
std::thread t2(&work2);
// std::thread t3(&work2);
t1.join();
t2.join();
// t3.join();
STOP_ACTIVE_MONITORING;
monitor::print_stats();
return EXIT_SUCCESS;
}