blob: bdbc44c920217ea5e85b863c2f8b7b455cd28c61 [file] [log] [blame]
mbligh4a3e6972008-01-16 17:55:05 +00001#
2# Copyright 2007 Google Inc. All Rights Reserved.
3
4"""Runs profilers on a machine when no autotest job is running.
5
6This is used to profile a task when the task is running on a machine that is not
7running through autotest.
8"""
9
10__author__ = 'cranger@google.com (Colby Ranger)'
11
mblighfa29a2a2008-05-16 22:48:09 +000012import common
mblighccb9e182008-04-17 15:42:10 +000013from autotest_lib.client.common_lib import barrier
mbligh4a3e6972008-01-16 17:55:05 +000014
mbligha8ba7042009-12-19 05:29:13 +000015RUNTEST_PATTERN="job.run_test('barriertest',timeout_sync=%r,timeout_start=%r,\
16timeout_stop=%r,hostid='%s',masterid='%s',all_ids=%r)"
17
18def _encode_args(profiler, args, dargs):
19 parts = [repr(profiler)]
20 parts += [repr(arg) for arg in args]
21 parts += ["%s=%r" % darg for darg in dargs.iteritems()]
22 return ", ".join(parts)
23
mbligh4a3e6972008-01-16 17:55:05 +000024
25def generate_test(machines, hostname, profilers, timeout_start, timeout_stop,
jadmanski0afbb632008-06-06 21:10:57 +000026 timeout_sync=180):
mbligha8ba7042009-12-19 05:29:13 +000027 """
28 Generate control file that enables given profilers and starts barriertest.
29
30 @param machines: sequence of all the hostnames involved in the barrier
31 synchronization
32 @param hostname: hostname of the machine running the generated control file
33 @param profilers: a sequence of 3 items tuples where the first item is a
34 string (the profiler name), second argument is a tuple with the
35 non keyword arguments to give to the profiler when being added
36 with "job.profilers.add()" in the control file, third item is
37 a dictionary of the keyword arguments to give it
38 @param timeout_start: how many seconds to wait in barriertest for the
39 profilers to start (None means no timeout)
40 @param timeout_stop: how many seconds to wait in barriertest for the
41 profilers to stop (None means no timeout)
42 @param timeout_sync: how many seconds to wait in barriertest for other
43 machines to reach the start of the barriertest (None means no
44 timeout)
45 """
jadmanski0afbb632008-06-06 21:10:57 +000046 control_file = []
47 for profiler in profilers:
48 control_file.append("job.profilers.add(%s)"
mbligha8ba7042009-12-19 05:29:13 +000049 % _encode_args(*profiler))
mbligh4a3e6972008-01-16 17:55:05 +000050
mbligha8ba7042009-12-19 05:29:13 +000051 control_file.append(RUNTEST_PATTERN % (timeout_sync, timeout_start,
52 timeout_stop, hostname, "PROF_MASTER", machines))
mbligh4a3e6972008-01-16 17:55:05 +000053
jadmanski0afbb632008-06-06 21:10:57 +000054 for profiler in profilers:
55 control_file.append("job.profilers.delete('%s')" % profiler[0])
mbligh4a3e6972008-01-16 17:55:05 +000056
jadmanski0afbb632008-06-06 21:10:57 +000057 return "\n".join(control_file)
mbligh4a3e6972008-01-16 17:55:05 +000058
59
60def wait_for_profilers(machines, timeout = 300):
jadmanski0afbb632008-06-06 21:10:57 +000061 sb = barrier.barrier("PROF_MASTER", "sync_profilers",
mblighb65c5b02009-08-03 16:46:50 +000062 timeout, port=11920)
mbligh9c12f772009-06-22 19:03:55 +000063 sb.rendezvous_servers("PROF_MASTER", *machines)
mbligh4a3e6972008-01-16 17:55:05 +000064
65
66def start_profilers(machines, timeout = 120):
jadmanski0afbb632008-06-06 21:10:57 +000067 sb = barrier.barrier("PROF_MASTER", "start_profilers",
mblighb65c5b02009-08-03 16:46:50 +000068 timeout, port=11920)
mbligh9c12f772009-06-22 19:03:55 +000069 sb.rendezvous_servers("PROF_MASTER", *machines)
mbligh4a3e6972008-01-16 17:55:05 +000070
71
72def stop_profilers(machines, timeout = 120):
jadmanski0afbb632008-06-06 21:10:57 +000073 sb = barrier.barrier("PROF_MASTER", "stop_profilers",
mblighb65c5b02009-08-03 16:46:50 +000074 timeout, port=11920)
mbligh9c12f772009-06-22 19:03:55 +000075 sb.rendezvous_servers("PROF_MASTER", *machines)
mbligha8ba7042009-12-19 05:29:13 +000076
77
78def finish_profilers(machines, timeout = 120):
79 sb = barrier.barrier("PROF_MASTER", "finish_profilers",
80 timeout, port=11920)
81 sb.rendezvous_servers("PROF_MASTER", *machines)