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 8
8
#include " base/logger.hpp"
9
9
#include " base/shared-object.hpp"
10
10
#include < atomic>
11
+ #include < chrono>
11
12
#include < exception>
12
13
#include < memory>
13
14
#include < thread>
@@ -29,8 +30,14 @@ namespace icinga
29
30
*/
30
31
class CpuBoundWork
31
32
{
33
+ private:
34
+ using Clock = std::chrono::steady_clock;
35
+
36
+ CpuBoundWork (boost::asio::yield_context yc, Clock::time_point started, Clock::duration& took);
37
+
32
38
public:
33
39
CpuBoundWork (boost::asio::yield_context yc);
40
+ CpuBoundWork (boost::asio::yield_context yc, Clock::duration& took);
34
41
CpuBoundWork (const CpuBoundWork&) = delete ;
35
42
CpuBoundWork (CpuBoundWork&&) = delete ;
36
43
CpuBoundWork& operator =(const CpuBoundWork&) = delete ;
You can’t perform that action at this time.
0 commit comments