Skip to content

Commit 350ce94

Browse files
committed
Allow benchmarking of CpuBoundWork#CpuBoundWork() via additional out-param
1 parent e678f09 commit 350ce94

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/base/io-engine.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
3434
}
3535
}
3636

37+
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, Clock::duration& took)
38+
: CpuBoundWork(std::move(yc), Clock::now(), took)
39+
{
40+
}
41+
42+
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, Clock::time_point started, Clock::duration& took)
43+
: CpuBoundWork(std::move(yc))
44+
{
45+
took = Clock::now() - started;
46+
}
47+
3748
CpuBoundWork::~CpuBoundWork()
3849
{
3950
if (!m_Done) {

lib/base/io-engine.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "base/logger.hpp"
99
#include "base/shared-object.hpp"
1010
#include <atomic>
11+
#include <chrono>
1112
#include <exception>
1213
#include <memory>
1314
#include <thread>
@@ -29,8 +30,14 @@ namespace icinga
2930
*/
3031
class CpuBoundWork
3132
{
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+
3238
public:
3339
CpuBoundWork(boost::asio::yield_context yc);
40+
CpuBoundWork(boost::asio::yield_context yc, Clock::duration& took);
3441
CpuBoundWork(const CpuBoundWork&) = delete;
3542
CpuBoundWork(CpuBoundWork&&) = delete;
3643
CpuBoundWork& operator=(const CpuBoundWork&) = delete;

0 commit comments

Comments
 (0)