Module: Lrama::Reporter::Profile::CallStack

Defined in:
lib/lrama/reporter/profile/call_stack.rb

Class Method Summary collapse

Class Method Details

.report(enabled) ⇒ Object

See “Call-stack Profiling Lrama” in README.md for how to use.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lrama/reporter/profile/call_stack.rb', line 13

def self.report(enabled)
  if enabled && require_stackprof
    ex = nil #: Exception?
    path = 'tmp/stackprof-cpu-myapp.dump'

    StackProf.run(mode: :cpu, raw: true, out: path) do
      yield
    rescue Exception => e
      ex = e
    end

    STDERR.puts("Call-stack Profiling result is generated on #{path}")

    if ex
      raise ex
    end
  else
    yield
  end
end

.require_stackprofObject



35
36
37
38
39
40
41
# File 'lib/lrama/reporter/profile/call_stack.rb', line 35

def self.require_stackprof
  require "stackprof"
  true
rescue LoadError
  warn "stackprof is not installed. Please run `bundle install`."
  false
end