Skip to content

Commit

Permalink
fixed bug with bad memoization of total active record instantiation c…
Browse files Browse the repository at this point in the history
…ount; updating docs
  • Loading branch information
noahd1 committed Feb 27, 2009
1 parent 0309be0 commit 5e59d82
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
20 changes: 14 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,26 @@ Currently oink can only parse logs in the Hodel3000Logger format

=== Install

To print memory usage at the end of each request, include MemoryUsageLogger in your controller
To print memory usage at the end of each request, include Oink::MemoryUsageLogger in your controller. This will add lines like:

class ApplicationController
include MemoryUsageLogger
end
class ApplicationController
include Oink::MemoryUsageLogger
end

To print active record instantiation at the end of each request, include ActiveRecordCounter in your controller
which results in lines like this added to each request:

Feb 08 11:39:54 ey33-s00302 rails[9076]: Memory usage: 316516 | PID: 9076

To print active record instantiation at the end of each request, include Oink::InstanceTypeCounter in your controller.

class ApplicationController
include ActiveRecordCounter
include Oink::InstanceTypeCounter
end

which results in lines like this added to each request:

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

After installing the plugin and aggregating some enhanced logs, run the oink executable against the logs. Oink can point at a log file or a directory of log files
Expand Down
4 changes: 0 additions & 4 deletions TODO

This file was deleted.

1 change: 1 addition & 0 deletions lib/oink/rails/instance_type_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def self.included(klass)

def self.reset_instance_type_count
@@instantiated = {}
@@total = nil
end

def self.instantiated_hash
Expand Down
12 changes: 11 additions & 1 deletion spec/rails/instance_type_counter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@
Pen.create(:location => "Backyard")
Pig.first
ActiveRecord::Base.total_objects_instantiated.should == 3
end
end

describe "reset" do
it "should reset the total count" do
Pig.create(:name => "Babe")
ActiveRecord::Base.instantiated_hash["Pig"].should == 1
ActiveRecord::Base.reset_instance_type_count
ActiveRecord::Base.total_objects_instantiated.should == 0
Pig.create(:name => "Babe")
ActiveRecord::Base.total_objects_instantiated.should == 0
end

end

end

0 comments on commit 5e59d82

Please sign in to comment.