Class: AppProfiler::Backend::StackprofBackend

Inherits:
BaseBackend
  • Object
show all
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

Methods inherited from BaseBackend

#run, run_lock

Class Method Details

.nameObject



20
21
22
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 20

def name
  :stackprof
end

Instance Method Details

#resultsObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 49

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.message}",
  )
  nil
end

#running?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 62

def running?
  StackProf.running?
end

#start(params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 25

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.message}",
  )
  release_run_lock
  # This is a boolean instead of nil because StackProf#start returns a
  # boolean as well.
  false
end

#stopObject



43
44
45
46
47
# File 'lib/app_profiler/backend/stackprof_backend.rb', line 43

def stop
  StackProf.stop
ensure
  release_run_lock
end