Bug #19114
closedCalling TracePoint#enable multiple times causes TracePoint to be activated multiple times
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.
Updated by kyanagi (Kouhei Yanagita) about 1 year ago
- Status changed from Open to Closed
Applied in changeset git|06e2fbb8260022de8532d2e940fc69e8ea413679.
[Bug #19114] Fix for multiple calls of TracePoint#enable
Updated by ivoanjo (Ivo Anjo) about 1 year ago
Nice, thanks for fixing this one! 🙇