Skip to content

Instantly share code, notes, and snippets.

@dcadenas
Last active February 12, 2016 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcadenas/7388d4c856562d2dbb04 to your computer and use it in GitHub Desktop.
Save dcadenas/7388d4c856562d2dbb04 to your computer and use it in GitHub Desktop.
How to find origin of current running threads
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