mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-03 20:40:17 -05:00
Allow benchmarking of CpuBoundWork#CpuBoundWork() via additional out-param
This commit is contained in:
parent
a65f2d6b41
commit
76503f6b45
2 changed files with 32 additions and 0 deletions
|
|
@ -34,6 +34,31 @@ CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures how long it takes to acquire a slot.
|
||||
*
|
||||
* @param yc Forwarded to the regular constructor.
|
||||
* @param took Set to the time it took to acquire the slot.
|
||||
*/
|
||||
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, Clock::duration& took)
|
||||
: CpuBoundWork(std::move(yc), Clock::now(), took)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* An internal helper layer between the regular constructor and the one that measures how long it takes.
|
||||
* This is necessary to get the start time before the regular constructor is called.
|
||||
*
|
||||
* @param yc Forwarded to the regular constructor.
|
||||
* @param started The current time.
|
||||
* @param took Set to the time it took to acquire the slot.
|
||||
*/
|
||||
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, Clock::time_point started, Clock::duration& took)
|
||||
: CpuBoundWork(std::move(yc))
|
||||
{
|
||||
took = Clock::now() - started;
|
||||
}
|
||||
|
||||
CpuBoundWork::~CpuBoundWork()
|
||||
{
|
||||
if (!m_Done) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "base/logger.hpp"
|
||||
#include "base/shared.hpp"
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
|
@ -36,8 +37,14 @@ namespace icinga
|
|||
*/
|
||||
class CpuBoundWork
|
||||
{
|
||||
private:
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
||||
CpuBoundWork(boost::asio::yield_context yc, Clock::time_point started, Clock::duration& took);
|
||||
|
||||
public:
|
||||
CpuBoundWork(boost::asio::yield_context yc);
|
||||
CpuBoundWork(boost::asio::yield_context yc, Clock::duration& took);
|
||||
CpuBoundWork(const CpuBoundWork&) = delete;
|
||||
CpuBoundWork(CpuBoundWork&&) = delete;
|
||||
CpuBoundWork& operator=(const CpuBoundWork&) = delete;
|
||||
|
|
|
|||
Loading…
Reference in a new issue