Created
September 20, 2012 05:25
-
-
Save tommeier/3754101 to your computer and use it in GitHub Desktop.
Rake Timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake_timer' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment