Change server profilers to control themselves via a client
profiler_sync test.

This restores the code that oddly used to be in client/tests/barriertest.py
as a new "test" named more appropriately: profiler_sync.  Server code that
references it and generates client control files to launch it is updated.

Signed-off-by: Gregory Smith <[email protected]>

--- /dev/null   2009-12-17 12:29:38.000000000 -0800
+++ autotest/client/tests/profiler_sync/profiler_sync.py        2010-04-07 
10:28:50.000000000 -0700
@@ -0,0 +1,53 @@
+# This "test" is used by autotest_lib.server.standalone_profilers to start
+# and stop profilers on a collection of hosts at approximately the same
+# time by synchronizing using barriers.
+
+from autotest_lib.client.bin import test
+from autotest_lib.client.common_lib import barrier
+
+class profiler_sync(test.test):
+    version = 1
+
+
+    def execute(self, timeout_sync, timeout_start, timeout_stop,
+                hostid, masterid, all_ids):
+        """
+        @param timeout_sync: Seconds to wait for the synchronization of all
+                hosts that will be launching profilers. (local_sync_profilers)
+        @param timeout_start: Seconds to wait for each of the initial
+                sync_profilers and start_profilers barriers between this
+                host and the master to be reached.
+        @param timeout_stop: Seconds to wait for this host and the master to
+                reach each of the stop_profilers and finish_profilers barriers.
+        @param hostid: This host's id (typically the hostname).
+        @param masterid: The master barrier host id where autoserv is running.
+        @param all_ids: A list of all hosts to synchronize profilers on.
+        """
+        profilers = self.job.profilers
+
+        barrier_server = barrier.listen_server(port=11920)
+        b0 = self.job.barrier(hostid, "sync_profilers", timeout_start,
+                              listen_server=barrier_server)
+        b0.rendezvous_servers(masterid, hostid)
+
+        b1 = self.job.barrier(hostid, "start_profilers", timeout_start,
+                              listen_server=barrier_server)
+        b1.rendezvous_servers(masterid, hostid)
+
+        b2 = self.job.barrier(hostid, "local_sync_profilers", timeout_sync)
+        b2.rendezvous(*all_ids)
+
+        profilers.start(self)
+
+        b3 = self.job.barrier(hostid, "stop_profilers", timeout_stop,
+                              listen_server=barrier_server)
+        b3.rendezvous_servers(masterid, hostid)
+
+        profilers.stop(self)
+        profilers.report(self)
+
+        b4 = self.job.barrier(hostid, "finish_profilers", timeout_stop,
+                              listen_server=barrier_server)
+        b4.rendezvous_servers(masterid, hostid)
+
+        barrier_server.close()
--- autotest/server/profilers.py        2010-04-07 10:28:50.000000000 -0700
+++ autotest/server/profilers.py        2010-04-07 10:28:50.000000000 -0700
@@ -13,7 +13,7 @@
     Given the directory of the autotest client used to run a profiler,
     return the remote path where profiler results will be stored.
     """
-    return os.path.join(autodir, 'results', 'default', 'barriertest',
+    return os.path.join(autodir, 'results', 'default', 'profiler_sync',
                         'profiling')
 
 
--- autotest/server/samples/profilertest.srv    2010-04-07 10:28:50.000000000 
-0700
+++ autotest/server/samples/profilertest.srv    2010-04-07 10:28:50.000000000 
-0700
@@ -11,7 +11,7 @@
         control_file.append("job.profilers.add(%s)"
                                 % str(profiler)[1:-1])
 
-    control_file.append(("job.run_test('barriertest', timeout_sync=%d, "
+    control_file.append(("job.run_test('profiler_sync', timeout_sync=%d, "
                          "timeout_start=%d, timeout_stop=%d, "
                          "hostid='%s', masterid='%s', all_ids=%s)")
                         % (timeout_sync, timeout_start, timeout_stop,
--- autotest/server/standalone_profiler.py      2010-04-07 10:28:50.000000000 
-0700
+++ autotest/server/standalone_profiler.py      2010-04-07 10:28:50.000000000 
-0700
@@ -12,8 +12,13 @@
 import common
 from autotest_lib.client.common_lib import barrier
 
-RUNTEST_PATTERN="job.run_test('barriertest',timeout_sync=%r,timeout_start=%r,\
-timeout_stop=%r,hostid='%s',masterid='%s',all_ids=%r)"
+# Client control file snippet used to synchronize profiler start & stop.
+_RUNTEST_PATTERN = ("job.run_test('profiler_sync', timeout_sync=%r,\n"
+                    "             timeout_start=%r, timeout_stop=%r,\n"
+                    "             hostid='%s', masterid='%s', all_ids=%r)")
+_PROF_MASTER = "PROF_MASTER"
+_PORT = 11920
+
 
 def _encode_args(profiler, args, dargs):
     parts = [repr(profiler)]
@@ -23,9 +28,9 @@
 
 
 def generate_test(machines, hostname, profilers, timeout_start, timeout_stop,
-                        timeout_sync=180):
+                  timeout_sync=180):
     """
-    Generate control file that enables given profilers and starts barriertest.
+    Generate a control file that enables profilers and starts profiler_sync.
 
     @param machines: sequence of all the hostnames involved in the barrier
             synchronization
@@ -35,12 +40,12 @@
             non keyword arguments to give to the profiler when being added
             with "job.profilers.add()" in the control file, third item is
             a dictionary of the keyword arguments to give it
-    @param timeout_start: how many seconds to wait in barriertest for the
+    @param timeout_start: how many seconds to wait in profiler_sync for the
             profilers to start (None means no timeout)
-    @param timeout_stop: how many seconds to wait in barriertest for the
+    @param timeout_stop: how many seconds to wait in profiler_sync for the
             profilers to stop (None means no timeout)
-    @param timeout_sync: how many seconds to wait in barriertest for other
-            machines to reach the start of the barriertest (None means no
+    @param timeout_sync: how many seconds to wait in profiler_sync for other
+            machines to reach the start of the profiler_sync (None means no
             timeout)
     """
     control_file = []
@@ -48,34 +53,36 @@
         control_file.append("job.profilers.add(%s)"
                             % _encode_args(*profiler))
 
-    control_file.append(RUNTEST_PATTERN % (timeout_sync, timeout_start,
-        timeout_stop, hostname, "PROF_MASTER", machines))
+    profiler_sync_call = (_RUNTEST_PATTERN %
+                          (timeout_sync, timeout_start, timeout_stop,
+                           hostname, _PROF_MASTER, machines))
+    control_file.append(profiler_sync_call)
 
-    for profiler in profilers:
+    for profiler in reversed(profilers):
         control_file.append("job.profilers.delete('%s')" % profiler[0])
 
     return "\n".join(control_file)
 
 
-def wait_for_profilers(machines, timeout = 300):
-    sb = barrier.barrier("PROF_MASTER", "sync_profilers",
-            timeout, port=11920)
-    sb.rendezvous_servers("PROF_MASTER", *machines)
+def wait_for_profilers(machines, timeout=300):
+    sb = barrier.barrier(_PROF_MASTER, "sync_profilers",
+            timeout, port=_PORT)
+    sb.rendezvous_servers(_PROF_MASTER, *machines)
 
 
-def start_profilers(machines, timeout = 120):
-    sb = barrier.barrier("PROF_MASTER", "start_profilers",
-            timeout, port=11920)
-    sb.rendezvous_servers("PROF_MASTER", *machines)
+def start_profilers(machines, timeout=120):
+    sb = barrier.barrier(_PROF_MASTER, "start_profilers",
+            timeout, port=_PORT)
+    sb.rendezvous_servers(_PROF_MASTER, *machines)
 
 
-def stop_profilers(machines, timeout = 120):
-    sb = barrier.barrier("PROF_MASTER", "stop_profilers",
-            timeout, port=11920)
-    sb.rendezvous_servers("PROF_MASTER", *machines)
+def stop_profilers(machines, timeout=120):
+    sb = barrier.barrier(_PROF_MASTER, "stop_profilers",
+            timeout, port=_PORT)
+    sb.rendezvous_servers(_PROF_MASTER, *machines)
 
 
-def finish_profilers(machines, timeout = 120):
-    sb = barrier.barrier("PROF_MASTER", "finish_profilers",
-            timeout, port=11920)
-    sb.rendezvous_servers("PROF_MASTER", *machines)
+def finish_profilers(machines, timeout=120):
+    sb = barrier.barrier(_PROF_MASTER, "finish_profilers",
+            timeout, port=_PORT)
+    sb.rendezvous_servers(_PROF_MASTER, *machines)
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to