about summary refs log tree commit homepage
path: root/lib/mongrel
diff options
context:
space:
mode:
authorzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-09-22 08:16:54 +0000
committerzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-09-22 08:16:54 +0000
commite1d423ab4d835b8eea4e42444cc189bcdf79ec95 (patch)
treeaaf05aed8a91fe5b6a3bb23b00e03c97bd281bcd /lib/mongrel
parent5f0c661e6a08793180e9b4414da4b197b33b0c78 (diff)
downloadunicorn-e1d423ab4d835b8eea4e42444cc189bcdf79ec95.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@349 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib/mongrel')
-rw-r--r--lib/mongrel/command.rb10
-rw-r--r--lib/mongrel/configurator.rb10
-rw-r--r--lib/mongrel/debug.rb2
-rw-r--r--lib/mongrel/handlers.rb10
-rw-r--r--lib/mongrel/rails.rb4
-rw-r--r--lib/mongrel/stats.rb118
6 files changed, 83 insertions, 71 deletions
diff --git a/lib/mongrel/command.rb b/lib/mongrel/command.rb
index 7790b64..8f65426 100644
--- a/lib/mongrel/command.rb
+++ b/lib/mongrel/command.rb
@@ -157,6 +157,10 @@ module Mongrel
         puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n"
 
         self.commands.each do |name|
+          if /mongrel::/ =~ name
+            name = name[9 .. -1]
+          end
+
           puts " - #{name[1 .. -1]}\n"
         end
 
@@ -179,8 +183,12 @@ module Mongrel
           return true
         end
 
-        # command exists, set it up and validate it
         begin
+          # quick hack so that existing commands will keep working but the Mongrel:: ones can be moved
+          if ["start", "stop", "restart"].include? cmd_name
+            cmd_name = "mongrel::" + cmd_name
+          end
+
           command = GemPlugin::Manager.instance.create("/commands/#{cmd_name}", :argv => args)
         rescue OptionParser::InvalidOption
           STDERR.puts "#$! for command '#{cmd_name}'"
diff --git a/lib/mongrel/configurator.rb b/lib/mongrel/configurator.rb
index 5120ede..dd21e65 100644
--- a/lib/mongrel/configurator.rb
+++ b/lib/mongrel/configurator.rb
@@ -302,17 +302,17 @@ module Mongrel
     #   debug "/", what = [:rails]
     #
     # And it will only produce the log/mongrel_debug/rails.log file.
-    # Available options are:  :objects, :rails, :files, :threads, :params
+    # Available options are: :access, :files, :objects, :threads, :rails
     #
     # NOTE: Use [:files] to get accesses dumped to stderr like with WEBrick.
-    def debug(location, what = [:objects, :rails, :files, :threads, :params])
+    def debug(location, what = [:access, :files, :objects, :threads, :rails])
       require 'mongrel/debug'
       handlers = {
-        :files => "/handlers/requestlog::access",
-        :rails => "/handlers/requestlog::files",
+        :access => "/handlers/requestlog::access",
+        :files => "/handlers/requestlog::files",
         :objects => "/handlers/requestlog::objects",
         :threads => "/handlers/requestlog::threads",
-        :params => "/handlers/requestlog::params"
+        :rails => "/handlers/requestlog::params"
       }
 
       # turn on the debugging infrastructure, and ObjectTracker is a pig
diff --git a/lib/mongrel/debug.rb b/lib/mongrel/debug.rb
index 64a1a16..572696e 100644
--- a/lib/mongrel/debug.rb
+++ b/lib/mongrel/debug.rb
@@ -129,7 +129,7 @@ module RequestLog
           begin
             if o.respond_to? :length
               len = o.length
-              lengths[o.class] ||= Stats.new(o.class)
+              lengths[o.class] ||= Mongrel::Stats.new(o.class)
               lengths[o.class].sample(len)
             end
           rescue Object
diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb
index 4d36e8b..b0a399b 100644
--- a/lib/mongrel/handlers.rb
+++ b/lib/mongrel/handlers.rb
@@ -324,11 +324,11 @@ module Mongrel
     def initialize(ops={})
       @sample_rate = ops[:sample_rate] || 300
 
-      @processors = Stats.new("processors")
-      @reqsize = Stats.new("request Kb")
-      @headcount = Stats.new("req param count")
-      @respsize = Stats.new("response Kb")
-      @interreq = Stats.new("inter-request time")
+      @processors = Mongrel::Stats.new("processors")
+      @reqsize = Mongrel::Stats.new("request Kb")
+      @headcount = Mongrel::Stats.new("req param count")
+      @respsize = Mongrel::Stats.new("response Kb")
+      @interreq = Mongrel::Stats.new("inter-request time")
     end
 
 
diff --git a/lib/mongrel/rails.rb b/lib/mongrel/rails.rb
index ca430d5..e351cec 100644
--- a/lib/mongrel/rails.rb
+++ b/lib/mongrel/rails.rb
@@ -78,10 +78,12 @@ module Mongrel
             # we don't want the output to be really final until we're out of the lock
             cgi.default_really_final = false
 
-            log_threads_waiting_for(request.params["PATH_INFO"]) if $mongrel_debug_client
+            log_threads_waiting_for(request.params["PATH_INFO"] || @active_request_path) if $mongrel_debug_client
 
             @guard.synchronize(:EX) {
+              @active_request_path = request.params["PATH_INFO"]
               Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
+              @active_request_path = nil
             }
 
             # This finalizes the output using the proper HttpResponse way
diff --git a/lib/mongrel/stats.rb b/lib/mongrel/stats.rb
index eec6ff9..f6cf5ab 100644
--- a/lib/mongrel/stats.rb
+++ b/lib/mongrel/stats.rb
@@ -12,76 +12,78 @@
 #
 # It does all of this very fast and doesn't take up any memory since the samples
 # are not stored but instead all the values are calculated on the fly.
-class Stats
-  attr_reader :sum, :sumsq, :n, :min, :max
+module Mongrel
+  class Stats
+    attr_reader :sum, :sumsq, :n, :min, :max
 
-  def initialize(name)
-    @name = name
-    reset
-  end
+    def initialize(name)
+      @name = name
+      reset
+    end
 
-  # Resets the internal counters so you can start sampling again.
-  def reset
-    @sum = 0.0
-    @sumsq = 0.0
-    @last_time = Time.new
-    @n = 0.0
-    @min = 0.0
-    @max = 0.0
-  end
+    # Resets the internal counters so you can start sampling again.
+    def reset
+      @sum = 0.0
+      @sumsq = 0.0
+      @last_time = Time.new
+      @n = 0.0
+      @min = 0.0
+      @max = 0.0
+    end
 
-  # Adds a sampling to the calculations.
-  def sample(s)
-    @sum += s
-    @sumsq += s * s
-    if @n == 0
-      @min = @max = s
-    else
-      @min = s if @min > s
-      @max = s if @max < s
+    # Adds a sampling to the calculations.
+    def sample(s)
+      @sum += s
+      @sumsq += s * s
+      if @n == 0
+        @min = @max = s
+      else
+        @min = s if @min > s
+        @max = s if @max < s
+      end
+      @n+=1
     end
-    @n+=1
-  end
 
-  # Dump this Stats object with an optional additional message.
-  def dump(msg = "", out=STDERR)
-    out.puts "#{msg}: #{self.to_s}"
-  end
+    # Dump this Stats object with an optional additional message.
+    def dump(msg = "", out=STDERR)
+      out.puts "#{msg}: #{self.to_s}"
+    end
 
-  # Returns a common display (used by dump)
-  def to_s  
+    # Returns a common display (used by dump)
+    def to_s  
     "[#{@name}]: SUM=%0.4f, SUMSQ=%0.4f, N=%0.4f, MEAN=%0.4f, SD=%0.4f, MIN=%0.4f, MAX=%0.4f" % [@sum, @sumsq, @n, mean, sd, @min, @max]
-  end
+    end
 
 
-  # Calculates and returns the mean for the data passed so far.
-  def mean
-    @sum / @n
-  end
+    # Calculates and returns the mean for the data passed so far.
+    def mean
+      @sum / @n
+    end
 
-  # Calculates the standard deviation of the data so far.
-  def sd
-    # (sqrt( ((s).sumsq - ( (s).sum * (s).sum / (s).n)) / ((s).n-1) ))
-    begin
-      return Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) )
-    rescue Errno::EDOM
-      return 0.0
+    # Calculates the standard deviation of the data so far.
+    def sd
+      # (sqrt( ((s).sumsq - ( (s).sum * (s).sum / (s).n)) / ((s).n-1) ))
+      begin
+        return Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) )
+      rescue Errno::EDOM
+        return 0.0
+      end
     end
-  end
 
 
-  # Adds a time delta between now and the last time you called this.  This
-  # will give you the average time between two activities.
-  #
-  # An example is:
-  #
-  #  t = Stats.new("do_stuff")
-  #  10000.times { do_stuff(); t.tick }
-  #  t.dump("time")
-  #
-  def tick
-    now = Time.now
-    sample(now - @last_time)
-    @last_time = now
+    # Adds a time delta between now and the last time you called this.  This
+    # will give you the average time between two activities.
+    #
+    # An example is:
+    #
+    #  t = Stats.new("do_stuff")
+    #  10000.times { do_stuff(); t.tick }
+    #  t.dump("time")
+    #
+    def tick
+      now = Time.now
+      sample(now - @last_time)
+      @last_time = now
+    end
   end
 end