Created
November 19, 2012 07:12
-
-
Save tmm1/4109376 to your computer and use it in GitHub Desktop.
Improve GC::Profiler.total_time accuracy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bugs.ruby-lang.org/issues/7500