Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump heap from a fork #90

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/rbtrace/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,19 @@ def self.run
temp.unlink
end

tracer.eval("file = File.open('#{filename}', 'w'); ObjectSpace.dump_all(output: file); file.close")
tracer.eval(<<-RUBY)
Thread.new do
Thread.current.name = '__RBTrace__'
pid = ::Process.fork do
file = File.open('#{filename}.tmp', 'w')
ObjectSpace.dump_all(output: file)
file.close
File.rename('#{filename}.tmp', '#{filename}')
exit!(0)
end
Process.waitpid(pid)
end
RUBY
puts "Heapdump being written to #{filename}"

elsif opts[:shapesdump_given]
Expand All @@ -517,7 +529,19 @@ def self.run
temp.unlink
end

tracer.eval("file = File.open('#{filename}', 'w'); ObjectSpace.dump_shapes(output: file); file.close")
tracer.eval(<<-RUBY)
Thread.new do
Thread.current.name = '__RBTrace__'
pid = ::Process.fork do
file = File.open('#{filename}.tmp', 'w')
ObjectSpace.dump_shapes(output: file)
file.close
File.rename('#{filename}.tmp', '#{filename}')
exit!(0)
end
Process.waitpid(pid)
end
RUBY
puts "Shapes dump being written to #{filename}"

elsif opts[:eval_given]
Expand Down