Skip to content
Browse files

Refactored to be usuable as a gem, and updated documentation.

  • Loading branch information...
1 parent fd7fac3 commit 86e27bcaf69e15d7a4c7cb41e8e7ba674db8ca52 @technicalpickles technicalpickles committed Jul 6, 2010
Showing with 40 additions and 17 deletions.
  1. +32 −14 README.rdoc
  2. +1 −2 init.rb
  3. +5 −1 lib/oink.rb
  4. +2 −0 lib/oink/rails.rb
View
46 README.rdoc
@@ -22,33 +22,51 @@ Many thanks to Ben Johnson for Memory Usage Logger (http://github.com/binarylogi
Currently oink can only parse logs in the Hodel3000Logger format
-- http://github.com/topfunky/hodel_3000_compliant_logger/tree/master
+- http://github.com/topfunky/hodel_3000_compliant_logger
-=== Install
+When used as a gem, this is automatically brought in as a dependency.
-To print memory usage at the end of each request, include Oink::MemoryUsageLogger in your controller. This will add lines like:
+=== Installation and configuration
-class ApplicationController
- include Oink::MemoryUsageLogger
-end
+To begin, you'll want to install it:
-which results in lines like this added to each request:
+ gem install oink
+
+Next, you'll need to update your config/environment.rb to include oink as a dependency, and to configure Rails to use the hodel_3000_compliant_logger:
+
+ Rails::Initializer.run do |config|
+ # your other config here
+ config.gem 'oink'
+ begin
+ require 'hodel_3000_compliant_logger'
+ config.logger = Hodel3000CompliantLogger.new(config.log_path)
+ rescue LoadError => e
+ $stderr.puts "Hodel3000CompliantLogger unavailable, oink will be disabled"
+ end
+ end
+
+
+Oink allows you to add two type of statistics to your log output: memory usage and number of ActiveRecord objects instantiated. Here's an example for the output you can get:
Feb 08 11:39:54 ey33-s00302 rails[9076]: Memory usage: 316516 | PID: 9076
+ Feb 27 13:21:04 ey04-s00295 rails[11862]: Instantiation Breakdown: Total: 73 | User: 34 | Group: 20 | Medium: 20 | Sport: 10 | Post: 4 | Discussion: 2
-To print active record instantiation at the end of each request, include Oink::InstanceTypeCounter in your controller.
+For memory usage, add this to app/controllers/application_controller.rb:
class ApplicationController
- include Oink::InstanceTypeCounter
+ include Oink::MemoryUsageLogger
end
-which results in lines like this added to each request:
+For ActiveRecord objects instantiated, add this to your app/controllers/application_controller.rb:
+
+ class ApplicationController
+ include Oink::InstanceTypeCounter
+ end
- Feb 27 13:21:04 ey04-s00295 rails[11862]: Instantiation Breakdown: Total: 73 | User: 34 | Group: 20 | Medium: 20 | Sport: 10 | Post: 4 | Discussion: 2
-== Usage
+== Analyizing logs
-After installing the plugin and aggregating some enhanced logs, run the oink executable against the logs. This will typically be installed as script/oink. Oink can point at a log file or a directory of log files
+After installing the plugin and aggregating some enhanced logs, run the 'oink' executable against your server logs.
Usage: oink [options] files
-t, --threshold [INTEGER] Memory threshold in MB
@@ -115,4 +133,4 @@ Verbose format prints the summary as well as each action which exceeded the thre
=== Authors
- Maintained by Noah Davis
-- Thanks to Weplay (http://weplay.com) for sponsoring development and supporting open sourcing it from the start
+- Thanks to Weplay (http://weplay.com) for sponsoring development and supporting open sourcing it from the start
View
3 init.rb
@@ -1,2 +1 @@
-require "oink/rails/memory_usage_logger"
-require "oink/rails/instance_type_counter"
+require "oink/rails"
View
6 lib/oink.rb
@@ -2,4 +2,8 @@
require "oink/memory_usage_reporter"
require "oink/active_record_instantiation_reporter"
-require "oink/cli"
+require "oink/cli"
+
+if defined?(Rails)
+ require 'oink/rails'
+end
View
2 lib/oink/rails.rb
@@ -0,0 +1,2 @@
+require "oink/rails/memory_usage_logger"
+require "oink/rails/instance_type_counter"

0 comments on commit 86e27bc

Please sign in to comment.
Something went wrong with that request. Please try again.