Skip to content

Commit

Permalink
use time_ns
Browse files Browse the repository at this point in the history
  • Loading branch information
taegyunkim committed Sep 20, 2024
1 parent a95e522 commit ec7ac63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nanoseconds>(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<nanoseconds>(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<int64_t>(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<int64_t>(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;
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/profiling/collector/stack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ec7ac63

Please sign in to comment.