Skip to content

Commit

Permalink
Merge pull request #90 from casperisfine/dump-fork
Browse files Browse the repository at this point in the history
Dump heap from a fork
  • Loading branch information
SamSaffron authored Feb 1, 2023
2 parents 326800f + 3e03fd3 commit aa3e716
Showing 1 changed file with 26 additions and 2 deletions.
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

0 comments on commit aa3e716

Please sign in to comment.