summary refs log tree commit
path: root/lib/rack/runtime.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rack/runtime.rb')
-rw-r--r--lib/rack/runtime.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/rack/runtime.rb b/lib/rack/runtime.rb
index 83d6c0ca..e86add31 100644
--- a/lib/rack/runtime.rb
+++ b/lib/rack/runtime.rb
@@ -14,9 +14,9 @@ module Rack
 
     FORMAT_STRING = "%0.6f"
     def call(env)
-      start_time = Time.now
+      start_time = clock_time
       status, headers, body = @app.call(env)
-      request_time = Time.now - start_time
+      request_time = clock_time - start_time
 
       if !headers.has_key?(@header_name)
         headers[@header_name] = FORMAT_STRING % request_time
@@ -24,5 +24,17 @@ module Rack
 
       [status, headers, body]
     end
+
+    private
+
+    if defined?(Process::CLOCK_MONOTONIC)
+      def clock_time
+        Process.clock_gettime(Process::CLOCK_MONOTONIC)
+      end
+    else
+      def clock_time
+        Time.now.to_f
+      end
+    end
   end
 end