On 10/24/2012 07:05 AM, [email protected] wrote:
From: Yunping Zheng <[email protected]>

This patch adds a systemtap profiler to autotest. Now systemtap
can run during your test, providing useful debug data.

When you use this profiler on virt tests, you should add
     'profilers = systemtap'
and
     'stap_script_file = file_path_systemtap_script'

On your test cfg file. If the 'file_path_systemtap_script' you
assigned is a relative path,the script will try to find the file
under 'test.autodir/profilers/systemtap/scripts'.

Before using this patch make sure you host is support "stap",you can
run  "stap -e 'probe begin { log(\"Support\") exit() }'" to have a
check, if you host not suppor stap,please install systemtap and
related packages.

Hey Yunping, I remember the first version of this patch brought problems on next testing, it was breaking running the virttests from autotest. Do you remember that, and if so, have you fixed that problem?

Signed-off-by: Yunping Zheng <[email protected]>
---
  client/profilers/catprofile/catprofile.py   |  2 +-
  client/profilers/cmdprofile/cmdprofile.py   |  2 +-
  client/profilers/cpistat/cpistat.py         |  2 +-
  client/profilers/iostat/iostat.py           |  2 +-
  client/profilers/kvm_modload/kvm_modload.py |  2 +-
  client/profilers/kvm_stat/kvm_stat.py       |  2 +-
  client/profilers/lockmeter/lockmeter.py     |  2 +-
  client/profilers/mpstat/mpstat.py           |  2 +-
  client/profilers/oprofile/oprofile.py       |  2 +-
  client/profilers/perf/perf.py               |  2 +-
  client/profilers/readprofile/readprofile.py |  2 +-
  client/profilers/sar/sar.py                 |  2 +-
  client/profilers/systemtap/control          |  5 ++
  client/profilers/systemtap/src/.version     |  2 +
  client/profilers/systemtap/systemtap.py     | 82 +++++++++++++++++++++++++++++
  client/profilers/vmstat/vmstat.py           |  2 +-
  16 files changed, 102 insertions(+), 13 deletions(-)
  create mode 100644 client/profilers/systemtap/__init__.py
  create mode 100644 client/profilers/systemtap/control
  create mode 100644 client/profilers/systemtap/src/.version
  create mode 100644 client/profilers/systemtap/systemtap.py

diff --git a/client/profilers/catprofile/catprofile.py 
b/client/profilers/catprofile/catprofile.py
index b854782..5b8464d 100644
--- a/client/profilers/catprofile/catprofile.py
+++ b/client/profilers/catprofile/catprofile.py
@@ -13,7 +13,7 @@ class catprofile(profiler.profiler):

      # filenames: list of filenames to cat
      def initialize(self, filenames = ['/proc/meminfo', '/proc/slabinfo'],
-                            outfile = 'monitor', interval = 1):
+                            outfile = 'monitor', interval = 1, **dargs):
          self.filenames = filenames
          self.outfile = outfile
          self.interval = interval
diff --git a/client/profilers/cmdprofile/cmdprofile.py 
b/client/profilers/cmdprofile/cmdprofile.py
index c4c6c5a..66e7fde 100644
--- a/client/profilers/cmdprofile/cmdprofile.py
+++ b/client/profilers/cmdprofile/cmdprofile.py
@@ -13,7 +13,7 @@ class cmdprofile(profiler.profiler):


      def initialize(self, cmds=['ps'], interval=60, outputfile='cmdprofile',
-                   outputfiles=None):
+                   outputfiles=None, **dargs):

          # do some basic sanity checking on the parameters
          if not outputfiles and not outputfile:
diff --git a/client/profilers/cpistat/cpistat.py 
b/client/profilers/cpistat/cpistat.py
index 8506958..b24e761 100644
--- a/client/profilers/cpistat/cpistat.py
+++ b/client/profilers/cpistat/cpistat.py
@@ -10,7 +10,7 @@ from autotest.client import profiler
  class cpistat(profiler.profiler):
      version = 1

-    def initialize(self, interval = 1):
+    def initialize(self, interval = 1, **dargs):
          self.interval = interval


diff --git a/client/profilers/iostat/iostat.py 
b/client/profilers/iostat/iostat.py
index b3ebbbc..2a8a7dc 100644
--- a/client/profilers/iostat/iostat.py
+++ b/client/profilers/iostat/iostat.py
@@ -9,7 +9,7 @@ from autotest.client.shared import utils, error
  class iostat(profiler.profiler):
      version = 2

-    def initialize(self, interval = 1, options = ''):
+    def initialize(self, interval = 1, options = '', **dargs):
          # Usage: iostat [ options... ] [ <interval> [ <count> ] ]
          # e.g, iostat -tmx 2
          self.interval = interval
diff --git a/client/profilers/kvm_modload/kvm_modload.py 
b/client/profilers/kvm_modload/kvm_modload.py
index 1b9747e..fd234cd 100644
--- a/client/profilers/kvm_modload/kvm_modload.py
+++ b/client/profilers/kvm_modload/kvm_modload.py
@@ -14,7 +14,7 @@ class kvm_modload(profiler.profiler):
      version = 4


-    def initialize(self, interval=None, options=None):
+    def initialize(self, interval=None, options=None, **dargs):
          pass


diff --git a/client/profilers/kvm_stat/kvm_stat.py 
b/client/profilers/kvm_stat/kvm_stat.py
index f4d2fa5..ef34e95 100644
--- a/client/profilers/kvm_stat/kvm_stat.py
+++ b/client/profilers/kvm_stat/kvm_stat.py
@@ -17,7 +17,7 @@ class kvm_stat(profiler.profiler):
      test execution, redirecting its output to a file on the profile dir.
      """
      version = 1
-    def initialize(self):
+    def initialize(self, **drags):
          """
          Gets path of kvm_stat and verifies if debugfs needs to be mounted.
          """
diff --git a/client/profilers/lockmeter/lockmeter.py 
b/client/profilers/lockmeter/lockmeter.py
index 7d774f9..07c5171 100644
--- a/client/profilers/lockmeter/lockmeter.py
+++ b/client/profilers/lockmeter/lockmeter.py
@@ -29,7 +29,7 @@ class lockmeter(profiler.profiler):
          self.cmd = self.srcdir + '/lockstat'


-    def initialize(self):
+    def initialize(self, **dargs):
          self.job.require_gcc()

          if not os.path.exists('/proc/lockmeter'):
diff --git a/client/profilers/mpstat/mpstat.py 
b/client/profilers/mpstat/mpstat.py
index 1c8a2a0..8fcbcc2 100644
--- a/client/profilers/mpstat/mpstat.py
+++ b/client/profilers/mpstat/mpstat.py
@@ -9,7 +9,7 @@ class mpstat(profiler.profiler):
      version = 1


-    def initialize(self, interval = 1):
+    def initialize(self, interval = 1, **dargs):
          self.interval = interval


diff --git a/client/profilers/oprofile/oprofile.py 
b/client/profilers/oprofile/oprofile.py
index 0022fa5..f5dae4b 100644
--- a/client/profilers/oprofile/oprofile.py
+++ b/client/profilers/oprofile/oprofile.py
@@ -95,7 +95,7 @@ class oprofile(profiler.profiler):
          self._setup_oprofile()


-    def initialize(self, vmlinux=None, events=[], others=None, local=None):
+    def initialize(self, vmlinux=None, events=[], others=None, local=None, 
**dargs):
          self.job.require_gcc()

          if not vmlinux:
diff --git a/client/profilers/perf/perf.py b/client/profilers/perf/perf.py
index 21f7bd6..c3dc737 100644
--- a/client/profilers/perf/perf.py
+++ b/client/profilers/perf/perf.py
@@ -13,7 +13,7 @@ from autotest.client import profiler, os_dep, utils
  class perf(profiler.profiler):
      version = 1

-    def initialize(self, events=["cycles","instructions"], trace=False):
+    def initialize(self, events=["cycles","instructions"], trace=False, 
**dargs):
          if type(events) == str:
              self.events = [events]
          else:
diff --git a/client/profilers/readprofile/readprofile.py 
b/client/profilers/readprofile/readprofile.py
index 255d90a..c5caa4a 100644
--- a/client/profilers/readprofile/readprofile.py
+++ b/client/profilers/readprofile/readprofile.py
@@ -26,7 +26,7 @@ class readprofile(profiler.profiler):
          utils.make('readprofile')


-    def initialize(self):
+    def initialize(self, **dargs):
          self.job.require_gcc()

          try:
diff --git a/client/profilers/sar/sar.py b/client/profilers/sar/sar.py
index ce4d0ff..3d8578b 100644
--- a/client/profilers/sar/sar.py
+++ b/client/profilers/sar/sar.py
@@ -17,7 +17,7 @@ class sar(profiler.profiler):
      """
      version = 1

-    def initialize(self, interval=1):
+    def initialize(self, interval=1, **dargs):
          """
          Set sar interval and verify what flags the installed sar supports.

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..bf600d2
--- /dev/null
+++ b/client/profilers/systemtap/control
@@ -0,0 +1,5 @@
+# You must provide a path to a systemtap script
+st_script = '/usr/share/systemtap/tapset/timestamp.stp'
+job.profilers.add('systemtap', stap_script_file=st_script)
+job.run_test('sleeptest', seconds=5)
+job.profilers.delete('systemtap')
diff --git a/client/profilers/systemtap/src/.version 
b/client/profilers/systemtap/src/.version
new file mode 100644
index 0000000..569369f
--- /dev/null
+++ b/client/profilers/systemtap/src/.version
@@ -0,0 +1,2 @@
+I1
+.
\ No newline at end of file
diff --git a/client/profilers/systemtap/systemtap.py 
b/client/profilers/systemtap/systemtap.py
new file mode 100644
index 0000000..ce5e4d8
--- /dev/null
+++ b/client/profilers/systemtap/systemtap.py
@@ -0,0 +1,82 @@
+"""
+Autotest systemtap profiler.
+"""
+import logging, os, re, subprocess
+from autotest.client import profiler, os_dep
+from autotest.client.shared import utils, error
+
+
+class systemtap(profiler.profiler):
+    """
+    Tracing test process using systemtap tools.
+    """
+    version = 1
+
+    def initialize(self, **dargs):
+        self.is_enabled = False
+
+        stap_installed = False
+        try:
+            self.stap_path = os_dep.command('stap')
+            stap_installed = True
+        except ValueError:
+            logging.error('Command stap not present')
+
+        if stap_installed:
+            self.is_enabled = True
+            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)):
+                logging.warning("Seems your host does not support systemtap")
+                self.is_enabled = False
+            if not self.script_name:
+                logging.warning("You should assign a script file")
+                self.is_enabled = False
+
+
+    def _get_stap_script_name(self, test):
+        try:
+            if os.path.isabs(self.script_name):
+                return self.script_name
+            else:
+                return os.path.join(test.autodir, 
"profilers/systemtap/scripts", self.script_name)
+        except AttributeError:
+            return self.script_name
+
+
+    def start(self, test):
+        if self.is_enabled:
+            stap_script = self._get_stap_script_name(test)
+            if os.path.isfile(stap_script):
+                cmd = "stap %s"  % (stap_script)
+                logfile = open(os.path.join(test.profdir, "systemtap.log"), 
'w')
+                p = subprocess.Popen(cmd, shell=True, stdout=logfile,
+                                     stderr=subprocess.STDOUT)
+                self.pid = p.pid
+            else:
+                logging.warning("Asked for systemtap profiling, but no script "
+                                "file %s not found", stap_script)
+                self.is_enabled = False
+        else:
+            logging.warning("Asked for systemtap profiling, but it couldn't "
+                            "be initialized")
+
+
+    def stop(self, test):
+        if self.is_enabled:
+            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/profilers/vmstat/vmstat.py 
b/client/profilers/vmstat/vmstat.py
index 6195032..6cc174c 100644
--- a/client/profilers/vmstat/vmstat.py
+++ b/client/profilers/vmstat/vmstat.py
@@ -11,7 +11,7 @@ from autotest.client import profiler
  class vmstat(profiler.profiler):
      version = 1

-    def initialize(self, interval = 1):
+    def initialize(self, interval = 1, **dargs):
          self.interval = interval




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

Reply via email to