Skip to content

Instantly share code, notes, and snippets.

@tommeier
Created September 20, 2012 05:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommeier/3754101 to your computer and use it in GitHub Desktop.
Save tommeier/3754101 to your computer and use it in GitHub Desktop.
Rake Timer
require 'rake'
Rake::Task.class_eval do
alias :execute_without_tracing :execute
def execute(*args)
@executed_at = Time.now
execute_without_tracing(*args)
end
alias :invoke_with_call_chain_without_tracing :invoke_with_call_chain
def invoke_with_call_chain(*args)
@invoked_at = Time.now
result = invoke_with_call_chain_without_tracing(*args)
show_timings
result
ensure
@invoked_at = @executed_at = nil
end
def show_timings
return if application.options.dryrun
return unless @executed_at
finished_at = Time.now
execution_time = finished_at - @executed_at
invocation_time = finished_at - @invoked_at
printf("=> Completed task %-40s (in %.2fs total, %.2fs exclusive)\n", name, invocation_time, execution_time)
end
end
require 'rake_timer'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment