diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/method_call.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/metrics/system.rb | 8 |
2 files changed, 14 insertions, 18 deletions
diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index bb39b1d5462..f4a916f154d 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -4,7 +4,7 @@ module Gitlab class MethodCall MUTEX = Mutex.new BASE_LABELS = { module: nil, method: nil }.freeze - attr_reader :real_time_seconds, :cpu_time, :call_count, :labels + attr_reader :real_time, :cpu_time, :call_count, :labels def self.call_duration_histogram return @call_duration_histogram if @call_duration_histogram @@ -27,42 +27,38 @@ module Gitlab @transaction = transaction @name = name @labels = { module: @module_name, method: @method_name } - @real_time_seconds = 0.0 - @cpu_time = 0 + @real_time = 0.0 + @cpu_time = 0.0 @call_count = 0 end # Measures the real and CPU execution time of the supplied block. def measure - start_real_seconds = System.monotonic_time + start_real = System.monotonic_time start_cpu = System.cpu_time retval = yield - real_time_seconds = System.monotonic_time - start_real_seconds + real_time = System.monotonic_time - start_real cpu_time = System.cpu_time - start_cpu - @real_time_seconds += real_time_seconds + @real_time += real_time @cpu_time += cpu_time @call_count += 1 if call_measurement_enabled? && above_threshold? - self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time_seconds) + self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time) end retval end - def real_time_milliseconds - real_time_seconds.in_milliseconds.to_i - end - # Returns a Metric instance of the current method call. def to_metric Metric.new( Instrumentation.series, { - duration: real_time_milliseconds, - cpu_duration: cpu_time, + duration: real_time.in_milliseconds.to_i, + cpu_duration: cpu_time.in_milliseconds.to_i, call_count: call_count }, method: @name @@ -72,7 +68,7 @@ module Gitlab # Returns true if the total runtime of this method exceeds the method call # threshold. def above_threshold? - real_time_milliseconds >= Metrics.method_call_threshold + real_time.in_milliseconds >= Metrics.method_call_threshold end def call_measurement_enabled? diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index 4852017bf38..e60e245cf89 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -35,19 +35,19 @@ module Gitlab if Process.const_defined?(:CLOCK_THREAD_CPUTIME_ID) def self.cpu_time Process - .clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :millisecond) + .clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :float_second) end else def self.cpu_time Process - .clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :millisecond) + .clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :float_second) end end # Returns the current real time in a given precision. # - # Returns the time as a Fixnum. - def self.real_time(precision = :millisecond) + # Returns the time as a Float for precision = :float_second. + def self.real_time(precision = :float_second) Process.clock_gettime(Process::CLOCK_REALTIME, precision) end |