Module: Flows::Plugin::Profiler
- Defined in:
- lib/flows/plugin/profiler.rb,
lib/flows/plugin/profiler/report.rb,
lib/flows/plugin/profiler/wrapper.rb,
lib/flows/plugin/profiler/injector.rb,
lib/flows/plugin/profiler/report/raw.rb,
lib/flows/plugin/profiler/report/flat.rb,
lib/flows/plugin/profiler/report/tree.rb,
lib/flows/plugin/profiler/report/events.rb,
lib/flows/plugin/profiler/report/tree/node.rb,
lib/flows/plugin/profiler/report/flat/method_report.rb,
lib/flows/plugin/profiler/report/tree/calculated_node.rb
Overview
even without calling Profiler.profile using this module has some performance impact. Don't left this module used in production environments.
Allows to record execution count and time of particular method on class or singleton class.
Recorded data can be displayed in a different ways. See Report implementations for possible options.
To do a measurement you have call your classes inside Profiler.profile block.
Defined Under Namespace
Modules: Injector, Wrapper Classes: Report
Constant Summary collapse
- THREAD_VAR_FLAG =
:flows_profiler_flag
- THREAD_VAR_REPORT =
:flows_profiler_report
Class Method Summary collapse
-
.for_method(method_name) ⇒ Module
Generates profiler module for a particular method.
-
.last_report ⇒ Report?
Last generated report if some.
-
.profile(report = :raw) { ... } ⇒ Object
Profiles a block execution.
-
.reset ⇒ Object
Resets thread-local variables used for reporting.
Class Method Details
.for_method(method_name) ⇒ Module
Generates profiler module for a particular method.
Use include
for instance methods and extend
for singleton ones.
63 64 65 66 67 68 69 |
# File 'lib/flows/plugin/profiler.rb', line 63 def for_method(method_name) Module.new.tap do |mod| injector_mod = Injector.make_module(method_name) mod.const_set(:Injector, injector_mod) mod.extend injector_mod end end |
.last_report ⇒ Report?
Returns last generated report if some.
97 98 99 |
# File 'lib/flows/plugin/profiler.rb', line 97 def last_report Thread.current[THREAD_VAR_REPORT] end |
.profile(report = :raw) { ... } ⇒ Object
Profiles a block execution.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/flows/plugin/profiler.rb', line 78 def profile(report = :raw) thread = Thread.current thread[THREAD_VAR_FLAG] = true thread[THREAD_VAR_REPORT] = make_report(report) yield ensure thread[THREAD_VAR_FLAG] = false end |
.reset ⇒ Object
Resets thread-local variables used for reporting.
90 91 92 93 94 |
# File 'lib/flows/plugin/profiler.rb', line 90 def reset thread = Thread.current thread[THREAD_VAR_FLAG] = false thread[THREAD_VAR_REPORT] = nil end |