From 15e2f5565594f263bb7d2a3f14ed0c4cc50c53fe Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 21 Apr 2017 17:31:19 +0800 Subject: [PATCH] Add rake task to gather `GC.stat` for Sidekiq. --- lib/tasks/gc.rake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/gc.rake diff --git a/lib/tasks/gc.rake b/lib/tasks/gc.rake new file mode 100644 index 00000000000..ebc49e35283 --- /dev/null +++ b/lib/tasks/gc.rake @@ -0,0 +1,21 @@ +desc "Returns `GC.stat` for each Sidekiq process in JSON" +task "sidekiq:gc_stat" do + pids = `ps -eo pid,args | grep ' [s]idekiq ' | awk '{print $1}'`.split("\n").map(&:to_i) + results = [] + hostname = `hostname`.chomp + + pids.each do |pid| + tmp_path = Tempfile.new.path + + system( + "bundle exec rbtrace -p #{pid} -e \"o = GC.stat; f = File.open('#{tmp_path}', 'w'); f.write(o.to_json); f.close\"", + out: "/dev/null", err: "/dev/null" + ) + + result = JSON.parse(File.read(tmp_path)) + result["hostname"] = hostname + results << result + end + + puts results.to_json +end