Class: Camayoc::Stats
- Inherits:
-
Object
- Object
- Camayoc::Stats
- Defined in:
- lib/camayoc/stats.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
Returns the value of attribute handlers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#<<(handler) ⇒ Object
Quick alias for adding a handler.
- #[](descendant_name) ⇒ Object
-
#add(handler, filter_opts = {}) ⇒ Object
- Add handler with filter options *
handler
- Handler instance *
filter_opts
-
Options for a new Handlers::Filter instance (optional).
- Handler instance *
- Add handler with filter options *
-
#benchmark(stat, options = {}) ⇒ Object
Executes a block, stores the timing information in the specified stat and returns the value of the block.
-
#count(stat, value, options = {}) ⇒ Object
Count and incr/decr convenience methods.
- #decrement(stat, options = {}) ⇒ Object
-
#event(stat, value, options = {}) ⇒ Object
Generic event.
- #increment(stat, options = {}) ⇒ Object
-
#initialize(name, parent = nil) ⇒ Stats
constructor
- Constructor *
name
- Name of stat *
parent
-
Optional parent stat (default: nil).
- Name of stat *
- Constructor *
-
#realtime(stat, options = {}) ⇒ Object
Executes a block, stores the timing information in the specified stat and returns the time **in seconds** that the execution took.
-
#timing(stat, value, options = {}) ⇒ Object
Timing stat.
Constructor Details
#initialize(name, parent = nil) ⇒ Stats
Constructor
name
-
Name of stat
parent
-
Optional parent stat (default: nil)
9 10 11 12 13 |
# File 'lib/camayoc/stats.rb', line 9 def initialize(name,parent=nil) self.name = name self.parent = parent self.handlers = [] end |
Instance Attribute Details
#handlers ⇒ Object
Returns the value of attribute handlers.
4 5 6 |
# File 'lib/camayoc/stats.rb', line 4 def handlers @handlers end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/camayoc/stats.rb', line 4 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/camayoc/stats.rb', line 4 def parent @parent end |
Instance Method Details
#<<(handler) ⇒ Object
Quick alias for adding a handler
32 33 34 |
# File 'lib/camayoc/stats.rb', line 32 def <<(handler) self.add(handler) end |
#[](descendant_name) ⇒ Object
15 16 17 |
# File 'lib/camayoc/stats.rb', line 15 def [](descendant_name) Camayoc[Camayoc.join(name,descendant_name)] end |
#add(handler, filter_opts = {}) ⇒ Object
Add handler with filter options
handler
-
Handler instance
filter_opts
-
Options for a new Handlers::Filter instance (optional)
23 24 25 26 27 28 29 |
# File 'lib/camayoc/stats.rb', line 23 def add(handler,filter_opts={}) if !filter_opts.empty? handler = Handlers::Filter.new(handler,filter_opts) end self.handlers << handler self end |
#benchmark(stat, options = {}) ⇒ Object
Executes a block, stores the timing information in the specified stat and returns the value of the block. Use this to wrap existing code with timing information without worrying about return values.
62 63 64 65 66 67 68 |
# File 'lib/camayoc/stats.rb', line 62 def benchmark(stat,={}) result = nil realtime(stat,) do result = yield end result end |
#count(stat, value, options = {}) ⇒ Object
Count and incr/decr convenience methods
47 48 49 |
# File 'lib/camayoc/stats.rb', line 47 def count(stat,value,={}) propagate(:count,stat,value,) end |
#decrement(stat, options = {}) ⇒ Object
55 56 57 |
# File 'lib/camayoc/stats.rb', line 55 def decrement(stat,={}) count(stat,-1,) end |
#event(stat, value, options = {}) ⇒ Object
Generic event
42 43 44 |
# File 'lib/camayoc/stats.rb', line 42 def event(stat,value,={}) propagate(:generic,stat,value,) end |
#increment(stat, options = {}) ⇒ Object
51 52 53 |
# File 'lib/camayoc/stats.rb', line 51 def increment(stat,={}) count(stat,1,) end |
#realtime(stat, options = {}) ⇒ Object
Executes a block, stores the timing information in the specified stat and returns the time **in seconds** that the execution took. This is basically a drop-in replacement for calls to Benchmark.realtime
73 74 75 76 77 78 79 80 |
# File 'lib/camayoc/stats.rb', line 73 def realtime(stat,={}) start_time = Time.now yield duration = (Time.now.to_f - start_time.to_f) # Convert to ms for timing call timing(stat,(duration*1000).round,) duration end |
#timing(stat, value, options = {}) ⇒ Object
Timing stat
37 38 39 |
# File 'lib/camayoc/stats.rb', line 37 def timing(stat,value,={}) propagate(:timing,stat,value,) end |