noahd1 / oink

Log parser to identify actions which significantly increase VM heap size
MIT License
1.18k stars 71 forks source link

Not getting "Oink Action" lines in the log #11

Closed yar closed 13 years ago

yar commented 13 years ago

Hi

I am trying to use Oink 0.9.2 and hodel_3000_compliant_logger 0.1.0, as gems, under rails 2.3.11.

In environment.rb:

Rails::Initializer.run do |config| require 'hodel_3000_compliant_logger' config.logger = h3_log = Hodel3000CompliantLogger.new(config.log_path) config.middleware.use "Oink::Middleware", :logger => h3_log ... end

This is what I am getting in log/development.log:

Jul 08 17:09:09 yarmac rails[29643]: Completed in 582ms (View: 194, DB: 21) | 200 OK [http://weather.local/] Jul 08 17:09:09 yarmac rails[29643]: Memory usage: 2561680 | PID: 29643 Jul 08 17:09:09 yarmac rails[29643]: Instantiation Breakdown: Total: 14 | Photo: 6 | Location: 5 | Weatherfinder: 1 | Forecast: 1 | Language: 1 Jul 08 17:09:09 yarmac rails[29643]: Oink Log Entry Complete

No "Oink Action" line!

If I then run

% oink --threshold=0 log/development.log

---- MEMORY THRESHOLD ---- THRESHOLD: 0 MB

-- SUMMARY -- Worst Requests:

  1. Jul 08 17:09:09, 15360 KB,
  2. Jul 08 17:02:54, 2052 KB,
  3. Jul 08 17:02:50, 2052 KB,
  4. Jul 08 17:02:50, 2052 KB,
  5. Jul 08 17:02:51, 2052 KB,
  6. Jul 08 17:02:50, 2052 KB,
  7. Jul 08 17:02:52, 2052 KB,
  8. Jul 08 17:02:52, 2052 KB,
  9. Jul 08 17:02:53, 2052 KB,
  10. Jul 08 17:02:49, 2052 KB,

Worst Actions: 44, %

– the result is missing the action list as well.

Is Rails 2.3.11 still supported?

noahd1 commented 13 years ago

I believe it's a bug if it's not working on 2.3.x. The culprit is here, which checks the environment for a key named "action_dispatch.request.parameters", which I guess did not exist in 2.3.x.

If you happen to know a better environment variable to check for, preferably one that works on both 2.3.x and 3.x I can patch that.

yar commented 13 years ago

Here you go:

diff --git a/lib/oink/middleware.rb b/lib/oink/middleware.rb
index f69c015..81346f7 100644
--- a/lib/oink/middleware.rb
+++ b/lib/oink/middleware.rb
@@ -28,9 +28,9 @@ module Oink
     end

     def log_routing(env)
-      if env.has_key?('action_dispatch.request.parameters')
-        controller = env['action_dispatch.request.parameters']['controller']
-        action     = env['action_dispatch.request.parameters']['action']
+      if env.has_key?(key = 'action_dispatch.request.parameters') || env.has_key?(key = 'action_controller.request.path_parameters')
+        controller = env[key]['controller']
+        action     = env[key]['action']
         @logger.info("Oink Action: #{controller}##{action}")
       end
     end
yar commented 13 years ago

(I deleted and resubmitted the comment because one of the lines was truncated.)

noahd1 commented 13 years ago

Thanks for noting the issue and for the patch.

yar commented 13 years ago

Great! Kudos for the expressive self-documenting syntax.