• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import time
2
3ssh_hosts = [hosts.create_host(m, initialize=False) for m in machines]
4at_hosts = [autotest.Autotest(h) for h in ssh_hosts]
5
6
7def 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('profiler_sync', timeout_sync=%d, "
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)))
19
20    for profiler in profilers:
21        control_file.append("job.profilers.delete('%s')" % profiler[0])
22
23    params = ["\n".join(control_file), "profile-" + profiler[0], at.host]
24    return subcommand(at.run, params, name)
25
26
27def wait_for_profilers(machines, timeout = 180):
28    # wait until the profilers have started
29    sync_bar = barrier("PROF_MASTER", "sync_profilers",
30            timeout, port=11920)
31    sync_bar.rendezvous_servers("PROF_MASTER", *machines)
32
33
34def start_profilers(machines, timeout = 180):
35    # wait until the profilers have started
36    start_bar = barrier("PROF_MASTER", "start_profilers",
37            timeout, port=11920)
38    start_bar.rendezvous_servers("PROF_MASTER", *machines)
39
40
41def stop_profilers(machines, timeout = 120):
42    stop_bar = barrier("PROF_MASTER", "stop_profilers", timeout, port=11920)
43    stop_bar.rendezvous_servers("PROF_MASTER", *machines)
44
45
46def server_sleep_test(seconds):
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)
53
54
55def main():
56    timeout_sync = 180
57    timeout_start = 60
58    timeout_stop = 60
59    profilers = [["vmstat"], ["iostat"]]
60
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)
67
68
69main()
70