Skip to content

Instantly share code, notes, and snippets.

@brixen
Created July 20, 2009 19:31
Show Gist options
  • Save brixen/150726 to your computer and use it in GitHub Desktop.
Save brixen/150726 to your computer and use it in GitHub Desktop.
# This script provides a place to insert a potentially platform-specific
# method of monitoring a benchmark and possibly aborting the run if it
# exceeds a specified time limit. See README for more details.
def write_status(name, report, status)
File.open report, "a" do |f|
f.puts "---"
f.puts "name: #{name}"
f.puts "status: #{status}"
end
end
limit, vm, runner, name, iterations, report = ARGV
finish = Time.now.to_i + limit.to_i
if pid = Kernel.fork
STDERR.puts "pid: #{pid}"
loop do
Process.waitpid pid, Process::WNOHANG
if status = $?
if status.success?
write_status name, report, "success"
exit 0
end
write_status name, report, "Exited with status #{status.exitstatus}"
exit 1
end
if Time.now.to_i > finish
write_status name, report, "Timeout"
Process.kill :TERM, pid
Process.waitpid pid, Process::WNOHANG
sleep 2
Process.kill :KILL, pid
Process.waitpid pid
exit 1
end
sleep 1
end
else
cmd = "#{vm} #{runner} #{name} #{iterations} #{report} > /dev/null"
system cmd
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment