Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-04-08 23:52:21 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2016-04-08 23:52:21 +0300
commit833808d737058ff25b34f6bd5eb4d4989c43e49d (patch)
tree2a3b686617e973650b92666698c213183d2dc60e /lib
parent5ef170ae820388bbbe29b36c3c7091a5bda6733c (diff)
parentc56f702ec3806606459e4edc3de097f1bb6baf4e (diff)
Merge branch 'instrument-rails-cache' into 'master'
Instrument Rails cache code See merge request !3619
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/subscribers/rails_cache.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/metrics/subscribers/rails_cache.rb b/lib/gitlab/metrics/subscribers/rails_cache.rb
new file mode 100644
index 00000000000..49e5f86e6e6
--- /dev/null
+++ b/lib/gitlab/metrics/subscribers/rails_cache.rb
@@ -0,0 +1,39 @@
+module Gitlab
+ module Metrics
+ module Subscribers
+ # Class for tracking the total time spent in Rails cache calls
+ class RailsCache < ActiveSupport::Subscriber
+ attach_to :active_support
+
+ def cache_read(event)
+ increment(:cache_read_duration, event.duration)
+ end
+
+ def cache_write(event)
+ increment(:cache_write_duration, event.duration)
+ end
+
+ def cache_delete(event)
+ increment(:cache_delete_duration, event.duration)
+ end
+
+ def cache_exist?(event)
+ increment(:cache_exists_duration, event.duration)
+ end
+
+ def increment(key, duration)
+ return unless current_transaction
+
+ current_transaction.increment(:cache_duration, duration)
+ current_transaction.increment(key, duration)
+ end
+
+ private
+
+ def current_transaction
+ Transaction.current
+ end
+ end
+ end
+ end
+end