MiniProfilerをRubyに移植しており、Railsビューとパーシャルの自動計測を追加したかったのです。なぜこのメソッドは、ActionView :: Template:render?
私はexisting instrumentationのサポートについて認識していますが、理想的には「開始」と「停止」イベントを取得したいと考えています。通知をサポートしていない以前のバージョンのRailsもサポートしたいと考えています。
私は短いインスツルメンタをハッキングし、呼び出し後前とでレンダリングフックテスト:
def prof(klass, method)
with_profiling = (method.to_s + "_with_profiling").intern
without_profiling = (method.to_s + "_without_profiling").intern
klass.send :alias_method, without_profiling, method
klass.send :define_method, with_profiling do |*args, &orig|
puts "before #{method} #{args}"
self.send without_profiling, *args, &orig
puts "after #{method}"
end
klass.send :alias_method, method, with_profiling
end
prof ActionView::Template, :render
しかし、これが起動したら、render
が正しく計測されません。特に、これは、パーシャルの一部に動作しますが、と爆発:これと間違っている何
:
ActionView ::テンプレート::エラー(NilClass nilのための未定義のメソッド `html_safe」)メソッドフック?あなたは通常
nil
であるあなたの最終puts
の結果を返すメソッドを再定義しました
'(method.to_s + "_with_profiling")を有利にする何らかの理由'オーバーintern': "#{方法} _with_profiling" '? – tadman
本当に、私はそれをきれいにするでしょう –