blob: 2d6fc46e11a71c18000b1a20047e75fd735b1e7d [file] [log] [blame]
mblighe1417fa2007-12-10 16:55:13 +00001import time
2
jadmanski8d631c92008-08-18 21:12:40 +00003ssh_hosts = [hosts.create_host(m, initialize=False) for m in machines]
mblighe1417fa2007-12-10 16:55:13 +00004at_hosts = [autotest.Autotest(h) for h in ssh_hosts]
5
6
7def add_profilers(at, profilers, timeout_sync, timeout_start, timeout_stop,
jadmanski0afbb632008-06-06 21:10:57 +00008 machines, name):
9 control_file = []
10 for profiler in profilers:
11 control_file.append("job.profilers.add(%s)"
12 % str(profiler)[1:-1])
mblighe1417fa2007-12-10 16:55:13 +000013
mbligh9e44a452010-04-08 18:20:25 +000014 control_file.append(("job.run_test('profiler_sync', timeout_sync=%d, "
jadmanski09732722008-07-22 14:02:17 +000015 "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)))
mblighe1417fa2007-12-10 16:55:13 +000019
jadmanski0afbb632008-06-06 21:10:57 +000020 for profiler in profilers:
21 control_file.append("job.profilers.delete('%s')" % profiler[0])
mblighe1417fa2007-12-10 16:55:13 +000022
jadmanski0afbb632008-06-06 21:10:57 +000023 params = ["\n".join(control_file), "profile-" + profiler[0], at.host]
24 return subcommand(at.run, params, name)
mblighe1417fa2007-12-10 16:55:13 +000025
26
mblighe74782b2008-01-03 01:58:17 +000027def wait_for_profilers(machines, timeout = 180):
jadmanski0afbb632008-06-06 21:10:57 +000028 # wait until the profilers have started
29 sync_bar = barrier("PROF_MASTER", "sync_profilers",
mblighb65c5b02009-08-03 16:46:50 +000030 timeout, port=11920)
mbligh9c12f772009-06-22 19:03:55 +000031 sync_bar.rendezvous_servers("PROF_MASTER", *machines)
mblighe74782b2008-01-03 01:58:17 +000032
33
34def start_profilers(machines, timeout = 180):
jadmanski0afbb632008-06-06 21:10:57 +000035 # wait until the profilers have started
36 start_bar = barrier("PROF_MASTER", "start_profilers",
mblighb65c5b02009-08-03 16:46:50 +000037 timeout, port=11920)
mbligh9c12f772009-06-22 19:03:55 +000038 start_bar.rendezvous_servers("PROF_MASTER", *machines)
mblighe1417fa2007-12-10 16:55:13 +000039
40
41def stop_profilers(machines, timeout = 120):
mblighb65c5b02009-08-03 16:46:50 +000042 stop_bar = barrier("PROF_MASTER", "stop_profilers", timeout, port=11920)
mbligh9c12f772009-06-22 19:03:55 +000043 stop_bar.rendezvous_servers("PROF_MASTER", *machines)
mblighe1417fa2007-12-10 16:55:13 +000044
45
46def server_sleep_test(seconds):
jadmanski0afbb632008-06-06 21:10:57 +000047 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)
mblighe1417fa2007-12-10 16:55:13 +000053
54
55def main():
jadmanski0afbb632008-06-06 21:10:57 +000056 timeout_sync = 180
57 timeout_start = 60
58 timeout_stop = 60
59 profilers = [["vmstat"], ["iostat"]]
mblighe1417fa2007-12-10 16:55:13 +000060
jadmanski0afbb632008-06-06 21:10:57 +000061 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)
mblighe1417fa2007-12-10 16:55:13 +000067
68
69main()