From ec7ac63a73cc53f0ca9e1783ae52c9c71eb77c3c Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Fri, 20 Sep 2024 15:03:20 +0000 Subject: [PATCH] use time_ns --- .../profiling/dd_wrapper/src/sample.cpp | 26 +++++++++---------- ddtrace/profiling/collector/stack.pyx | 4 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp b/ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp index 7bb6fadb94..6a5c5d9aa5 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 + offset; + endtime_ns = _monotonic_ns; } return true; diff --git a/ddtrace/profiling/collector/stack.pyx b/ddtrace/profiling/collector/stack.pyx index b936c70985..b2e40dd120 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 = 0): +cdef stack_collect(ignore_profiler, thread_time, max_nframes, interval, wall_time, thread_span_links, collect_endpoint, now_ns): # 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=now, + now_ns=compat.now_ns() ) used_wall_time_ns = compat.monotonic_ns() - now