Add in more crashinfo collection code so that that when a machine
fails for some reason or another during a test which is using
profilers we still have some chance of pulling back the profiler data.

Since the crash will prevent the profiler's stop and report methods
from being called correctly the data pulled back may or may not be
useful, however for some profilers partial data will still be helpful,
and so it seems useful to pull back whatever data we can find.

Risk: Low
Visibility: Adds some more data to the crashinfo.* directories created
when machine crash unexpectedly during testing.

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



git-svn-id: http://test.kernel.org/svn/autotest/trunk@2815 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/remote.py b/server/hosts/remote.py
index b98fad6..6d05c07 100644
--- a/server/hosts/remote.py
+++ b/server/hosts/remote.py
@@ -3,7 +3,7 @@
 
 import os, time
 from autotest_lib.client.common_lib import error
-from autotest_lib.server import utils
+from autotest_lib.server import utils, profiler
 from autotest_lib.server.hosts import base_classes, bootloader
 
 
@@ -238,6 +238,24 @@
         finally:
             devnull.close()
 
+        # collect any profiler data we can find
+        print "Collecting any server-side profiler data lying around..."
+        try:
+            cmd = "ls %s" % profiler.PROFILER_TMPDIR
+            profiler_dirs = [path for path in self.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 = self.run("ls %s" % remote_path,
+                                         ignore_status=True).exit_status == 0
+                if not remote_exists:
+                    continue
+                local_path = os.path.join(infodir, "profiler." + profiler_dir)
+                os.mkdir(local_path)
+                self.get_file(remote_path + "/", local_path)
+        except Exception, e:
+            print "crashinfo collection of profiler data failed with:\n%s" % e
+
 
     def are_wait_up_processes_up(self):
         """