fix autotest oprofile setup process
1. move "--event" from start function to initialize function, because
"opcontrol --setup" without events specified sometimes may fail, this may be a bug
of opcontrol or ophelp, I have filed a bug report to oprofile mail list.
And give it a default value when user don't specify. Also, setup events
in initialize phase has logically meaning.
2. initialize(self, vmlinux = None, events = [], others = None)
Add vmlinux parameter, let user has a chance to specify vmlinux, such
as vmlinux-autotest, which can't be figured out by get_vmlinux function.
Add events list parameter, user can specify a list of events wanted to profiled.
Add others args, let user has chance to specify other args, such as "--callgraph=3".
3. add a sample control file oprofile.power5+
From: Yao Fei Zhu <walkinair@cn.ibm.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@359 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/profilers/oprofile/oprofile.py b/profilers/oprofile/oprofile.py
index a352e2c..3d9e9ea 100755
--- a/profilers/oprofile/oprofile.py
+++ b/profilers/oprofile/oprofile.py
@@ -16,24 +16,40 @@
system('make install')
- def initialize(self, event = None):
- self.event = event
+ def initialize(self, vmlinux = None, events = [], others = None):
+ if not vmlinux:
+ self.vmlinux = get_vmlinux()
+ else:
+ self.vmlinux = vmlinux
+ if not len(events):
+ self.events = ['default']
+ else:
+ self.events = events
+ self.others = others
+
+ # If there is existing setup file, oprofile may fail to start with default parameters.
+ if os.path.isfile('/root/.oprofile/daemonrc'):
+ os.rename('/root/.oprofile/daemonrc', '/root/.oprofile/daemonrc.org')
+
+ setup = ' --setup'
+ if not self.vmlinux:
+ setup += ' --no-vmlinux'
+ else:
+ setup += ' --vmlinux=%s' % self.vmlinux
+ for e in self.events:
+ setup += ' --event=%s' % e
+ if self.others:
+ setup += ' ' + self.others
+
self.opreport = self.srcdir + '/bin/opreport'
self.opcontrol = self.srcdir + '/bin/opcontrol'
- self.vmlinux = get_vmlinux()
- if not self.vmlinux:
- system(self.opcontrol + ' --setup --no-vmlinux')
- else:
- system(self.opcontrol + ' --setup --vmlinux=' + self.vmlinux)
+ system(self.opcontrol + setup)
def start(self, test):
system(self.opcontrol + ' --reset')
- if (self.event):
- system(self.opcontrol + ' --start --event ' +self.event)
- else:
- system(self.opcontrol + ' --start')
+ system(self.opcontrol + ' --start')
def stop(self, test):
diff --git a/samples/oprofile.power5+ b/samples/oprofile.power5+
new file mode 100644
index 0000000..e2547ab
--- /dev/null
+++ b/samples/oprofile.power5+
@@ -0,0 +1,24 @@
+print "Testing default event"
+job.profilers.add('oprofile')
+job.runtest('default', 'sleeptest', 1)
+job.profilers.delete('oprofile')
+
+print "Testing specified vmlinux"
+job.profilers.add('oprofile', '/boot/vmlinux-autotest')
+job.runtest('vmlinux', 'sleeptest', 1)
+job.profilers.delete('oprofile')
+
+print "Testing one event"
+job.profilers.add('oprofile', None, ['PM_RUN_CYC_GRP153:100000'])
+job.runtest('one', 'sleeptest', 1)
+job.profilers.delete('oprofile')
+
+print "Testing multiple events"
+job.profilers.add('oprofile', None, ['PM_RUN_CYC_GRP153:100000', 'PM_INST_CMPL_GRP153:10000'])
+job.runtest('multi', 'sleeptest', 1)
+job.profilers.delete('oprofile')
+
+print "Testing other args"
+job.profilers.add('oprofile', None, ['PM_RUN_CYC_GRP153:150000', 'PM_INST_CMPL_GRP153:150000'], '--callgraph=3')
+job.runtest('other', 'sleeptest', 1)
+job.profilers.delete('oprofile')