Class: Rack::Bug::CachePanel::Stats
- Inherits:
-
Object
- Object
- Rack::Bug::CachePanel::Stats
- Defined in:
- lib/rack/bug/panels/cache_panel/stats.rb
Defined Under Namespace
Classes: Query
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Instance Method Summary collapse
- #count_queries(method) ⇒ Object
- #deletes ⇒ Object
- #display_time ⇒ Object
- #get_multis ⇒ Object
- #gets ⇒ Object
- #hits ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #misses ⇒ Object
- #queries_to_param ⇒ Object
- #record_call(method, time, hit, *keys) ⇒ Object
- #sets ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize ⇒ Stats
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
#calls ⇒ Object (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 |
#keys ⇒ Object (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 |
#queries ⇒ Object (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 |
#deletes ⇒ Object
66 67 68 |
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 66 def deletes count_queries(:delete) end |
#display_time ⇒ Object
48 49 50 |
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 48 def display_time "%.2fms" % time end |
#get_multis ⇒ Object
70 71 72 |
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 70 def get_multis count_queries(:get_multi) end |
#gets ⇒ Object
58 59 60 |
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 58 def gets count_queries(:get) end |
#hits ⇒ Object
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 |
#misses ⇒ Object
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_param ⇒ Object
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 |
#sets ⇒ Object
62 63 64 |
# File 'lib/rack/bug/panels/cache_panel/stats.rb', line 62 def sets count_queries(:set) end |
#time ⇒ Object
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 |