Skip to content

Commit

Permalink
use if branch for timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Sep 21, 2024
1 parent b9ab9bb commit 0df2e20
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions include/quill/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,23 @@ class LoggerImpl : public detail::LoggerBase
// Store the timestamp of the log statement at the start of the call. This gives more accurate
// timestamp especially if the queue is full
// This is very rare but might lead to out of order timestamp in the log file if we block on push for too long
uint64_t const current_timestamp = (clock_source == ClockSourceType::Tsc) ? detail::rdtsc()
: (clock_source == ClockSourceType::System)
? static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count())
: user_clock->now();

uint64_t current_timestamp;

if (clock_source == ClockSourceType::Tsc)
{
current_timestamp = detail::rdtsc();
}
else if (clock_source == ClockSourceType::System)
{
current_timestamp = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
else
{
current_timestamp = user_clock->now();
}

if (QUILL_UNLIKELY(thread_context == nullptr))
{
Expand Down

0 comments on commit 0df2e20

Please sign in to comment.