Class: Insight::CachePanel::Stats
- Inherits:
-
Object
- Object
- Insight::CachePanel::Stats
- Defined in:
- lib/insight/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, key) ⇒ Object
- #sets ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize ⇒ Stats
Returns a new instance of Stats.
32 33 34 35 36 37 38 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 32 def initialize @queries = [] @misses = @calls = 0 @time = 0.0 @keys = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
28 29 30 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 28 def calls @calls end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
29 30 31 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 29 def keys @keys end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
30 31 32 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 30 def queries @queries end |
Instance Method Details
#count_queries(method) ⇒ Object
85 86 87 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 85 def count_queries(method) @queries.select { |q| q.method == method }.size end |
#deletes ⇒ Object
69 70 71 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 69 def deletes count_queries(:delete) end |
#display_time ⇒ Object
51 52 53 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 51 def display_time "%.2fms" % time end |
#get_multis ⇒ Object
73 74 75 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 73 def get_multis count_queries(:get_multi) end |
#gets ⇒ Object
61 62 63 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 61 def gets count_queries(:get) end |
#hits ⇒ Object
77 78 79 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 77 def hits @queries.select { |q| [:get, :get_multi].include?(q.method) && q.hit }.size end |
#misses ⇒ Object
81 82 83 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 81 def misses @queries.select { |q| [:get, :get_multi].include?(q.method) && !q.hit }.size end |
#queries_to_param ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 89 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, key) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 40 def record_call(method, time, hit, key) if Array === key @queries << Query.new(:get_multi, time, hit, key) else @queries << Query.new(method.to_sym, time, hit, [key]) end @calls += 1 @time += time @keys += keys end |
#sets ⇒ Object
65 66 67 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 65 def sets count_queries(:set) end |
#time ⇒ Object
55 56 57 58 59 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 55 def time @queries.inject(0) do |memo, query| memo + query.time end end |