| OLD | NEW |
| 1 # | 1 # |
| 2 # Copyright 2007 Google Inc. All Rights Reserved. | 2 # Copyright 2007 Google Inc. All Rights Reserved. |
| 3 | 3 |
| 4 """Runs profilers on a machine when no autotest job is running. | 4 """Runs profilers on a machine when no autotest job is running. |
| 5 | 5 |
| 6 This is used to profile a task when the task is running on a machine that is not | 6 This is used to profile a task when the task is running on a machine that is not |
| 7 running through autotest. | 7 running through autotest. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 __author__ = 'cranger@google.com (Colby Ranger)' | 10 __author__ = 'cranger@google.com (Colby Ranger)' |
| 11 | 11 |
| 12 import common | 12 import common |
| 13 from autotest_lib.client.common_lib import barrier | 13 from autotest_lib.client.common_lib import barrier |
| 14 | 14 |
| 15 RUNTEST_PATTERN="job.run_test('barriertest',timeout_sync=%r,timeout_start=%r,\ | 15 # Client control file snippet used to synchronize profiler start & stop. |
| 16 timeout_stop=%r,hostid='%s',masterid='%s',all_ids=%r)" | 16 _RUNTEST_PATTERN = ("job.run_test('profiler_sync', timeout_sync=%r,\n" |
| 17 " timeout_start=%r, timeout_stop=%r,\n" |
| 18 " hostid='%s', masterid='%s', all_ids=%r)") |
| 19 _PROF_MASTER = "PROF_MASTER" |
| 20 _PORT = 11920 |
| 21 |
| 17 | 22 |
| 18 def _encode_args(profiler, args, dargs): | 23 def _encode_args(profiler, args, dargs): |
| 19 parts = [repr(profiler)] | 24 parts = [repr(profiler)] |
| 20 parts += [repr(arg) for arg in args] | 25 parts += [repr(arg) for arg in args] |
| 21 parts += ["%s=%r" % darg for darg in dargs.iteritems()] | 26 parts += ["%s=%r" % darg for darg in dargs.iteritems()] |
| 22 return ", ".join(parts) | 27 return ", ".join(parts) |
| 23 | 28 |
| 24 | 29 |
| 25 def generate_test(machines, hostname, profilers, timeout_start, timeout_stop, | 30 def generate_test(machines, hostname, profilers, timeout_start, timeout_stop, |
| 26 timeout_sync=180): | 31 timeout_sync=180): |
| 27 """ | 32 """ |
| 28 Generate control file that enables given profilers and starts barriertest. | 33 Generate a control file that enables profilers and starts profiler_sync. |
| 29 | 34 |
| 30 @param machines: sequence of all the hostnames involved in the barrier | 35 @param machines: sequence of all the hostnames involved in the barrier |
| 31 synchronization | 36 synchronization |
| 32 @param hostname: hostname of the machine running the generated control file | 37 @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 | 38 @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 | 39 string (the profiler name), second argument is a tuple with the |
| 35 non keyword arguments to give to the profiler when being added | 40 non keyword arguments to give to the profiler when being added |
| 36 with "job.profilers.add()" in the control file, third item is | 41 with "job.profilers.add()" in the control file, third item is |
| 37 a dictionary of the keyword arguments to give it | 42 a dictionary of the keyword arguments to give it |
| 38 @param timeout_start: how many seconds to wait in barriertest for the | 43 @param timeout_start: how many seconds to wait in profiler_sync for the |
| 39 profilers to start (None means no timeout) | 44 profilers to start (None means no timeout) |
| 40 @param timeout_stop: how many seconds to wait in barriertest for the | 45 @param timeout_stop: how many seconds to wait in profiler_sync for the |
| 41 profilers to stop (None means no timeout) | 46 profilers to stop (None means no timeout) |
| 42 @param timeout_sync: how many seconds to wait in barriertest for other | 47 @param timeout_sync: how many seconds to wait in profiler_sync for other |
| 43 machines to reach the start of the barriertest (None means no | 48 machines to reach the start of the profiler_sync (None means no |
| 44 timeout) | 49 timeout) |
| 45 """ | 50 """ |
| 46 control_file = [] | 51 control_file = [] |
| 47 for profiler in profilers: | 52 for profiler in profilers: |
| 48 control_file.append("job.profilers.add(%s)" | 53 control_file.append("job.profilers.add(%s)" |
| 49 % _encode_args(*profiler)) | 54 % _encode_args(*profiler)) |
| 50 | 55 |
| 51 control_file.append(RUNTEST_PATTERN % (timeout_sync, timeout_start, | 56 profiler_sync_call = (_RUNTEST_PATTERN % |
| 52 timeout_stop, hostname, "PROF_MASTER", machines)) | 57 (timeout_sync, timeout_start, timeout_stop, |
| 58 hostname, _PROF_MASTER, machines)) |
| 59 control_file.append(profiler_sync_call) |
| 53 | 60 |
| 54 for profiler in profilers: | 61 for profiler in reversed(profilers): |
| 55 control_file.append("job.profilers.delete('%s')" % profiler[0]) | 62 control_file.append("job.profilers.delete('%s')" % profiler[0]) |
| 56 | 63 |
| 57 return "\n".join(control_file) | 64 return "\n".join(control_file) |
| 58 | 65 |
| 59 | 66 |
| 60 def wait_for_profilers(machines, timeout = 300): | 67 def wait_for_profilers(machines, timeout=300): |
| 61 sb = barrier.barrier("PROF_MASTER", "sync_profilers", | 68 sb = barrier.barrier(_PROF_MASTER, "sync_profilers", |
| 62 timeout, port=11920) | 69 timeout, port=_PORT) |
| 63 sb.rendezvous_servers("PROF_MASTER", *machines) | 70 sb.rendezvous_servers(_PROF_MASTER, *machines) |
| 64 | 71 |
| 65 | 72 |
| 66 def start_profilers(machines, timeout = 120): | 73 def start_profilers(machines, timeout=120): |
| 67 sb = barrier.barrier("PROF_MASTER", "start_profilers", | 74 sb = barrier.barrier(_PROF_MASTER, "start_profilers", |
| 68 timeout, port=11920) | 75 timeout, port=_PORT) |
| 69 sb.rendezvous_servers("PROF_MASTER", *machines) | 76 sb.rendezvous_servers(_PROF_MASTER, *machines) |
| 70 | 77 |
| 71 | 78 |
| 72 def stop_profilers(machines, timeout = 120): | 79 def stop_profilers(machines, timeout=120): |
| 73 sb = barrier.barrier("PROF_MASTER", "stop_profilers", | 80 sb = barrier.barrier(_PROF_MASTER, "stop_profilers", |
| 74 timeout, port=11920) | 81 timeout, port=_PORT) |
| 75 sb.rendezvous_servers("PROF_MASTER", *machines) | 82 sb.rendezvous_servers(_PROF_MASTER, *machines) |
| 76 | 83 |
| 77 | 84 |
| 78 def finish_profilers(machines, timeout = 120): | 85 def finish_profilers(machines, timeout=120): |
| 79 sb = barrier.barrier("PROF_MASTER", "finish_profilers", | 86 sb = barrier.barrier(_PROF_MASTER, "finish_profilers", |
| 80 timeout, port=11920) | 87 timeout, port=_PORT) |
| 81 sb.rendezvous_servers("PROF_MASTER", *machines) | 88 sb.rendezvous_servers(_PROF_MASTER, *machines) |
| OLD | NEW |