mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 02:41:59 +00:00
46 lines
967 B
C++
46 lines
967 B
C++
#pragma once
|
|
|
|
#include <Common/ProfileEvents.h>
|
|
#include <Common/Stopwatch.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
enum Time
|
|
{
|
|
Nanoseconds,
|
|
Microseconds,
|
|
Milliseconds,
|
|
Seconds,
|
|
};
|
|
|
|
template <Time time>
|
|
struct ProfileEventTimeIncrement
|
|
{
|
|
explicit ProfileEventTimeIncrement<time>(ProfileEvents::Event event_)
|
|
: event(event_), watch(CLOCK_MONOTONIC) {}
|
|
|
|
UInt64 elapsed()
|
|
{
|
|
if constexpr (time == Time::Nanoseconds)
|
|
return watch.elapsedNanoseconds();
|
|
else if constexpr (time == Time::Microseconds)
|
|
return watch.elapsedMicroseconds();
|
|
else if constexpr (time == Time::Milliseconds)
|
|
return watch.elapsedMilliseconds();
|
|
else if constexpr (time == Time::Seconds)
|
|
return watch.elapsedSeconds();
|
|
}
|
|
|
|
~ProfileEventTimeIncrement()
|
|
{
|
|
watch.stop();
|
|
ProfileEvents::increment(event, elapsed());
|
|
}
|
|
|
|
ProfileEvents::Event event;
|
|
Stopwatch watch;
|
|
};
|
|
|
|
}
|