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)
-
- (Object) calls
readonly
Returns the value of attribute calls.
-
- (Object) keys
readonly
Returns the value of attribute keys.
-
- (Object) queries
readonly
Returns the value of attribute queries.
Instance Method Summary (collapse)
- - (Object) count_queries(method)
- - (Object) deletes
- - (Object) display_time
- - (Object) get_multis
- - (Object) gets
- - (Object) hits
-
- (Stats) initialize
constructor
A new instance of Stats.
- - (Object) misses
- - (Object) queries_to_param
- - (Object) record_call(method, time, hit, key)
- - (Object) sets
- - (Object) time
Constructor Details
- (Stats) initialize
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
- (Object) calls (readonly)
Returns the value of attribute calls
28 29 30 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 28 def calls @calls end |
- (Object) keys (readonly)
Returns the value of attribute keys
29 30 31 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 29 def keys @keys end |
- (Object) queries (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
- (Object) count_queries(method)
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 |
- (Object) deletes
69 70 71 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 69 def deletes count_queries(:delete) end |
- (Object) display_time
51 52 53 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 51 def display_time "%.2fms" % time end |
- (Object) get_multis
73 74 75 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 73 def get_multis count_queries(:get_multi) end |
- (Object) gets
61 62 63 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 61 def gets count_queries(:get) end |
- (Object) hits
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 |
- (Object) misses
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 |
- (Object) queries_to_param
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 |
- (Object) record_call(method, time, hit, key)
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 |
- (Object) sets
65 66 67 |
# File 'lib/insight/panels/cache_panel/stats.rb', line 65 def sets count_queries(:set) end |
- (Object) time
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 |