Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 4f7ee11

Browse files
committed
Fix timestamp math for platforms with _POSIX_MONOTONIC_CLOCK
Hello, hello! 🎉 First the disclaimer (I guess it may be relevant): I work at @DataDog on profiling for the [ddtrace](https://github.com/DataDog/dd-trace-rb) gem, although we don't use `rb_profile_frames` (but it is quite interesting). I noticed that the fix for tmm1#122 in tmm1#163 actually missed the new `_POSIX_MONOTONIC_CLOCK` branch, where the math was still incorrect (used 1000 instead of 1000000 when attempting to convert seconds to microseconds). cc @djudd @casperisfine
1 parent 6524e61 commit 4f7ee11

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/stackprof/stackprof.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ static const char *fake_frame_cstrs[] = {
4949
}
5050

5151
static int64_t delta_usec(timestamp_t *start, timestamp_t *end) {
52-
int64_t result = 1000 * (end->tv_sec - start->tv_sec);
52+
int64_t result = MICROSECONDS_IN_SECOND * (end->tv_sec - start->tv_sec);
5353
if (end->tv_nsec < start->tv_nsec) {
54-
result -= 1000;
54+
result -= MICROSECONDS_IN_SECOND;
5555
result += (NANOSECONDS_IN_SECOND + end->tv_nsec - start->tv_nsec) / 1000;
5656
} else {
5757
result += (end->tv_nsec - start->tv_nsec) / 1000;

0 commit comments

Comments
 (0)