Skip to content

Commit

Permalink
Fixed: Pprof compatibility with Ruby 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Sep 9, 2020
1 parent b520c63 commit 5bca986
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/ddtrace/profiling/pprof/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def build_locations(backtrace_locations, length)
if omitted > 0
desc = omitted == 1 ? DESC_FRAME_OMITTED : DESC_FRAMES_OMITTED
locations << @locations.fetch(
'',
''.freeze,
0,
"#{omitted} #{desc}",
&method(:build_location)
Expand Down
6 changes: 4 additions & 2 deletions lib/ddtrace/profiling/pprof/message_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def initialize(seed = 0, &block)
# If they match an existing message, it will return the
# matching object. If it doesn't match, it will yield to
# the block with the next ID & args given.
def fetch(*args)
def fetch(*args, &block)
key = @key_block ? @key_block.call(*args) : args.hash
@items[key] ||= yield(@sequence.next, *args)
# TODO: Ruby 2.0 doesn't like yielding here... switch when 2.0 is dropped.
# rubocop:disable Performance/RedundantBlockCall
@items[key] ||= block.call(@sequence.next, *args)
end

def length
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/profiling/pprof/string_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Pprof
class StringTable
def initialize
@sequence = Utils::Sequence.new
@ids = { '' => @sequence.next }
@ids = { ''.freeze => @sequence.next }
end

def fetch(string)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/profiling/pprof/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
before do
expect(described_class)
.to receive(:new)
.with([described_class::DEFAULT_MAPPINGS.first].to_h)
.with(Hash[[described_class::DEFAULT_MAPPINGS.first]])
.and_return(template)
end

Expand Down

0 comments on commit 5bca986

Please sign in to comment.