Class: Wildsight::Profiler::Profile
- Inherits:
-
Object
- Object
- Wildsight::Profiler::Profile
- Defined in:
- lib/wildsight/profiler/profiler.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #<<(time) ⇒ Object
- #close ⇒ Object
- #duration ⇒ Object
- #exception ⇒ Object
- #export ⇒ Object
-
#initialize(name, parent) ⇒ Profile
constructor
A new instance of Profile.
- #profile!(&block) ⇒ Object
- #raw ⇒ Object
- #result ⇒ Object
- #set(before, after) ⇒ Object
- #subtimes ⇒ Object
Constructor Details
#initialize(name, parent) ⇒ Profile
Returns a new instance of Profile.
44 45 46 47 48 49 50 |
# File 'lib/wildsight/profiler/profiler.rb', line 44 def initialize(name, parent) @name = name @parent = parent @subtimes = [] @result = nil @exception = nil end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
42 43 44 |
# File 'lib/wildsight/profiler/profiler.rb', line 42 def @options end |
Instance Method Details
#<<(time) ⇒ Object
80 81 82 |
# File 'lib/wildsight/profiler/profiler.rb', line 80 def <<(time) @subtimes << time end |
#close ⇒ Object
67 68 69 70 |
# File 'lib/wildsight/profiler/profiler.rb', line 67 def close @parent << raw if @parent @parent end |
#duration ⇒ Object
88 89 90 91 |
# File 'lib/wildsight/profiler/profiler.rb', line 88 def duration return raw if [:raw] return raw - subtimes end |
#exception ⇒ Object
76 77 78 |
# File 'lib/wildsight/profiler/profiler.rb', line 76 def exception @exception end |
#export ⇒ Object
97 98 99 |
# File 'lib/wildsight/profiler/profiler.rb', line 97 def export { before: @before, after: @after, duration: duration, raw: raw } end |
#profile!(&block) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/wildsight/profiler/profiler.rb', line 57 def profile!(&block) @before = DateTime.now.to_f begin @result = block.call rescue Exception => e @exception = e end @after = DateTime.now.to_f end |
#raw ⇒ Object
93 94 95 |
# File 'lib/wildsight/profiler/profiler.rb', line 93 def raw (@after - @before) * 1000 end |
#result ⇒ Object
72 73 74 |
# File 'lib/wildsight/profiler/profiler.rb', line 72 def result @result end |
#set(before, after) ⇒ Object
52 53 54 55 |
# File 'lib/wildsight/profiler/profiler.rb', line 52 def set(before, after) @before = before @after = after end |
#subtimes ⇒ Object
84 85 86 |
# File 'lib/wildsight/profiler/profiler.rb', line 84 def subtimes @subtimes.inject(0.0) { |c,x| c + x } end |