summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-12-10 13:25:16 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:25:48 +0100
commit60a6a240ea21cbfa564b9373b1c3bb57316aae46 (patch)
treee27239c2899b39b9fd7027d88dd0273ec8fcd155 /lib/gitlab
parent141e946c3da97c7af02aaca5324c6e4ce7362a04 (diff)
downloadgitlab-ce-60a6a240ea21cbfa564b9373b1c3bb57316aae46.tar.gz
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.
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/metrics.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb
index 08393995165..007429fa194 100644
--- a/lib/gitlab/metrics.rb
+++ b/lib/gitlab/metrics.rb
@@ -1,5 +1,9 @@
module Gitlab
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
Settings.metrics['pool_size'] || 16
end
@@ -20,16 +24,15 @@ module Gitlab
@hostname
end
+ # Returns a relative path and line number based on the last application call
+ # 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|
- l.path.start_with?(root) && !l.path.start_with?(metrics)
+ l.path.start_with?(RAILS_ROOT) && !l.path.start_with?(METRICS_ROOT)
end
if frame
- return frame.path.gsub(/^#{Rails.root.to_s}\/?/, ''), frame.lineno
+ return frame.path.sub(PATH_REGEX, ''), frame.lineno
else
return nil, nil
end