Modify the crash collection to collect server profiler data into the
correct profiler results directories, instead of just a catch-all
top-level directory. Makes use of the same mechanism we already use
for remembering Autotest client directories for crash collection.

Risk: Medium
Visibility: After a crash intermediate profiler data should be in the
location users would expect to see it, if the test completed normally.

Signed-off-by: John Admanski <jadmanski@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@3322 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/crashcollect.py b/server/crashcollect.py
index 8dbbb72..567a323 100644
--- a/server/crashcollect.py
+++ b/server/crashcollect.py
@@ -30,7 +30,6 @@
         collect_log_file(host, "/var/log/messages", crashinfo_dir)
         collect_log_file(host, "/var/log/monitor-ssh-reboots", crashinfo_dir)
         collect_command(host, "dmesg", os.path.join(crashinfo_dir, "dmesg"))
-        collect_profiler_data(host, crashinfo_dir)
         collect_uncollected_logs(host)
 
 
@@ -115,34 +114,6 @@
         devnull.close()
 
 
-def collect_profiler_data(host, dest_path):
-    """Collects any leftover profiler data that can be found.
-
-    Any profiler data found will be written into a subdirectory of the
-    crashinfo path called "profiler.$REMOTEDIR" where $REMOTEDIR is the
-    basename of the remote profiler data path.
-
-    @param host: The RemoteHost to collect from
-    @param dest_path: A directory to copy the profiler results into
-    """
-    logging.info("Collecting any server-side profiler data lying around...")
-    try:
-        cmd = "ls %s" % profiler.PROFILER_TMPDIR
-        profiler_dirs = [path for path in host.run(cmd).stdout.split()
-                         if path.startswith("autoserv-")]
-        for profiler_dir in profiler_dirs:
-            remote_path = profiler.get_profiler_results_dir(profiler_dir)
-            remote_exists = host.run("ls %s" % remote_path,
-                                     ignore_status=True).exit_status == 0
-            if not remote_exists:
-                continue
-            local_path = os.path.join(dest_path, "profiler." + profiler_dir)
-            os.mkdir(local_path)
-            host.get_file(remote_path + "/", local_path)
-    except Exception, e:
-        logging.warning("Collection of profiler data failed with:\n%s", e)
-
-
 def collect_uncollected_logs(host):
     """Collects any leftover uncollected logs from the client.
 
diff --git a/server/profiler.py b/server/profiler.py
index ccc5ce6..997df1a 100644
--- a/server/profiler.py
+++ b/server/profiler.py
@@ -182,6 +182,11 @@
                 at.run(control_script, background=True)
                 self._wait_on_client(host, autodir, "ready")
                 self._signal_client(host, autodir, "start")
+
+                remote_results_dir = get_profiler_results_dir(autodir)
+                local_results_dir = os.path.join(test.profdir, host.hostname)
+                self.job.add_client_log(host.hostname, remote_results_dir,
+                                        local_results_dir)
             except:
                 self._get_failure_logs(autodir, test, host)
                 raise
@@ -215,14 +220,15 @@
         for host, (at, autodir) in self._get_hosts(host).iteritems():
             if wait_on_client:
                 self._wait_on_client(host, autodir, "finished")
-            results_dir = get_profiler_results_dir(autodir) + "/"
+            results_dir = get_profiler_results_dir(autodir)
             local_dir = os.path.join(test.profdir, host.hostname)
             if not os.path.exists(local_dir):
                 os.makedirs(local_dir)
 
+            self.job.remove_client_log(host.hostname, results_dir, local_dir)
             tempdir = tempfile.mkdtemp(dir=self.job.tmpdir)
             try:
-                host.get_file(results_dir, tempdir)
+                host.get_file(results_dir + "/", tempdir)
             except error.AutoservRunError:
                 pass # no files to pull back, nothing we can do
             utils.merge_trees(tempdir, local_dir)