mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-11 05:36:07 +10:00
This allows us to track how much time of a transaction is spent in dealing with cached data.
40 lines
959 B
Ruby
40 lines
959 B
Ruby
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
|