14 #include "quill/backend/RdtscClock.h" 15 #include "quill/core/Attributes.h" 16 #include "quill/core/ChronoTimeUtils.h" 17 #include "quill/core/Codec.h" 18 #include "quill/core/Common.h" 19 #include "quill/core/DynamicFormatArgStore.h" 20 #include "quill/core/Rdtsc.h" 22 #include "quill/bundled/fmt/format.h" 23 #include "quill/std/Chrono.h" 49 template <ClockSourceType ClockType>
53 static_assert((ClockType == ClockSourceType::Tsc) || (ClockType == ClockSourceType::System),
61 if constexpr (ClockType == ClockSourceType::Tsc)
63 _ns_per_tick = RdtscClock::RdtscTicks::instance().ns_per_tick();
76 [[nodiscard]] std::chrono::duration<double>
elapsed()
const 78 return elapsed_as<std::chrono::duration<double>>();
88 if constexpr (ClockType == ClockSourceType::Tsc)
90 return std::chrono::duration_cast<T>(std::chrono::nanoseconds{
91 static_cast<uint64_t
>(
static_cast<double>(
rdtsc() - _start_tp) * _ns_per_tick)});
104 if constexpr (ClockType == ClockSourceType::Tsc)
115 double _ns_per_tick{0};
116 uint64_t _start_tp{0};
143 template <quill::ClockSourceType ClockType>
146 static size_t compute_encoded_size(quill::detail::SizeCacheVector&,
147 quill::detail::StopWatch<ClockType>
const&) noexcept
149 return sizeof(double);
152 static void encode(std::byte*& buffer, quill::detail::SizeCacheVector
const&, uint32_t&,
153 quill::detail::StopWatch<ClockType>
const& sw) noexcept
156 double const elapsed_seconds = sw.elapsed().count();
157 std::memcpy(buffer, &elapsed_seconds,
sizeof(elapsed_seconds));
158 buffer +=
sizeof(elapsed_seconds);
161 static double decode_arg(std::byte*& buffer)
163 double elapsed_seconds;
164 std::memcpy(&elapsed_seconds, buffer,
sizeof(elapsed_seconds));
165 buffer +=
sizeof(elapsed_seconds);
166 return elapsed_seconds;
169 static void decode_and_store_arg(std::byte*& buffer, quill::DynamicFormatArgStore* args_store)
171 args_store->push_back(decode_arg(buffer));
StopWatch()
Constructor.
Definition: StopWatch.h:59
Definition: MegaEventCodecFuzzer.cpp:101
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:28
std::chrono::duration< double > elapsed() const
Returns the elapsed time since construction.
Definition: StopWatch.h:76
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT uint64_t rdtsc() noexcept
Get the TSC counter.
Definition: Rdtsc.h:105
T elapsed_as() const
Returns the elapsed time since construction as the specified duration type.
Definition: StopWatch.h:86
void reset()
Resets the stopwatch, starting the measurement from the current time.
Definition: StopWatch.h:102
QUILL_ATTRIBUTE_HOT void encode(std::byte *&buffer, SizeCacheVector const &conditional_arg_size_cache, Args &&... args)
Encodes multiple arguments into a buffer.
Definition: Codec.h:397
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT uint64_t get_steady_time_ns() noexcept
Mirrors std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::steady_clock::now().time_since_epoch()).count().
Definition: ChronoTimeUtils.h:90
A stopwatch utility for measuring elapsed time since construction.
Definition: StopWatch.h:50