tyler.kovacs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26  01:38 UTC
custom benchmarking - problems monkey patching perform_action_with_benchmark
I would like to override
ActionController::Benchmarking.perform_action_with_benchmark method so
that custom application-layer information is logged alongside render
and DB times in the production.log.  I''ve tried monkey-patching, but
for some reason, it doesn''t seem to work.   I can define new methods in
the ActionController::Benchmarking, but if I override
perform_action_with_benchmark my changes are ignored.
Here''s what I''ve got in
vendor/plugins/benchmark_enhancements/lib/benchmark_enhancements.rb:
module ActionController #:nodoc:
  module Benchmarking #:nodoc:
    def perform_action_with_benchmark
      unless logger
        perform_action_without_benchmark
      else
        runtime = [Benchmark::measure{ perform_action_without_benchmark
}.real, 0.0001].max
        log_message  = "Completed in #{sprintf("%.5f", runtime)}
(#{(1
/ runtime).floor} reqs/sec)"
        log_message << rendering_runtime(runtime) if @rendering_runtime
        log_message << active_record_runtime(runtime) if
Object.const_defined?("ActiveRecord") &&
ActiveRecord::Base.connected?
        log_message << custom_runtime(runtime)
        log_message << " | #{headers["Status"]}"
        log_message << " [#{complete_request_uri rescue
"unknown"}]"
        logger.info(log_message)
      end
    end
    def custom_runtime(runtime)
      " | Custom: #{sprintf("%.5f", rand)}"
    end
  end
end
I can verify that custom_runtime exists, so the file is being read, but
it never gets invoked.  It works if I edit the gem version of
benchmark.rb, but it doesn''t work if I monkey patch under
vendor/plugins.
Any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---