Created
July 31, 2016 02:36
-
-
Save igaiga/3f9270950caf079eba0fbd15edb5f232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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