Commit 60a6a240 authored by Yorick Peterse's avatar Yorick Peterse

Improved last_relative_application_frame timings

The previous setup wasn't exactly fast, resulting in instrumented method
calls taking about 600 times longer than non instrumented calls
(including any ActiveSupport code involved). With this commit this
slowdown has been reduced to around 185 times.
parent 141e946c
module Gitlab module Gitlab
module Metrics module Metrics
RAILS_ROOT = Rails.root.to_s
METRICS_ROOT = Rails.root.join('lib', 'gitlab', 'metrics').to_s
PATH_REGEX = /^#{RAILS_ROOT}\/?/
def self.pool_size def self.pool_size
Settings.metrics['pool_size'] || 16 Settings.metrics['pool_size'] || 16
end end
...@@ -20,16 +24,15 @@ module Gitlab ...@@ -20,16 +24,15 @@ module Gitlab
@hostname @hostname
end end
# Returns a relative path and line number based on the last application call
# frame.
def self.last_relative_application_frame def self.last_relative_application_frame
root = Rails.root.to_s
metrics = Rails.root.join('lib', 'gitlab', 'metrics').to_s
frame = caller_locations.find do |l| frame = caller_locations.find do |l|
l.path.start_with?(root) && !l.path.start_with?(metrics) l.path.start_with?(RAILS_ROOT) && !l.path.start_with?(METRICS_ROOT)
end end
if frame if frame
return frame.path.gsub(/^#{Rails.root.to_s}\/?/, ''), frame.lineno return frame.path.sub(PATH_REGEX, ''), frame.lineno
else else
return nil, nil return nil, nil
end end
......
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