diff --git a/ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp b/ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp index 6a5c5d9aa5..7bb6fadb94 100644 --- a/ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp +++ b/ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp @@ -313,24 +313,24 @@ Datadog::Sample::push_monotonic_ns(int64_t _monotonic_ns) // Monotonic times have their epoch at the system start, so they need an // adjustment to the standard epoch // Just set a static for now and use a lambda to compute the offset once - // const static auto offset = []() { - // // Get the current epoch time - // using namespace std::chrono; - // auto epoch_ns = duration_cast(system_clock::now().time_since_epoch()).count(); + const static auto offset = []() { + // Get the current epoch time + using namespace std::chrono; + auto epoch_ns = duration_cast(system_clock::now().time_since_epoch()).count(); - // // Get the current monotonic time. Use clock_gettime directly because the standard underspecifies - // // which clock is actually used in std::chrono - // timespec ts; - // clock_gettime(CLOCK_MONOTONIC, &ts); - // auto monotonic_ns = static_cast(ts.tv_sec) * 1'000'000'000LL + ts.tv_nsec; + // Get the current monotonic time. Use clock_gettime directly because the standard underspecifies + // which clock is actually used in std::chrono + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + auto monotonic_ns = static_cast(ts.tv_sec) * 1'000'000'000LL + ts.tv_nsec; - // // Compute the difference. We're after 1970, so epoch_ns will be larger - // return epoch_ns - monotonic_ns; - // }(); + // Compute the difference. We're after 1970, so epoch_ns will be larger + return epoch_ns - monotonic_ns; + }(); // If timeline is not enabled, then this is a no-op if (is_timeline_enabled()) { - endtime_ns = _monotonic_ns; + endtime_ns = _monotonic_ns + offset; } return true; diff --git a/ddtrace/profiling/collector/stack.pyx b/ddtrace/profiling/collector/stack.pyx index 906d255e56..72a066f96a 100644 --- a/ddtrace/profiling/collector/stack.pyx +++ b/ddtrace/profiling/collector/stack.pyx @@ -291,7 +291,7 @@ cdef collect_threads(thread_id_ignore_list, thread_time, thread_span_links) with ) -cdef stack_collect(ignore_profiler, thread_time, max_nframes, interval, wall_time, thread_span_links, collect_endpoint, now_ns): +cdef stack_collect(ignore_profiler, thread_time, max_nframes, interval, wall_time, thread_span_links, collect_endpoint, now_ns=0): # Do not use `threading.enumerate` to not mess with locking (gevent!) # Also collect the native threads, that are not registered with the built-in # threading module, to keep backward compatibility with the previous @@ -578,7 +578,7 @@ class StackCollector(collector.PeriodicCollector): wall_time, self._thread_span_links, self.endpoint_collection_enabled, - now_ns=compat.time_ns() + now_ns=now ) used_wall_time_ns = compat.monotonic_ns() - now