class NoBrainer::Profiler::ControllerRuntime::Profiler

Attributes

other_duration[RW]
read_duration[RW]
write_duration[RW]

Public Class Methods

cleanup_controller_profiler() click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 27
def self.cleanup_controller_profiler
  Thread.current[:nobrainer_controller_profiler] = nil
end
current() click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 31
def self.current
  Thread.current[:nobrainer_controller_profiler]
end
new() click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 7
def initialize
  @write_duration = @read_duration = @other_duration = 0.0
end
on_query(env) click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 35
def self.on_query(env)
  current.try(:add_query, env)
end
spawn_controller_profiler() click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 23
def self.spawn_controller_profiler
  Thread.current[:nobrainer_controller_profiler] = new
end

Public Instance Methods

add_query(env) click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 15
def add_query(env)
  case env[:query_type]
  when :write      then @write_duration += env[:duration]
  when :read       then @read_duration  += env[:duration]
  else                  @other_duration += env[:duration]
  end
end
total_duration() click to toggle source
# File lib/no_brainer/profiler/controller_runtime.rb, line 11
def total_duration
  read_duration + write_duration + other_duration
end