Module: RequireProfiler
- Defined in:
- lib/require_profiler/version.rb,
lib/require_profiler.rb,
lib/require_profiler/printer.rb,
lib/require_profiler/reporter.rb,
lib/require_profiler/printer/json.rb,
lib/require_profiler/printer/text.rb,
lib/require_profiler/printer/call_stack.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Printer Classes: Reporter
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Class Method Summary collapse
Class Attribute Details
.reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
8 9 10 |
# File 'lib/require_profiler.rb', line 8 def reporter @reporter end |
Class Method Details
.start(output: $stdout, format: nil, patterns: nil, exclude_patterns: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/require_profiler.rb', line 10 def start(output: $stdout, format: nil, patterns: nil, exclude_patterns: nil) raise ArgumentError, "There is already profiling in progress" if reporter reporter = @reporter = Reporter.new(printer: Printer.resolve(output, format)) require "require-hooks/setup" ::RequireHooks.around_load(patterns:, exclude_patterns:) do |path, &block| start = Time.now reporter.handle_event(Reporter::Event.new(type: :start, path:)) block.call ensure time = Time.now - start reporter.handle_event(Reporter::Event.new(type: :end, path:, time:)) end end |
.stop ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/require_profiler.rb', line 29 def stop raise "No reporter defined. Are you sure you called RequireProfiler.start?" unless reporter reporter.finish.tap do @reporter = nil end end |