Rails で特定のエンドポイントにプロファイラを仕掛けたいときに、どのようにコードを埋め込めば良いか、書いておきます。
stackprof
class FooController < ApplicationController
around_action :stackprofile
def index
end
:
private
def stackprofile(&action)
profile_dump = Rails.root.join('tmp', "stackprof-cpu-#{$$}.#{Time.current.to_i}.dump")
StackProf.run(mode: :cpu, out: profile_dump, &action)
end
end
参考:
memprof2
class FooController < ApplicationController
require 'memprof2' # Do not require by default
around_action :memprof2
def index
end
:
private
def memprof2
Memprof2.run do
begin
yield
ensure
Memprof2.report(out: Rails.root.join('tmp', "memprof-report.#{$$}.#{Time.current.to_i}.txt")
end
end
end
end
参考: