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