Class: Flamegraph::StackProfSampler

Inherits:
Object
  • Object
show all
Defined in:
lib/flamegraph/stackprof_sampler.rb

Class Method Summary collapse

Class Method Details

.collect(fidelity = 0.5) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
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
# File 'lib/flamegraph/stackprof_sampler.rb', line 2

def self.collect(fidelity=0.5)

  result = StackProf.run(mode: :wall,
                         raw: true,
                         aggregate: false,
                         interval: (fidelity * 1000).to_i) do
    yield
  end


  stacks = []
  stack = []

  return [] unless result && result[:raw]

  length = nil
  result[:raw].each do |i|
    if length.nil?
      length = i
      next
    end

    if length > 0
      frame = result[:frames][i]
      frame = "#{frame[:file]}:#{frame[:line]}:in `#{frame[:name]}'"
      stack << frame.to_s
      length -= 1
      next
    end

    i.times do
      stacks << stack.reverse
    end

    stack = []
    length = nil
  end

  stacks
end