mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 1 | import time |
| 2 | |
| 3 | ssh_hosts = [hosts.SSHHost(m, initialize=False) for m in machines] |
| 4 | at_hosts = [autotest.Autotest(h) for h in ssh_hosts] |
| 5 | |
| 6 | |
| 7 | def add_profilers(at, profilers, timeout_sync, timeout_start, timeout_stop, |
| 8 | machines, name): |
| 9 | control_file = [] |
| 10 | for profiler in profilers: |
| 11 | control_file.append("job.profilers.add(%s)" |
| 12 | % str(profiler)[1:-1]) |
| 13 | |
| 14 | control_file.append("job.run_test('barriertest',%d,%d,%d,'%s','%s',%s)" |
| 15 | % (timeout_sync, timeout_start, timeout_stop, |
| 16 | at.host.hostname, "PROF_MASTER", str(machines))) |
| 17 | |
| 18 | for profiler in profilers: |
| 19 | control_file.append("job.profilers.delete('%s')" % profiler[0]) |
| 20 | |
| 21 | params = ["\n".join(control_file), "profile-" + profiler[0], at.host] |
| 22 | return subcommand(at.run, params, name) |
| 23 | |
| 24 | |
mbligh | e74782b | 2008-01-03 01:58:17 +0000 | [diff] [blame] | 25 | def wait_for_profilers(machines, timeout = 180): |
| 26 | # wait until the profilers have started |
| 27 | sync_bar = barrier("PROF_MASTER", "sync_profilers", |
| 28 | timeout, port=63100) |
| 29 | sync_bar.rendevous_servers("PROF_MASTER", *machines) |
| 30 | |
| 31 | |
| 32 | def start_profilers(machines, timeout = 180): |
mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 33 | # wait until the profilers have started |
mbligh | 6b504ff | 2007-12-12 21:03:49 +0000 | [diff] [blame] | 34 | start_bar = barrier("PROF_MASTER", "start_profilers", |
| 35 | timeout, port=63100) |
mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 36 | start_bar.rendevous_servers("PROF_MASTER", *machines) |
| 37 | |
| 38 | |
| 39 | def stop_profilers(machines, timeout = 120): |
mbligh | 6b504ff | 2007-12-12 21:03:49 +0000 | [diff] [blame] | 40 | stop_bar = barrier("PROF_MASTER", "stop_profilers", timeout, port=63100) |
mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 41 | stop_bar.rendevous_servers("PROF_MASTER", *machines) |
| 42 | |
| 43 | |
| 44 | def server_sleep_test(seconds): |
| 45 | wait_for_profilers(machines) |
mbligh | e74782b | 2008-01-03 01:58:17 +0000 | [diff] [blame] | 46 | start_profilers(machines) |
mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 47 | for i in range(seconds): |
| 48 | print "%d of %d" % (i, seconds) |
| 49 | time.sleep(1) |
| 50 | stop_profilers(machines) |
| 51 | |
| 52 | |
| 53 | def main(): |
mbligh | e74782b | 2008-01-03 01:58:17 +0000 | [diff] [blame] | 54 | timeout_sync = 180 |
mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 55 | timeout_start = 60 |
| 56 | timeout_stop = 60 |
| 57 | profilers = [["vmstat"], ["iostat"]] |
| 58 | |
| 59 | tests = [subcommand(server_sleep_test, [20], "server_sleep_test")] |
| 60 | for at in at_hosts: |
| 61 | name = "profiled-%s" % at.host.hostname |
| 62 | tests.append(add_profilers(at, profilers, timeout_sync, |
| 63 | timeout_start, timeout_stop, machines, name)) |
| 64 | parallel(tests) |
| 65 | |
| 66 | |
| 67 | main() |