Skip to content

Instantly share code, notes, and snippets.

@crakaC
Last active November 22, 2017 15:11
Show Gist options
  • Save crakaC/45daaa0af7685f2e49637ceb8fefaa00 to your computer and use it in GitHub Desktop.
Save crakaC/45daaa0af7685f2e49637ceb8fefaa00 to your computer and use it in GitHub Desktop.
puma, sidekiqのheap_dumpをとる(gem 'rbtrace'が必要)
#!/bin/bash -e
cd ~/live
sidekiq_pid=`ps aux | grep sidekiq | grep -v grep | awk '{print $2}'`
puma_pid=`ps aux | grep puma | grep -v grep | awk '{print $2}'`
/home/mastodon/.rbenv/shims/bundle exec rbtrace -p $puma_pid --timeout 30 -e 'Thread.new{GC.start;require "objspace";io=File.open("/tmp/puma.dump", "w"); ObjectSpace.dump_all(output: io); io.close}'
/home/mastodon/.rbenv/shims/bundle exec rbtrace -p $sidekiq_pid --timeout 30 -e 'Thread.new{GC.start;require "objspace";io=File.open("/tmp/sidekiq.dump", "w"); ObjectSpace.dump_all(output: io); io.close}'
# ちょっと待つと吉
sleep 5
rm /tmp/dump.tar.gz
tar -zcf /tmp/dump.tar.gz /tmp/puma.dump /tmp/sidekiq.dump
rm /tmp/*.dump
# 吐き出しきれないときのために
sysctl kernel.msgmax=1073741824
sysctl kernel.msgmnb=1073741824
#!/bin/bash
# mastodon-web, mastodon-sidekiq起動後に実行する
cd ~/live
sidekiq_pid=`ps aux | grep sidekiq | grep -v grep | awk '{print $2}'`
puma_pid=`ps aux | grep puma | grep -v grep | awk '{print $2}'`
/home/mastodon/.rbenv/shims/bundle exec rbtrace -p $puma_pid -e 'Thread.new{require "rbtrace"; require "objspace";ObjectSpace.trace_object_allocations_start;}'
/home/mastodon/.rbenv/shims/bundle exec rbtrace -p $sidekiq_pid -e 'Thread.new{require "rbtrace"; require "objspace";ObjectSpace.trace_object_allocations_start;}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment