Class: IEV::Profiler
- Inherits:
-
Object
- Object
- IEV::Profiler
- Defined in:
- lib/iev/profiler.rb
Instance Attribute Summary collapse
-
#bench ⇒ Object
readonly
Returns the value of attribute bench.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(prefix, dir: "profile") ⇒ Profiler
constructor
A new instance of Profiler.
- #profiler_enabled? ⇒ Boolean
- #run(&block) ⇒ Object
- #run!(&block) ⇒ Object
Constructor Details
#initialize(prefix, dir: "profile") ⇒ Profiler
Returns a new instance of Profiler.
14 15 16 17 |
# File 'lib/iev/profiler.rb', line 14 def initialize(prefix, dir: "profile") @prefix = prefix @dir = dir end |
Instance Attribute Details
#bench ⇒ Object (readonly)
Returns the value of attribute bench.
8 9 10 |
# File 'lib/iev/profiler.rb', line 8 def bench @bench end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
8 9 10 |
# File 'lib/iev/profiler.rb', line 8 def dir @dir end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/iev/profiler.rb', line 8 def prefix @prefix end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
8 9 10 |
# File 'lib/iev/profiler.rb', line 8 def profile @profile end |
Class Method Details
.measure(prefix = nil, &block) ⇒ Object
10 11 12 |
# File 'lib/iev/profiler.rb', line 10 def self.measure(prefix = nil, &block) new(prefix).run(&block) end |
Instance Method Details
#profiler_enabled? ⇒ Boolean
35 36 37 |
# File 'lib/iev/profiler.rb', line 35 def profiler_enabled? $IEV_PROFILE end |
#run(&block) ⇒ Object
19 20 21 |
# File 'lib/iev/profiler.rb', line 19 def run(&block) profiler_enabled? ? run!(&block) : block.call end |
#run!(&block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/iev/profiler.rb', line 23 def run!(&block) retval = nil @profile = RubyProf.profile allow_exceptions: true do @bench = Benchmark.measure do retval = block.call end end retval ensure print_reports end |