-
-
Save mkreyman/a9df6068e46ec4b9d9744af77f1c51d2 to your computer and use it in GitHub Desktop.
ruby-prof: Add profiling to your rake tasks.
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
| group :development do | |
| gem "ruby-prof" | |
| 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
| if ENV["TIMESTAMPS"] | |
| module Rake | |
| class Task | |
| def execute_with_timestamps(*args) | |
| start = Time.now | |
| execute_without_timestamps(*args) | |
| execution_time_in_seconds = Time.now - start | |
| puts | |
| printf("%s took %.1f seconds\n", name, execution_time_in_seconds) | |
| end | |
| alias_method :execute_without_timestamps, :execute | |
| alias_method :execute, :execute_with_timestamps | |
| end | |
| end | |
| end | |
| if ENV["PROFILE"] | |
| require "ruby-prof" | |
| module Rake | |
| class Task | |
| def execute_with_profile(*args) | |
| RubyProf.start | |
| execute_without_profile(*args) | |
| result = RubyProf.stop | |
| printer = RubyProf::CallStackPrinter.new(result) | |
| printer.print STDOUT, {} | |
| end | |
| alias_method :execute_without_profile, :execute | |
| alias_method :execute, :execute_with_profile | |
| end | |
| 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
| TIMESTAMPS=true rake mytask | |
| PROFILE=true rake mytask > /path/to/profile.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment