Commit 120fbbd4 authored by Paco Guzman's avatar Paco Guzman

Measure CPU time for instrumented methods

parent 0c0ef7df
...@@ -77,6 +77,7 @@ v 8.9.0 (unreleased) ...@@ -77,6 +77,7 @@ v 8.9.0 (unreleased)
- All classes in the Banzai::ReferenceParser namespace are now instrumented - All classes in the Banzai::ReferenceParser namespace are now instrumented
- Remove deprecated issues_tracker and issues_tracker_id from project model - Remove deprecated issues_tracker and issues_tracker_id from project model
- Allow users to create confidential issues in private projects - Allow users to create confidential issues in private projects
- Measure CPU time for instrumented methods
v 8.8.5 (unreleased) v 8.8.5 (unreleased)
- Ensure branch cleanup regardless of whether the GitHub import process succeeds - Ensure branch cleanup regardless of whether the GitHub import process succeeds
......
...@@ -97,15 +97,16 @@ def #{name}(#{args_signature}) ...@@ -97,15 +97,16 @@ def #{name}(#{args_signature})
trans = Gitlab::Metrics::Instrumentation.transaction trans = Gitlab::Metrics::Instrumentation.transaction
if trans if trans
start = Time.now start = Time.now
retval = super cpu_start = Gitlab::Metrics::System.cpu_time
duration = (Time.now - start) * 1000.0 retval = super
duration = (Time.now - start) * 1000.0
if duration >= Gitlab::Metrics.method_call_threshold if duration >= Gitlab::Metrics.method_call_threshold
trans.increment(:method_duration, duration) cpu_duration = Gitlab::Metrics::System.cpu_time - cpu_start
trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES, trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
{ duration: duration }, { duration: duration, cpu_duration: cpu_duration },
method: #{label.inspect}) method: #{label.inspect})
end end
......
...@@ -149,13 +149,16 @@ module Gitlab ...@@ -149,13 +149,16 @@ module Gitlab
trans = Gitlab::Metrics::Instrumentation.transaction trans = Gitlab::Metrics::Instrumentation.transaction
if trans if trans
start = Time.now start = Time.now
retval = super cpu_start = Gitlab::Metrics::System.cpu_time
duration = (Time.now - start) * 1000.0 retval = super
duration = (Time.now - start) * 1000.0
if duration >= Gitlab::Metrics.method_call_threshold if duration >= Gitlab::Metrics.method_call_threshold
cpu_duration = Gitlab::Metrics::System.cpu_time - cpu_start
trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES, trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
{ duration: duration }, { duration: duration, cpu_duration: cpu_duration },
method: #{label.inspect}) method: #{label.inspect})
end end
......
...@@ -57,7 +57,7 @@ describe Gitlab::Metrics::Instrumentation do ...@@ -57,7 +57,7 @@ describe Gitlab::Metrics::Instrumentation do
and_return(transaction) and_return(transaction)
expect(transaction).to receive(:add_metric). expect(transaction).to receive(:add_metric).
with(described_class::SERIES, an_instance_of(Hash), with(described_class::SERIES, hash_including(:duration, :cpu_duration),
method: 'Dummy.foo') method: 'Dummy.foo')
@dummy.foo @dummy.foo
...@@ -137,7 +137,7 @@ describe Gitlab::Metrics::Instrumentation do ...@@ -137,7 +137,7 @@ describe Gitlab::Metrics::Instrumentation do
and_return(transaction) and_return(transaction)
expect(transaction).to receive(:add_metric). expect(transaction).to receive(:add_metric).
with(described_class::SERIES, an_instance_of(Hash), with(described_class::SERIES, hash_including(:duration, :cpu_duration),
method: 'Dummy#bar') method: 'Dummy#bar')
@dummy.new.bar @dummy.new.bar
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment