Created
September 29, 2017 07:25
-
-
Save janklimo/3bde02c05fae13fc719340c222b774c4 to your computer and use it in GitHub Desktop.
Measure how much memory gets used by a Ruby process
This file contains 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
def print_memory_usage | |
memory_before = `ps -o rss= -p #{Process.pid}`.to_i | |
yield | |
memory_after = `ps -o rss= -p #{Process.pid}`.to_i | |
puts "Memory: #{((memory_after - memory_before) / 1024.0).round(2)} MB" | |
end |
This file contains 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
task something_complex: :environment do | |
print_memory_usage do | |
client = Client.new | |
client.run | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment