1*9c5db199SXin Liimport time 2*9c5db199SXin Li 3*9c5db199SXin Lissh_hosts = [hosts.create_host(m) for m in machines] 4*9c5db199SXin Liat_hosts = [autotest.Autotest(h) for h in ssh_hosts] 5*9c5db199SXin Li 6*9c5db199SXin Li 7*9c5db199SXin Lidef add_profilers(at, profilers, timeout_sync, timeout_start, timeout_stop, 8*9c5db199SXin Li machines, name): 9*9c5db199SXin Li control_file = [] 10*9c5db199SXin Li for profiler in profilers: 11*9c5db199SXin Li control_file.append("job.profilers.add(%s)" 12*9c5db199SXin Li % str(profiler)[1:-1]) 13*9c5db199SXin Li 14*9c5db199SXin Li control_file.append(("job.run_test('profiler_sync', timeout_sync=%d, " 15*9c5db199SXin Li "timeout_start=%d, timeout_stop=%d, " 16*9c5db199SXin Li "hostid='%s', mainid='%s', all_ids=%s)") 17*9c5db199SXin Li % (timeout_sync, timeout_start, timeout_stop, 18*9c5db199SXin Li at.host.hostname, "PROF_MAIN", str(machines))) 19*9c5db199SXin Li 20*9c5db199SXin Li for profiler in profilers: 21*9c5db199SXin Li control_file.append("job.profilers.delete('%s')" % profiler[0]) 22*9c5db199SXin Li 23*9c5db199SXin Li params = ["\n".join(control_file), "profile-" + profiler[0], at.host] 24*9c5db199SXin Li return subcommand(at.run, params, name) 25*9c5db199SXin Li 26*9c5db199SXin Li 27*9c5db199SXin Lidef wait_for_profilers(machines, timeout = 180): 28*9c5db199SXin Li # wait until the profilers have started 29*9c5db199SXin Li sync_bar = barrier("PROF_MAIN", "sync_profilers", 30*9c5db199SXin Li timeout, port=11920) 31*9c5db199SXin Li sync_bar.rendezvous_servers("PROF_MAIN", *machines) 32*9c5db199SXin Li 33*9c5db199SXin Li 34*9c5db199SXin Lidef start_profilers(machines, timeout = 180): 35*9c5db199SXin Li # wait until the profilers have started 36*9c5db199SXin Li start_bar = barrier("PROF_MAIN", "start_profilers", 37*9c5db199SXin Li timeout, port=11920) 38*9c5db199SXin Li start_bar.rendezvous_servers("PROF_MAIN", *machines) 39*9c5db199SXin Li 40*9c5db199SXin Li 41*9c5db199SXin Lidef stop_profilers(machines, timeout = 120): 42*9c5db199SXin Li stop_bar = barrier("PROF_MAIN", "stop_profilers", timeout, port=11920) 43*9c5db199SXin Li stop_bar.rendezvous_servers("PROF_MAIN", *machines) 44*9c5db199SXin Li 45*9c5db199SXin Li 46*9c5db199SXin Lidef server_sleep_test(seconds): 47*9c5db199SXin Li wait_for_profilers(machines) 48*9c5db199SXin Li start_profilers(machines) 49*9c5db199SXin Li for i in range(seconds): 50*9c5db199SXin Li print "%d of %d" % (i, seconds) 51*9c5db199SXin Li time.sleep(1) 52*9c5db199SXin Li stop_profilers(machines) 53*9c5db199SXin Li 54*9c5db199SXin Li 55*9c5db199SXin Lidef main(): 56*9c5db199SXin Li timeout_sync = 180 57*9c5db199SXin Li timeout_start = 60 58*9c5db199SXin Li timeout_stop = 60 59*9c5db199SXin Li profilers = [["vmstat"], ["iostat"]] 60*9c5db199SXin Li 61*9c5db199SXin Li tests = [subcommand(server_sleep_test, [20], "server_sleep_test")] 62*9c5db199SXin Li for at in at_hosts: 63*9c5db199SXin Li name = "profiled-%s" % at.host.hostname 64*9c5db199SXin Li tests.append(add_profilers(at, profilers, timeout_sync, 65*9c5db199SXin Li timeout_start, timeout_stop, machines, name)) 66*9c5db199SXin Li parallel(tests) 67*9c5db199SXin Li 68*9c5db199SXin Li 69*9c5db199SXin Limain() 70