Class: Rack::Bug::RedisPanel::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/panels/redis_panel/stats.rb

Defined Under Namespace

Classes: Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



26
27
28
29
30
# File 'lib/rack/bug/panels/redis_panel/stats.rb', line 26

def initialize
  @queries = []
  @calls = 0
  @time = 0.0
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



23
24
25
# File 'lib/rack/bug/panels/redis_panel/stats.rb', line 23

def calls
  @calls
end

#queriesObject (readonly)

Returns the value of attribute queries.



24
25
26
# File 'lib/rack/bug/panels/redis_panel/stats.rb', line 24

def queries
  @queries
end

Instance Method Details

#display_timeObject



38
39
40
# File 'lib/rack/bug/panels/redis_panel/stats.rb', line 38

def display_time
  "%.2fms" % time
end

#record_call(time, command_args, backtrace) ⇒ Object



32
33
34
35
36
# File 'lib/rack/bug/panels/redis_panel/stats.rb', line 32

def record_call(time, command_args, backtrace)
  @queries << Query.new(time, command_args, backtrace)
  @calls += 1
  @time += time
end

#timeObject



42
43
44
45
46
# File 'lib/rack/bug/panels/redis_panel/stats.rb', line 42

def time
  @queries.inject(0) do |memo, query|
    memo + query.time
  end
end