Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created July 31, 2016 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igaiga/3f9270950caf079eba0fbd15edb5f232 to your computer and use it in GitHub Desktop.
Save igaiga/3f9270950caf079eba0fbd15edb5f232 to your computer and use it in GitHub Desktop.
# https://speakerdeck.com/a_matsuda/3x-rails
# メソッド呼び出し回数の記録
class MethodCounter
def initialize(app)
@app = app
end
def call(env)
calls = []
trace = TracePoint.new(:call, :c_call) do |tp|
calls << [tp.defined_class, tp.method_id, tp.lineno]
end
trace.enable
ret = @app.call env
trace.disable
pp calls.group_by(&:itself).map {|k, v| {k => v.length}}.sort_by {|h| -h.values.first}
ret
end
end
use MethodCounter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment