Class: AppProfiler::Backend::StackprofBackend
- Inherits:
-
BaseBackend
- Object
- BaseBackend
- AppProfiler::Backend::StackprofBackend
- Defined in:
- lib/app_profiler/backend/stackprof_backend.rb
Constant Summary collapse
- DEFAULTS =
{ mode: :cpu, raw: true, }.freeze
- AVAILABLE_MODES =
[ :wall, :cpu, :object, ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #results ⇒ Object
- #run(params = {}) ⇒ Object
- #running? ⇒ Boolean
- #start(params = {}) ⇒ Object
- #stop ⇒ Object
Methods inherited from BaseBackend
Class Method Details
.name ⇒ Object
20 21 22 |
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 20 def name :stackprof end |
Instance Method Details
#results ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 63 def results stackprof_profile = backend_results return unless stackprof_profile BaseProfile.from_stackprof(stackprof_profile) rescue => error AppProfiler.logger.info( "[Profiler] failed to obtain the profile error_class=#{error.class} error_message=#{error.}", ) nil end |
#run(params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 25 def run(params = {}) started = start(params) yield return unless started stop results ensure # Only stop the profiler if profiling was started in this context. stop if started end |
#running? ⇒ Boolean
76 77 78 |
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 76 def running? StackProf.running? end |
#start(params = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 39 def start(params = {}) # Do not start the profiler if StackProf was started somewhere else. return false if running? return false unless acquire_run_lock clear StackProf.start(**DEFAULTS, **params) rescue => error AppProfiler.logger.info( "[Profiler] failed to start the profiler error_class=#{error.class} error_message=#{error.}", ) release_run_lock # This is a boolean instead of nil because StackProf#start returns a # boolean as well. false end |
#stop ⇒ Object
57 58 59 60 61 |
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 57 def stop StackProf.stop ensure release_run_lock end |