Module: RequireProfiler
- Defined in:
- lib/require_profiler/version.rb,
lib/require_profiler.rb,
lib/require_profiler/plugins.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/ruby_profiling.rb,
lib/require_profiler/printer/call_stack.rb,
lib/require_profiler/plugins/http_plugin.rb,
lib/require_profiler/plugins/yaml_plugin.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Plugins, Printer, RubyProfiling Classes: Reporter
Constant Summary collapse
- VERSION =
"0.2.1"
Class Attribute Summary collapse
-
.reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Class Method Summary collapse
- .start(output: ENV.fetch("REQUIRE_PROFILE_PATH", $stdout), format: ENV["REQUIRE_PROFILE_FORMAT"], threshold: ENV.fetch("REQUIRE_PROFILE_THRESHOLD", "0.0").to_f, focus: ENV["REQUIRE_PROFILE_FOCUS"], patterns: nil, exclude_patterns: nil) ⇒ Object
- .stop ⇒ Object
Class Attribute Details
.reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
12 13 14 |
# File 'lib/require_profiler.rb', line 12 def reporter @reporter end |
Class Method Details
.start(output: ENV.fetch("REQUIRE_PROFILE_PATH", $stdout), format: ENV["REQUIRE_PROFILE_FORMAT"], threshold: ENV.fetch("REQUIRE_PROFILE_THRESHOLD", "0.0").to_f, focus: ENV["REQUIRE_PROFILE_FOCUS"], patterns: nil, exclude_patterns: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/require_profiler.rb', line 14 def start( output: ENV.fetch("REQUIRE_PROFILE_PATH", $stdout), format: ENV["REQUIRE_PROFILE_FORMAT"], threshold: ENV.fetch("REQUIRE_PROFILE_THRESHOLD", "0.0").to_f, focus: ENV["REQUIRE_PROFILE_FOCUS"], patterns: nil, exclude_patterns: nil ) raise ArgumentError, "There is already profiling in progress" if reporter focus = Regexp.new(focus) if focus.is_a?(String) reporter = @reporter = Reporter.new(printer: Printer.resolve(output, format, threshold:, focus:), focus:) 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:)) if RubyProfiling.enabled? RubyProfiling.capture(path) { block.call } else block.call end ensure time = Time.now - start reporter.handle_event(Reporter::Event.new(type: :end, path:, time:)) end Plugins.register_reporter(reporter) unless ENV["REQUIRE_PROFILER_PLUGINS"] == "false" end |
.stop ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/require_profiler.rb', line 46 def stop raise "No reporter defined. Are you sure you called RequireProfiler.start?" unless reporter reporter.finish.tap do @reporter = nil end end |