Created
February 28, 2014 09:50
Revisions
-
knightq created this gist
Feb 28, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ # 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