Class: Insight::CachePanel::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/insight/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.



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

#callsObject (readonly)

Returns the value of attribute calls.



28
29
30
# File 'lib/insight/panels/cache_panel/stats.rb', line 28

def calls
  @calls
end

#keysObject (readonly)

Returns the value of attribute keys.



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

def keys
  @keys
end

#queriesObject (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

#deletesObject



69
70
71
# File 'lib/insight/panels/cache_panel/stats.rb', line 69

def deletes
  count_queries(:delete)
end

#display_timeObject



51
52
53
# File 'lib/insight/panels/cache_panel/stats.rb', line 51

def display_time
  "%.2fms" % time
end

#get_multisObject



73
74
75
# File 'lib/insight/panels/cache_panel/stats.rb', line 73

def get_multis
  count_queries(:get_multi)
end

#getsObject



61
62
63
# File 'lib/insight/panels/cache_panel/stats.rb', line 61

def gets
  count_queries(:get)
end

#hitsObject



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

#missesObject



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_paramObject



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

#setsObject



65
66
67
# File 'lib/insight/panels/cache_panel/stats.rb', line 65

def sets
  count_queries(:set)
end

#timeObject



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