Sha256: a634b116fd324d90d4aef9e356c70e38c193e01e7276599d4634d727a21765c8

Contents?: true

Size: 779 Bytes

Versions: 5

Compression:

Stored size: 779 Bytes

Contents

class Flamegraph::StackProfSampler
  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[: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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flamegraph-0.1.0 lib/flamegraph/stackprof_sampler.rb
flamegraph-0.0.9 lib/flamegraph/stackprof_sampler.rb
flamegraph-0.0.8 lib/flamegraph/stackprof_sampler.rb
flamegraph-0.0.7 lib/flamegraph/stackprof_sampler.rb
flamegraph-0.0.6 lib/flamegraph/stackprof_sampler.rb