Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created November 19, 2012 07:12
Show Gist options
  • Save tmm1/4109376 to your computer and use it in GitHub Desktop.
Save tmm1/4109376 to your computer and use it in GitHub Desktop.
Improve GC::Profiler.total_time accuracy
diff --git a/gc.c b/gc.c
index e65d0ec..0f14a2f 100644
--- a/gc.c
+++ b/gc.c
@@ -127,7 +127,13 @@ typedef struct gc_profile_record {
static double
getrusage_time(void)
{
-#ifdef RUSAGE_SELF
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
+ struct timespec ts;
+
+ if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == 0) {
+ return ts.tv_sec + ts.tv_nsec * 1e-9;
+ }
+#elif defined RUSAGE_SELF
struct rusage usage;
struct timeval time;
getrusage(RUSAGE_SELF, &usage);
@tmm1
Copy link
Author

tmm1 commented Dec 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment