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