mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2007 Google Inc. All Rights Reserved. |
| 3 | |
| 4 | """Runs profilers on a machine when no autotest job is running. |
| 5 | |
| 6 | This is used to profile a task when the task is running on a machine that is not |
| 7 | running through autotest. |
| 8 | """ |
| 9 | |
| 10 | __author__ = 'cranger@google.com (Colby Ranger)' |
| 11 | |
mbligh | fa29a2a | 2008-05-16 22:48:09 +0000 | [diff] [blame] | 12 | import common |
mbligh | ccb9e18 | 2008-04-17 15:42:10 +0000 | [diff] [blame] | 13 | from autotest_lib.client.common_lib import barrier |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 14 | |
mbligh | a8ba704 | 2009-12-19 05:29:13 +0000 | [diff] [blame] | 15 | RUNTEST_PATTERN="job.run_test('barriertest',timeout_sync=%r,timeout_start=%r,\ |
| 16 | timeout_stop=%r,hostid='%s',masterid='%s',all_ids=%r)" |
| 17 | |
| 18 | def _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 | |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 24 | |
| 25 | def generate_test(machines, hostname, profilers, timeout_start, timeout_stop, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 26 | timeout_sync=180): |
mbligh | a8ba704 | 2009-12-19 05:29:13 +0000 | [diff] [blame] | 27 | """ |
| 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 | """ |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 46 | control_file = [] |
| 47 | for profiler in profilers: |
| 48 | control_file.append("job.profilers.add(%s)" |
mbligh | a8ba704 | 2009-12-19 05:29:13 +0000 | [diff] [blame] | 49 | % _encode_args(*profiler)) |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 50 | |
mbligh | a8ba704 | 2009-12-19 05:29:13 +0000 | [diff] [blame] | 51 | control_file.append(RUNTEST_PATTERN % (timeout_sync, timeout_start, |
| 52 | timeout_stop, hostname, "PROF_MASTER", machines)) |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 53 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 54 | for profiler in profilers: |
| 55 | control_file.append("job.profilers.delete('%s')" % profiler[0]) |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 56 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 57 | return "\n".join(control_file) |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | def wait_for_profilers(machines, timeout = 300): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 61 | sb = barrier.barrier("PROF_MASTER", "sync_profilers", |
mbligh | b65c5b0 | 2009-08-03 16:46:50 +0000 | [diff] [blame] | 62 | timeout, port=11920) |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame] | 63 | sb.rendezvous_servers("PROF_MASTER", *machines) |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | def start_profilers(machines, timeout = 120): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 67 | sb = barrier.barrier("PROF_MASTER", "start_profilers", |
mbligh | b65c5b0 | 2009-08-03 16:46:50 +0000 | [diff] [blame] | 68 | timeout, port=11920) |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame] | 69 | sb.rendezvous_servers("PROF_MASTER", *machines) |
mbligh | 4a3e697 | 2008-01-16 17:55:05 +0000 | [diff] [blame] | 70 | |
| 71 | |
| 72 | def stop_profilers(machines, timeout = 120): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 73 | sb = barrier.barrier("PROF_MASTER", "stop_profilers", |
mbligh | b65c5b0 | 2009-08-03 16:46:50 +0000 | [diff] [blame] | 74 | timeout, port=11920) |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame] | 75 | sb.rendezvous_servers("PROF_MASTER", *machines) |
mbligh | a8ba704 | 2009-12-19 05:29:13 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | def finish_profilers(machines, timeout = 120): |
| 79 | sb = barrier.barrier("PROF_MASTER", "finish_profilers", |
| 80 | timeout, port=11920) |
| 81 | sb.rendezvous_servers("PROF_MASTER", *machines) |