Class: Strumbar::Instrumentation::Mongoid::RuntimeTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/strumbar/instrumentation/mongoid/runtime_tracker.rb

Overview

This is basically how ActiveRecord instruments this, although they use a LogSubscriber, for no adequately explained reason. I’m not sure if we should include the controller mixin in Strumbar or not? Seems simultaneously in and out of scope.

Constant Summary collapse

RUNTIME_KEY =
'Mongoid::RuntimeTracker#runtime'
COUNT_KEY =
'Mongoid::RuntimeTracker#count'

Class Method Summary collapse

Class Method Details

.countObject



23
24
25
# File 'lib/strumbar/instrumentation/mongoid/runtime_tracker.rb', line 23

def self.count
  Thread.current[COUNT_KEY] ||= 0
end

.count=(value) ⇒ Object



19
20
21
# File 'lib/strumbar/instrumentation/mongoid/runtime_tracker.rb', line 19

def self.count= value
  Thread.current[COUNT_KEY] = value
end

.resetObject



27
28
29
30
# File 'lib/strumbar/instrumentation/mongoid/runtime_tracker.rb', line 27

def self.reset
  time, self.runtime, self.count = runtime, 0, 0
  time
end

.runtimeObject



15
16
17
# File 'lib/strumbar/instrumentation/mongoid/runtime_tracker.rb', line 15

def self.runtime
  Thread.current[RUNTIME_KEY] ||= 0
end

.runtime=(value) ⇒ Object



11
12
13
# File 'lib/strumbar/instrumentation/mongoid/runtime_tracker.rb', line 11

def self.runtime= value
  Thread.current[RUNTIME_KEY] = value
end