Class: Cardio::Logger::Performance::CategoryLog
- Inherits:
-
Object
- Object
- Cardio::Logger::Performance::CategoryLog
- Defined in:
- lib/cardio/logger/performance/category_log.rb
Constant Summary collapse
- HIERARCHY =
{ 'SQL' => 0, 'rule' => 1, 'fetch' => 2, 'content' => 3, 'format' => 4 }
Instance Method Summary collapse
- #duration(category) ⇒ Object
- #each_pair ⇒ Object
-
#initialize(category = nil) ⇒ CategoryLog
constructor
A new instance of CategoryLog.
- #start(category) ⇒ Object
- #stop(category) ⇒ Object
Constructor Details
#initialize(category = nil) ⇒ CategoryLog
Returns a new instance of CategoryLog.
13 14 15 16 17 18 19 20 |
# File 'lib/cardio/logger/performance/category_log.rb', line 13 def initialize category=nil @time_per_category = Hash.new { |h, key| h[key] = 0 } @start_time = {} @stack = [] if category start category end end |
Instance Method Details
#duration(category) ⇒ Object
45 46 47 |
# File 'lib/cardio/logger/performance/category_log.rb', line 45 def duration category @time_per_category[category] end |
#each_pair ⇒ Object
49 50 51 52 53 54 |
# File 'lib/cardio/logger/performance/category_log.rb', line 49 def each_pair cats = (['SQL', 'rule', 'fetch', 'content', 'format'] & @time_per_category.keys) | @time_per_category.keys cats.each do |key| yield(key, @time_per_category[key]) end end |
#start(category) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cardio/logger/performance/category_log.rb', line 22 def start category if active_category if hierarchy(category) < hierarchy(active_category) pause active_category else return end end @start_time[category] = Time.now @stack << category end |
#stop(category) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/cardio/logger/performance/category_log.rb', line 35 def stop category if active_category == category save_duration category @stack.pop if active_category continue active_category end end end |