From 94f4a0e91ee7077bcb4391a6f754c6ec58e78a15 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sat, 29 Dec 2018 16:44:09 +0000 Subject: `TracePoint#enable(target_thraed:)` [Feature #15473] * vm_trace.c (tracepoint_enable_m): `TracePoint#enable` supports `target_thread:` keyword to filter a target thread. [Feature #15473] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_settracefunc.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 2ada093f8d..6c07bf90f6 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -2115,4 +2115,42 @@ class TestSetTraceFunc < Test::Unit::TestCase } assert_equal [], events end + + def test_enable_target_thread + events = [] + TracePoint.new(:line) do |tp| + events << Thread.current + end.enable(target_thread: Thread.current) do + a = 1 + Thread.new{ + b = 2 + c = 3 + }.join + d = 4 + end + assert_equal Array.new(3){Thread.current}, events + + events = [] + tp = TracePoint.new(:line) do |tp| + events << Thread.current + end + + q1 = Queue.new + q2 = Queue.new + + th = Thread.new{ + q1 << :ok; q2.pop + t1 = 1 + t2 = 2 + } + q1.pop + tp.enable(target_thread: th) do + q2 << 1 + a = 1 + b = 2 + th.join + end + + assert_equal Array.new(2){th}, events + end end -- cgit v1.2.3