Permalink
Browse files

Added elapsed time to remote and local command finished log messages

  • Loading branch information...
1 parent 7c8678d commit 1aa7c8b0807907c76b69c6dcdd59ec2b0ccccae1 @cgriego cgriego committed Jan 11, 2010
Showing with 22 additions and 6 deletions.
  1. +6 −3 lib/capistrano/command.rb
  2. +5 −1 lib/capistrano/recipes/deploy.rb
  3. +11 −2 lib/capistrano/recipes/deploy/strategy/base.rb
View
9 lib/capistrano/command.rb
@@ -1,3 +1,4 @@
+require 'benchmark'
require 'capistrano/errors'
require 'capistrano/processable'
@@ -159,11 +160,13 @@ def initialize(tree, sessions, options={}, &block)
# fails (non-zero return code) on any of the hosts, this will raise a
# Capistrano::CommandError.
def process!
- loop do
- break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
+ elapsed = Benchmark.realtime do
+ loop do
+ break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
+ end
end
- logger.trace "command finished" if logger
+ logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
View
6 lib/capistrano/recipes/deploy.rb
@@ -1,3 +1,4 @@
+require 'benchmark'
require 'yaml'
require 'capistrano/recipes/deploy/scm'
require 'capistrano/recipes/deploy/strategy'
@@ -95,10 +96,13 @@ def with_env(name, value)
# returns the command output as a string
def run_locally(cmd)
logger.trace "executing locally: #{cmd.inspect}" if logger
- output_on_stdout = `#{cmd}`
+ elapsed = Benchmark.realtime do
+ output_on_stdout = `#{cmd}`
+ end
if $?.to_i > 0 # $? is command exit code (posix style)
raise Capistrano::LocalArgumentError, "Command #{cmd} returned status code #{$?}"
end
+ logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
output_on_stdout
end
View
13 lib/capistrano/recipes/deploy/strategy/base.rb
@@ -1,3 +1,4 @@
+require 'benchmark'
require 'capistrano/recipes/deploy/dependencies'
module Capistrano
@@ -49,16 +50,24 @@ def method_missing(sym, *args, &block)
# A wrapper for Kernel#system that logs the command being executed.
def system(*args)
cmd = args.join(' ')
+ result = nil
if RUBY_PLATFORM =~ /win32/
cmd = cmd.split(/\s+/).collect {|w| w.match(/^[\w+]+:\/\//) ? w : w.gsub('/', '\\') }.join(' ') # Split command by spaces, change / by \\ unless element is a some+thing://
cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D
cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D
logger.trace "executing locally: #{cmd}"
- super(cmd)
+ elapsed = Benchmark.realtime do
+ result = super(cmd)
+ end
else
logger.trace "executing locally: #{cmd}"
- super
+ elapsed = Benchmark.realtime do
+ result = super
+ end
end
+
+ logger.trace "command finished in #{(elapsed * 1000).round}ms"
+ result
end
private

0 comments on commit 1aa7c8b

Please sign in to comment.