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 ⇒ Object
- #run! ⇒ 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) ⇒ Object
10 11 12 |
# File 'lib/iev/profiler.rb', line 10 def self.measure(prefix = nil, &) new(prefix).run(&) end |
Instance Method Details
#profiler_enabled? ⇒ Boolean
35 36 37 |
# File 'lib/iev/profiler.rb', line 35 def profiler_enabled? $IEV_PROFILE end |
#run ⇒ Object
19 20 21 |
# File 'lib/iev/profiler.rb', line 19 def run(&) profiler_enabled? ? run!(&) : yield end |
#run! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/iev/profiler.rb', line 23 def run! retval = nil @profile = RubyProf.profile allow_exceptions: true do @bench = Benchmark.measure do retval = yield end end retval ensure print_reports end |