Last active
February 12, 2016 14:41
-
-
Save dcadenas/7388d4c856562d2dbb04 to your computer and use it in GitHub Desktop.
How to find origin of current running threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'objspace' | |
ObjectSpace.trace_object_allocations_start | |
def all_child_threads | |
Thread.list - [Thread.current] | |
end | |
trap(:INFO) { | |
puts "#" * 90 | |
all_child_threads.each do |t| | |
p ObjectSpace.allocation_sourcefile(t) => ObjectSpace.allocation_sourceline(t) | |
end | |
puts "#" * 90 | |
} | |
Thread.new do | |
loop do | |
puts 'thread 1' | |
sleep(1) | |
end | |
end | |
Thread.new do | |
loop do | |
puts 'thread 2' | |
sleep(1) | |
end | |
end | |
all_child_threads.each(&:join) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment