Project

General

Profile

Actions

Bug #19114

open

Calling TracePoint#enable multiple times causes TracePoint to be activated multiple times

Added by ivoanjo (Ivo Anjo) 3 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0preview2 (2022-09-09 master 35cfc9a3bb) [x86_64-darwin20]
[ruby-core:110669]

Description

Howdy 👋! I work for Datadog on the ddtrace gem and I found an issue with TracePoint.

Background

For tracking time spent in Garbage Collection on our Ruby profiler, we use a tracepoint. While doing some experiments around our code, I realized that enabling the same TracePoint more than once made it trigger multiple times.

How to reproduce (Ruby version & script)

This can be reproduced with any tracepoint:

puts RUBY_DESCRIPTION
puts "Enabling tracepoint"
tracepoint = TracePoint.new(:line) { |tp| p [tp.path, tp.lineno, tp.event] }.tap(&:enable)
5.times { tracepoint.enable }
puts "Finished!"

Expectation and result

This is the output of the above script:

ruby 3.2.0preview2 (2022-09-09 master 35cfc9a3bb) [x86_64-darwin20]
Enabling tracepoint
["<internal:kernel>", 91, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["<internal:trace_point>", 213, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["triggertracepoint.rb", 4, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["<internal:trace_point>", 213, :line]
["triggertracepoint.rb", 5, :line]
["triggertracepoint.rb", 5, :line]
["triggertracepoint.rb", 5, :line]
["triggertracepoint.rb", 5, :line]
["triggertracepoint.rb", 5, :line]
["triggertracepoint.rb", 5, :line]
Finished!

My expectation is that once enabled, a TracePoint fires only once for each event, regardless of how many times TracePoint#enable was called. Instead, I see it being called as many times as #enable was called.

No data to display

Actions

Also available in: Atom PDF

Like0