Skip to content

Instantly share code, notes, and snippets.

@janklimo
Created September 29, 2017 07:25
Show Gist options
  • Save janklimo/3bde02c05fae13fc719340c222b774c4 to your computer and use it in GitHub Desktop.
Save janklimo/3bde02c05fae13fc719340c222b774c4 to your computer and use it in GitHub Desktop.
Measure how much memory gets used by a Ruby process
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
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