TraceCollector - time s&us using same timespec

This commit is contained in:
bharatnc 2020-09-14 19:12:00 -07:00 committed by alesapin
parent ac59add38c
commit cdeedda1d2
2 changed files with 7 additions and 9 deletions

View File

@ -13,13 +13,6 @@ inline UInt64 clock_gettime_ns(clockid_t clock_type = CLOCK_MONOTONIC)
return UInt64(ts.tv_sec * 1000000000LL + ts.tv_nsec);
}
inline UInt64 clock_gettime_microseconds(clockid_t clock_type = CLOCK_MONOTONIC)
{
struct timespec ts;
clock_gettime(clock_type, &ts);
return UInt64((ts.tv_sec * 1000000LL) + (ts.tv_nsec / 1000));
}
/** Differs from Poco::Stopwatch only by using 'clock_gettime' instead of 'gettimeofday',
* returns nanoseconds instead of microseconds, and also by other minor differencies.
*/

View File

@ -141,8 +141,13 @@ void TraceCollector::run()
if (trace_log)
{
UInt64 time = clock_gettime_ns(CLOCK_REALTIME);
UInt64 time_in_microseconds = clock_gettime_microseconds(CLOCK_REALTIME);
// time and time_in_microseconds are both being constructed from the same timespec so that the
// times will be equal upto the precision of a second.
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
UInt64 time = UInt64(ts.tv_sec * 1000000000LL + ts.tv_nsec);
UInt64 time_in_microseconds = UInt64((ts.tv_sec * 1000000LL) + (ts.tv_nsec / 1000));
TraceLogElement element{time_t(time / 1000000000), time_in_microseconds, time, trace_type, thread_id, query_id, trace, size};
trace_log->add(element);
}