Class: Rack::Bug::CachePanel::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/panels/cache_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.



33
34
35
36
37
38
39
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 33

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

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



29
30
31
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 29

def calls
  @calls
end

#keysObject (readonly)

Returns the value of attribute keys.



30
31
32
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 30

def keys
  @keys
end

#queriesObject (readonly)

Returns the value of attribute queries.



31
32
33
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 31

def queries
  @queries
end

Instance Method Details

#count_queries(method) ⇒ Object



82
83
84
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 82

def count_queries(method)
  @queries.select { |q| q.method == method }.size
end

#deletesObject



66
67
68
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 66

def deletes
  count_queries(:delete)
end

#display_timeObject



48
49
50
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 48

def display_time
  "%.2fms" % time
end

#get_multisObject



70
71
72
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 70

def get_multis
  count_queries(:get_multi)
end

#getsObject



58
59
60
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 58

def gets
  count_queries(:get)
end

#hitsObject



74
75
76
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 74

def hits
  @queries.select { |q| [:get, :get_multi].include?(q.method) && q.hit }.size
end

#missesObject



78
79
80
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 78

def misses
  @queries.select { |q| [:get, :get_multi].include?(q.method) && !q.hit }.size
end

#queries_to_paramObject



86
87
88
89
90
91
92
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 86

def queries_to_param
  params = {}
  @queries.each_with_index do |query, index|
    params["keys_#{index}"] = query.keys.first
  end
  params
end

#record_call(method, time, hit, *keys) ⇒ Object



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

def record_call(method, time, hit, *keys)
  @queries << Query.new(method, time, hit, keys)
  @calls += 1
  @time += time
  @keys += keys
end

#setsObject



62
63
64
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 62

def sets
  count_queries(:set)
end

#timeObject



52
53
54
55
56
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 52

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