Skip to content

Instantly share code, notes, and snippets.

@fragoulis
Last active January 26, 2021 07:56
Show Gist options
  • Save fragoulis/552b9e15d71ba21b6583fe76b623dfd3 to your computer and use it in GitHub Desktop.
Save fragoulis/552b9e15d71ba21b6583fe76b623dfd3 to your computer and use it in GitHub Desktop.
Getting a memory profile on a running ruby process
bundle exec rbtrace -p $1 -e 'Thread.new{GC.start;require "objspace";io=File.open("/tmp/ruby-heap.dump", "w"); ObjectSpace.dump_all(output: io); io.close}'
bundle exec rbtrace -p $1 -e 'Thread.new{require "memory_profiler"; MemoryProfiler.start}'
bundle exec rbtrace -p $1 -e 'Thread.new{require "memory_profiler"; MemoryProfiler.stop.pretty_print(to_file: "/tmp/memory_profiler.log", detailed_report: true, scale_bytes: true)}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment