Skip to content

Commit 348cf5f

Browse files
committed
Fix timestamp math: 1 million microseconds in second
1 parent 21fc809 commit 348cf5f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/stackprof/stackprof.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <pthread.h>
1717

1818
#define BUF_SIZE 2048
19+
#define MICROSECONDS_IN_SECOND 1000000
1920

2021
typedef struct {
2122
size_t total_samples;
@@ -497,7 +498,7 @@ stackprof_record_sample()
497498
struct timeval diff;
498499
gettimeofday(&t, NULL);
499500
timersub(&t, &_stackprof.last_sample_at, &diff);
500-
timestamp_delta = (1000 * diff.tv_sec) + diff.tv_usec;
501+
timestamp_delta = (MICROSECONDS_IN_SECOND * diff.tv_sec) + diff.tv_usec;
501502
}
502503
num = rb_profile_frames(0, sizeof(_stackprof.frames_buffer) / sizeof(VALUE), _stackprof.frames_buffer, _stackprof.lines_buffer);
503504
stackprof_record_sample_for_stack(num, timestamp_delta);
@@ -516,7 +517,7 @@ stackprof_record_gc_samples()
516517

517518
// We don't know when the GC samples were actually marked, so let's
518519
// assume that they were marked at a perfectly regular interval.
519-
delta_to_first_unrecorded_gc_sample = (1000 * diff.tv_sec + diff.tv_usec) - (_stackprof.unrecorded_gc_samples - 1) * NUM2LONG(_stackprof.interval);
520+
delta_to_first_unrecorded_gc_sample = (MICROSECONDS_IN_SECOND * diff.tv_sec + diff.tv_usec) - (_stackprof.unrecorded_gc_samples - 1) * NUM2LONG(_stackprof.interval);
520521
if (delta_to_first_unrecorded_gc_sample < 0) {
521522
delta_to_first_unrecorded_gc_sample = 0;
522523
}

0 commit comments

Comments
 (0)