Created
July 20, 2009 19:31
-
-
Save brixen/150726 to your computer and use it in GitHub Desktop.
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
| # 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