From: Yunping Zheng <[email protected]>

This patch add systemtap profilers in autotest. systemstap will run
ships with your test.using systemtap can provide more useful debugging
date.
When you use this profoler,you should add 'profilers = systemtap' and
'stap_script_file = file_path_systemtap_script' under you test.if the
'file_path_systemtap_script' you assigned is a relative path,the
script will find the file under 'test.virtdir'.

Signed-off-by: yunping zheng <[email protected]>
Signed-off-by: Yunping Zheng <[email protected]>
---
 client/profilers/systemtap/control      |  3 ++
 client/profilers/systemtap/systemtap.py | 52 +++++++++++++++++++++++++++++++++
 client/virt/utils_misc.py               |  2 +-
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 client/profilers/systemtap/__init__.py
 create mode 100644 client/profilers/systemtap/control
 create mode 100644 client/profilers/systemtap/systemtap.py

diff --git a/client/profilers/systemtap/__init__.py 
b/client/profilers/systemtap/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/client/profilers/systemtap/control 
b/client/profilers/systemtap/control
new file mode 100644
index 0000000..fca7fea
--- /dev/null
+++ b/client/profilers/systemtap/control
@@ -0,0 +1,3 @@
+job.profilers.add('systemtap', 2)
+job.run_test('sleeptest', seconds=5)
+job.profilers.delete('systemtap')
diff --git a/client/profilers/systemtap/systemtap.py 
b/client/profilers/systemtap/systemtap.py
new file mode 100644
index 0000000..4ad513e
--- /dev/null
+++ b/client/profilers/systemtap/systemtap.py
@@ -0,0 +1,52 @@
+"""
+Run systemstap.
+"""
+import logging, os, re, subprocess
+from autotest.client import profiler
+from autotest.client.shared import utils, error
+from autotest.client.virt import utils_misc
+
+class systemtap(profiler.profiler):
+    version = 1
+
+    def initialize(self, **dargs):
+        """
+            Tracing the qemu process using systemtap tools.
+        """
+        self.script_name = dargs.get('stap_script_file')
+        stap_support_cmd = "stap -e 'probe begin { log(\"Support\") exit() }'"
+        if not  re.findall("Support", utils.system_output(stap_support_cmd)):
+            raise error.TestWarn("Seems your host not support 'stap'")
+        if not self.script_name:
+            raise error.TestWarn("You should assign a script file")
+
+    def start(self, test):
+        stap_script = utils_misc.get_path(test.virtdir, self.script_name)
+        if os.path.isfile(stap_script):
+            cmd = "sudo stap %s"  % (stap_script)
+            filename = "systemtap.log"
+            logfile = open(utils_misc.get_path(test.profdir, filename), 'w')
+            logging.debug("Start systemtap profiling, using:'%s'" % cmd)
+            p = subprocess.Popen(cmd, shell=True, stdout=logfile,
+                                             stderr=subprocess.STDOUT)
+            self.pid = p.pid
+        else:
+            raise error.TestWarn("The stap script '%s' not exist" % 
stap_script)
+
+    def stop(self, test):
+        try:
+            term_profiler = "kill -15 %d" % self.pid
+            # send SIGTERM to iostat and give it a 5-sec timeout
+            utils.system(term_profiler, timeout=5)
+        except error.CmdError: # probably times out
+            pass
+        # do a ps again to see if iostat is still there
+        ps_cmd = "ps -p %d | grep stap" % self.pid
+        out = utils.system_output(ps_cmd, ignore_status=True)
+        if out != '':
+            kill_profiler = 'kill -9 %d' % self.pid
+            utils.system(kill_profiler, ignore_status=True)
+
+
+    def report(self, test):
+        return None
diff --git a/client/virt/utils_misc.py b/client/virt/utils_misc.py
index 50fd47a..1fb3faa 100644
--- a/client/virt/utils_misc.py
+++ b/client/virt/utils_misc.py
@@ -1623,7 +1623,7 @@ def run_tests(parser, job):
             # Setting up profilers during test execution.
             profilers = param_dict.get("profilers", "").split()
             for profiler in profilers:
-                job.profilers.add(profiler)
+                job.profilers.add(profiler, **param_dict)
             # We need only one execution, profiled, hence we're passing
             # the profile_only parameter to job.run_test().
             profile_only = bool(profilers) or None
-- 
1.7.11.4

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to