File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,31 @@ CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
34
34
}
35
35
}
36
36
37
+ /* *
38
+ * Measures how long it takes to acquire a slot.
39
+ *
40
+ * @param yc Forwarded to the regular constructor.
41
+ * @param took Set to the time it took to acquire the slot.
42
+ */
43
+ CpuBoundWork::CpuBoundWork (boost::asio::yield_context yc, Clock::duration& took)
44
+ : CpuBoundWork(std::move(yc), Clock::now(), took)
45
+ {
46
+ }
47
+
48
+ /* *
49
+ * An internal helper layer between the regular constructor and the one that measures how long it takes.
50
+ * This is necessary to get the start time before the regular constructor is called.
51
+ *
52
+ * @param yc Forwarded to the regular constructor.
53
+ * @param started The current time.
54
+ * @param took Set to the time it took to acquire the slot.
55
+ */
56
+ CpuBoundWork::CpuBoundWork (boost::asio::yield_context yc, Clock::time_point started, Clock::duration& took)
57
+ : CpuBoundWork(std::move(yc))
58
+ {
59
+ took = Clock::now () - started;
60
+ }
61
+
37
62
CpuBoundWork::~CpuBoundWork ()
38
63
{
39
64
if (!m_Done) {
Original file line number Diff line number Diff line change 10
10
#include " base/logger.hpp"
11
11
#include " base/shared.hpp"
12
12
#include < atomic>
13
+ #include < chrono>
13
14
#include < exception>
14
15
#include < memory>
15
16
#include < thread>
@@ -36,8 +37,14 @@ namespace icinga
36
37
*/
37
38
class CpuBoundWork
38
39
{
40
+ private:
41
+ using Clock = std::chrono::steady_clock;
42
+
43
+ CpuBoundWork (boost::asio::yield_context yc, Clock::time_point started, Clock::duration& took);
44
+
39
45
public:
40
46
CpuBoundWork (boost::asio::yield_context yc);
47
+ CpuBoundWork (boost::asio::yield_context yc, Clock::duration& took);
41
48
CpuBoundWork (const CpuBoundWork&) = delete ;
42
49
CpuBoundWork (CpuBoundWork&&) = delete ;
43
50
CpuBoundWork& operator =(const CpuBoundWork&) = delete ;
You can’t perform that action at this time.
0 commit comments