about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--bin/mongrel_rails16
-rw-r--r--lib/mongrel.rb3
-rw-r--r--lib/mongrel/debug.rb155
-rw-r--r--test/test_debug.rb4
4 files changed, 39 insertions, 139 deletions
diff --git a/bin/mongrel_rails b/bin/mongrel_rails
index fc8c447..e622ba2 100644
--- a/bin/mongrel_rails
+++ b/bin/mongrel_rails
@@ -57,18 +57,18 @@ class Start < GemPlugin::Plugin "/commands"
       settings = conf.merge(settings)
     end
     
-    config = Mongrel::Rails::RailsConfigurator.new(settings) do
-      log "Starting Mongrel in #{settings[:environment]} mode at #{settings[:host]}:#{settings[:port]}"
+    config = Mongrel::Rails::RailsConfigurator.new(defaults) do
+      log "Starting Mongrel in #{defaults[:environment]} mode at #{defaults[:host]}:#{defaults[:port]}"
       
       if defaults[:daemon]
-        log "Daemonizing, any open files are closed.  Look at #{settings[:pid_file]} and #{settings[:log_file]} for info."
+        log "Daemonizing, any open files are closed.  Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info."
         daemonize
       end
       
       listener do
         mime = {}
         if defaults[:mime_map]
-          log "Loading additional MIME types from #{settings[:mime_map]}"
+          log "Loading additional MIME types from #{defaults[:mime_map]}"
           mime = load_mime_map(defaults[:mime_map], mime)
         end
         
@@ -77,16 +77,16 @@ class Start < GemPlugin::Plugin "/commands"
           debug "/"
         end
 
-        log "Starting Rails in environment #{settings[:environment]} ..."
+        log "Starting Rails in environment #{defaults[:environment]} ..."
         uri "/", :handler => rails
         log "Rails loaded."
 
         log "Loading any Rails specific GemPlugins"
         load_plugins
 
-        if settings[:config_script]
-          log "Loading #{settings[:config_script]} external config script"
-          run_config(settings[:config_script])
+        if defaults[:config_script]
+          log "Loading #{defaults[:config_script]} external config script"
+          run_config(defaults[:config_script])
         end
 
         setup_rails_signals
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 2c84018..88c1103 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -448,7 +448,8 @@ module Mongrel
       rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL
         # ignored
       rescue HttpParserError
-        STDERR.puts "BAD CLIENT: #$!"        
+        STDERR.puts "BAD CLIENT (#{params["REMOTE_ADDR"]}): #$!"
+        STDERR.puts "REQUEST DATA: #{data}"
       rescue => details
         STDERR.puts "ERROR: #$!"
         STDERR.puts details.backtrace.join("\n")
diff --git a/lib/mongrel/debug.rb b/lib/mongrel/debug.rb
index 5beacff..9e9a811 100644
--- a/lib/mongrel/debug.rb
+++ b/lib/mongrel/debug.rb
@@ -43,7 +43,6 @@ end
 
 module ObjectTracker
   @active_objects = nil
-  @live_object_tracking = true
 
   def ObjectTracker.configure
     @active_objects = Set.new
@@ -53,43 +52,32 @@ module ObjectTracker
     end
   end
 
-
-  def ObjectTracker.start
-    @live_object_tracking = true
-  end
-
-  def ObjectTracker.stop
-    @live_object_tracking = false
-  end
-
   def ObjectTracker.sample
-    Class.stopit do
-      ospace = Set.new
-      counts = {}
-      
-      # Strings can't be tracked easily and are so numerous that they drown out all else
-      # so we just ignore them in the counts.
-      ObjectSpace.each_object do |obj|
-        ospace << obj.object_id
-        counts[obj.class] ||= 0
-        counts[obj.class] += 1
-      end
-      
-      dead_objects = @active_objects - ospace
-      new_objects = ospace - @active_objects
-      live_objects = ospace & @active_objects
-      
-      MongrelDbg::trace(:objects, "COUNTS: #{dead_objects.length},#{new_objects.length},#{live_objects.length}")
-      
-      if MongrelDbg::tracing? :objects
-        top_20 = counts.sort{|a,b| b[1] <=> a[1]}[0..20]
-        MongrelDbg::trace(:objects,"TOP 20: #{top_20.inspect}")
-      end
-      
-      @active_objects = live_objects + new_objects
-
-      [@active_objects, top_20]
+    ospace = Set.new
+    counts = {}
+    
+    # Strings can't be tracked easily and are so numerous that they drown out all else
+    # so we just ignore them in the counts.
+    ObjectSpace.each_object do |obj|
+      ospace << obj.object_id
+      counts[obj.class] ||= 0
+      counts[obj.class] += 1
     end
+    
+    dead_objects = @active_objects - ospace
+    new_objects = ospace - @active_objects
+    live_objects = ospace & @active_objects
+    
+    MongrelDbg::trace(:objects, "COUNTS: #{dead_objects.length},#{new_objects.length},#{live_objects.length}")
+    
+    if MongrelDbg::tracing? :objects
+      top_20 = counts.sort{|a,b| b[1] <=> a[1]}[0..20]
+      MongrelDbg::trace(:objects,"TOP 20: #{top_20.inspect}")
+    end
+    
+    @active_objects = live_objects + new_objects
+    
+    [@active_objects, top_20]
   end
 
 end
@@ -121,101 +109,17 @@ module Kernel
   end
 
   def log_open_files
-    Class.stopit do
-      open_counts = {}
-      $open_files.each do |f,args|
-        open_counts[args] ||= 0
-        open_counts[args] += 1
-      end
-      MongrelDbg::trace(:files, open_counts.to_yaml)
+    open_counts = {}
+    $open_files.each do |f,args|
+      open_counts[args] ||= 0
+      open_counts[args] += 1
     end
+    MongrelDbg::trace(:files, open_counts.to_yaml)
   end
 end  
 
 
 
-class Class
-  alias_method :orig_new, :new
-  
-  @@count = 0
-  @@stopit = false
-  @@class_caller_count = Hash.new{|hash,key| hash[key] = Hash.new(0)}
-  
-  def new(*arg,&blk)
-    unless @@stopit
-      @@stopit = true
-      @@count += 1
-      @@class_caller_count[self][caller.join("\n\t")] += 1
-      @@stopit = false
-    end
-    orig_new(*arg,&blk)
-  end
-
-
-  def Class.report_object_creations(out=$stderr, more_than=20)
-    Class.stopit do
-      out.puts "Number of objects created = #{@@count}"
-      
-      total = Hash.new(0)
-      
-      @@class_caller_count.each_key do |klass|
-        caller_count = @@class_caller_count[klass]
-        caller_count.each_value do |count|
-          total[klass] += count
-        end
-      end
-      
-      klass_list = total.keys.sort{|klass_a, klass_b|
-        a = total[klass_a]
-        b = total[klass_b]
-        if a != b
-          -1* (a <=> b)
-        else
-          klass_a.to_s <=> klass_b.to_s
-        end
-      }
-
-      below_count = 0
-
-      klass_list.each do |klass|
-        below_calls = 0
-        if total[klass] > more_than
-          out.puts "#{total[klass]}\t#{klass} objects created."
-          caller_count = @@class_caller_count[ klass]
-          caller_count.keys.sort_by{|call| -1*caller_count[call]}.each do |call|
-            if caller_count[call] > more_than
-              out.puts "\t** #{caller_count[call]} #{klass} objects AT:"
-              out.puts "\t#{call}\n\n"
-            else
-              below_calls += 1
-            end
-          end
-          out.puts "\t#{below_calls} more objects had calls less that #{more_than} limit.\n\n" if below_calls > 0
-        else
-          below_count += 1
-        end
-      end
-
-      out.puts "\t** #{below_count} More objects were created but the count was below the #{more_than} limit." if below_count > 0
-    end
-  end
-
-  def Class.reset_object_creations
-    Class.stopit do
-      @@count = 0
-      @@class_caller_count = Hash.new{|hash,key| hash[key] = Hash.new(0)}
-    end
-  end
-
-  def Class.stopit
-    @@stopit = true
-    yield
-    @@stopit = false
-  end
-
-end
-
-
 module RequestLog
 
   # Just logs whatever requests it gets to STDERR (which ends up in the mongrel
@@ -264,7 +168,6 @@ end
 
 
 END {
-open("log/mongrel_debug/object_tracking.log", "w") {|f| Class.report_object_creations(f) }
 MongrelDbg::trace(:files, "FILES OPEN AT EXIT")
 log_open_files
 }
diff --git a/test/test_debug.rb b/test/test_debug.rb
index 0bdb673..d94bf9a 100644
--- a/test/test_debug.rb
+++ b/test/test_debug.rb
@@ -24,10 +24,6 @@ class MongrelDbgTest < Test::Unit::TestCase
     assert File.exist?("log/mongrel_debug"), "Didn't make logging directory"
     assert File.exist?("log/mongrel_debug/rails.log"), "Didn't make the rails.log file"
     assert File.size("log/mongrel_debug/rails.log") > 0, "Didn't write anything to the log."
-
-    Class.report_object_creations(out)
-    Class.reset_object_creations
-    Class.report_object_creations(out)
   end
 
 end