On Tue, 2010-06-22 at 14:48 -0700, Arun Sharma wrote:
> On Tue, Jun 22, 2010 at 2:34 PM, Lucas Meneghel Rodrigues
> <[email protected]> wrote:
> > Could you send a full patch against the latest trunk please?
> 
> Certainly. As attached.
> 
>  -Arun

Hi Arun, I had reviewed your patch, it's mostly good, few small
comments. To begin with, all profilers need __init__.py files, and
cpistat needs execution permissions set. Also, there are other minor
comments below, I picked up your patch and made some modifications,
which I sent to the mailing list. Let me know if you like my
modifications.

diff --git a/client/profilers/perf/perf.py b/client/profilers/perf/perf.py
new file mode 100644
index 0000000..8f5eb44
--- /dev/null
+++ b/client/profilers/perf/perf.py
@@ -0,0 +1,42 @@ 
+"""
+perf is a tool included in the linux kernel tree that
+supports functionality similar to oprofile and more.
+
+...@see: http://lwn.net/Articles/310260/
+"""
+
+import time, os, subprocess, signal
+from autotest_lib.client.bin import profiler
+
+class perf(profiler.profiler):
+    version = 1
+
+    def initialize(self, events="cycles,instructions"):
+        self.events = events
+
+
+    def start(self, test):
+        self.logfile = os.path.join(test.profdir, "perf")
+        cmd = ("/usr/bin/perf record -a -o %s -e %s" %
+               (self.logfile, self.events))

^ Here, hardcoding the perf binary is a bad idea. Fedora, for example,
installs perf on /usr/sbin. So the best solution here is using
os_dep.command() to find the binary, which I did on a new version of the
test.

+        self._process = subprocess.Popen(cmd, shell=True, 
stderr=subprocess.STDOUT)
+
+
+    def stop(self, test):
+        os.kill(self._process.pid, signal.SIGINT)
+        self._process.wait()
+
+
+    def report(self, test):
+        self.reportfile_comm = os.path.join(test.profdir, 'perf.comm')
+        cmd = "/usr/bin/perf report -i %s --sort comm,dso" % self.logfile
+        outfile = open(self.reportfile_comm, 'w')
+        p1 = subprocess.Popen(cmd, shell=True, stdout=outfile,
+                              stderr=subprocess.STDOUT)
+        p1.wait()
+        self.reportfile_cpu = os.path.join(test.profdir, 'perf.cpu')
+        cmd = "/usr/bin/perf report -i %s --sort cpu,dso" % self.logfile
+        outfile = open(self.reportfile_cpu, 'w')
+        p2 = subprocess.Popen(cmd, shell=True, stdout=outfile,
+                              stderr=subprocess.STDOUT)

^ Not all perf versions support the same set of sort keys, so I thought
we could parse perf report help output and choose the ones available at
runtime. I actually did that, it's on the version I sent to the mailing
list.

+        p2.wait()


_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to