Last active
December 31, 2015 03:19
-
-
Save robotmay/7927068 to your computer and use it in GitHub Desktop.
A Ruby utility script for use in `git bisect`. Returns a non-0 exit code if memory usage for the process exceeds a specified number.
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
# To run git bisect looking for the first spec suite to exceed 1000MB of RAM: | |
# git bisect run ruby memory_usage.rb 'rake spec' 1000000 | |
require 'open3' | |
command = ARGV[0] | |
threshold = ARGV[1].to_i || 500000 | |
cmd = "/usr/bin/time -v #{command}" | |
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| | |
output = stderr.read.gsub("\t", "") | |
match = /Maximum resident set size \(kbytes\): (.*)/.match(output.strip) | |
memory_usage = match[1].to_i | |
p "Memory usage: #{memory_usage}KB" | |
if memory_usage > threshold | |
Process.exit 1 | |
else | |
Process.exit 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment