Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow benchmarking of CpuBoundWork#CpuBoundWork() via additional out-param #10167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/base/io-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions lib/base/io-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/logger.hpp"
#include "base/shared-object.hpp"
#include <atomic>
#include <chrono>
#include <exception>
#include <memory>
#include <thread>
Expand All @@ -29,8 +30,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;
Expand Down
Loading