Created
February 28, 2014 09:50
Profile utils
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
# Usage: | |
# profile_memory do | |
# # your_code_to_be_profiled_here... | |
# end | |
module ProfileUtils | |
def get_current_memory_usage | |
`ps -o rss= -p #{Process.pid}`.to_i | |
end | |
def profile_memory(&block) | |
before = get_current_memory_usage | |
file, line, _ = caller[0].split(':') | |
if block_given? | |
instance_eval(&block) | |
puts "[#{file}:#{line}: #{(get_current_memory_usage - before) / 1024} MB (consumed)]" | |
else | |
before = 0 | |
puts "[#{file}:#{line}: #{(get_current_memory_usage - before) / 1024} MB (all)]" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment