Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for an averaged output

  • Loading branch information...
commit 8ec9a5cff32dff6939b31c5827cf31e9b2cbc6f9 1 parent 9bd33ec
@bjpirt bjpirt authored
View
10 README.rdoc
@@ -115,6 +115,16 @@ e.g. To find all actions which increase the heap size more than 75 MB, where log
1, PublicPagesController#join
1, CommentsController#create
+ Aggregated Totals:
+ Action Max Mean Min Total Number of requests
+ SportsController#show 101560 19754 4 5590540 283
+ CommentsController#create 8344 701 4 253324 361
+ ColorSchemesController#show 10124 739 4 68756 93
+ PublicPagesController#join 9004 1346 8 51172 38
+ DashboardsController#show 13696 2047 8 45036 22
+ SessionsController#create 9220 528 8 17448 33
+ GroupsController#show 10748 1314 8 15776 12
+
e.g. In verbose mode, oink will print out all the log information from your logs about the actions which exceeded the threshold specified
$ oink --format verbose --threshold=75 /tmp/logs/*
View
20 lib/oink/reports/base.rb
@@ -13,6 +13,7 @@ def initialize(input, threshold, options = {})
@pids = {}
@bad_actions = {}
+ @bad_actions_averaged = {}
@bad_requests = PriorityQueue.new(10)
end
@@ -32,6 +33,25 @@ def print_summary(output)
@bad_actions.sort{|a,b| b[1]<=>a[1]}.each { |elem|
output.puts "#{elem[1]}, #{elem[0]}"
}
+ output.puts "\nAggregated Totals:\n"
+ if @bad_actions_averaged.length > 0
+ action_stats = @bad_actions_averaged.map { |action,values|
+ total = values.inject(0){ |sum,x| sum+x }
+ {
+ :action => action,
+ :total => total,
+ :mean => total/values.length,
+ :max => values.max,
+ :min => values.min,
+ :count => values.length,
+ }
+ }
+ action_width = @bad_actions_averaged.keys.map{|k| k.length}.max
+ output.puts "#{'Action'.ljust(action_width)}\tMax\tMean\tMin\tTotal\tNumber of requests"
+ action_stats.sort{|a,b| b[:total]<=>a[:total]}.each do |action_stat|
+ output.puts "#{action_stat[:action].ljust(action_width)}\t#{action_stat[:max]}\t#{action_stat[:mean]}\t#{action_stat[:min]}\t#{action_stat[:total]}\t#{action_stat[:count]}"
+ end
+ end
end
end
end
View
4 lib/oink/reports/memory_usage_report.rb
@@ -52,6 +52,8 @@ def print(output)
@pids[pid][:buffer].each { |b| output.puts b }
output.puts "---------------------------------------------------------------------"
end
+ @bad_actions_averaged[@pids[pid][:action]] ||= []
+ @bad_actions_averaged[@pids[pid][:action]] << memory_diff
end
end
@@ -68,4 +70,4 @@ def print(output)
end
end
end
-end
+end
View
6 spec/oink/reports/active_record_instantiation_report_spec.rb
@@ -63,8 +63,8 @@ module Oink::Reports
io = StringIO.new(str)
output = PsuedoOutput.new
ActiveRecordInstantiationReport.new(io, 50).print(output)
- output[-2].should == "2, Media#show"
- output[-1].should == "1, Users#show"
+ output[8].should == "2, Media#show"
+ output[9].should == "1, Users#show"
end
it "should not be bothered by incomplete requests" do
@@ -190,4 +190,4 @@ module Oink::Reports
end
-end
+end
View
74 spec/oink/reports/memory_usage_report_spec.rb
@@ -79,8 +79,8 @@ module Oink::Reports
io = StringIO.new(str)
output = PsuedoOutput.new
MemoryUsageReport.new(io, TEN_MEGS).print(output)
- output[-2].should == "2, Media#show"
- output[-1].should == "1, Users#show"
+ output[8].should == "2, Media#show"
+ output[9].should == "1, Users#show"
end
it "should not report actions which do not complete properly" do
@@ -233,6 +233,74 @@ module Oink::Reports
end
end
+ describe "averaged format" do
+ it "should correctly calculate the stats for the actions" do
+ str = <<-STR
+ Feb 01 01:59:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
+ Feb 01 01:57:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"2332", "controller"=>"users"}
+ Feb 01 01:57:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 10} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 01:57:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ Feb 01 01:59:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"22900", "controller"=>"media"}
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS*3) + 40} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ Feb 01 01:59:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
+ Feb 01 01:59:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"22900", "controller"=>"media"}
+ Feb 01 01:59:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS*8) + 40} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 01:59:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ STR
+ io = StringIO.new(str)
+ output = PsuedoOutput.new
+ MemoryUsageReport.new(io, TEN_MEGS, :format => :averaged).print(output)
+ output.last.should == "Users#show\t51200\t35855\t20510\t71710\t2"
+ end
+ it "should sort by the total memory increase" do
+ str = <<-STR
+ Feb 01 01:57:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
+ Feb 01 01:57:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"2332", "controller"=>"users"}
+ Feb 01 01:57:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 10} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 01:57:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ Feb 01 01:57:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
+ Feb 01 01:57:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"2332", "controller"=>"users"}
+ Feb 01 01:57:30 ey04-s00297 rails[4413]: Memory usage: #{2*(TEN_MEGS + 10)} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 01:57:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"22900", "controller"=>"media"}
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{3*(TEN_MEGS + 10)} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ Feb 01 02:57:29 ey04-s00297 rails[4413]: Processing Users2#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users2#show
+ Feb 01 02:57:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"2332", "controller"=>"users"}
+ Feb 01 02:57:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 20} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 02:57:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ Feb 01 02:58:29 ey04-s00297 rails[4413]: Processing Users2#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
+ Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users2#show
+ Feb 01 02:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"22900", "controller"=>"media"}
+ Feb 01 02:58:30 ey04-s00297 rails[4413]: Memory usage: #{2*(TEN_MEGS + 20)} | PID: 4413
+ Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
+ Feb 01 02:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
+ STR
+ io = StringIO.new(str)
+ output = PsuedoOutput.new
+ MemoryUsageReport.new(io, TEN_MEGS, :format => :averaged).print(output)
+ output[12].should include('Users#show')
+ output[13].should include('Users2#show')
+ end
+ end
+
describe "multiple io streams" do
it "should accept multiple files" do
@@ -264,4 +332,4 @@ module Oink::Reports
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.