1 """ 2 readprofile - a tool to read kernel profiling information 3 4 The readprofile command uses the /proc/profile information to print ascii data 5 on standard output. The output is organized in three columns: the first is the 6 number of clock ticks, the second is the name of the C function in the kernel 7 where those many ticks occurred, and the third is the normalized `load' of the 8 procedure, calculated as a ratio between the number of ticks and the length of 9 the procedure. The output is filled with blanks to ease readability. 10 """ 11 import os, shutil 12 from autotest_lib.client.bin import utils, profiler 13 from autotest_lib.client.common_lib import error 14 15 class readprofile(profiler.profiler): 16 version = 1 17 18 # http://www.kernel.org/pub/linux/utils/util-linux/util-linux-2.12r.tar.bz2 19 def setup(self, tarball = 'util-linux-2.12r.tar.bz2'): 20 self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) 21 utils.extract_tarball_to_dir(self.tarball, self.srcdir) 22 os.chdir(self.srcdir) 23 24 utils.configure() 25 os.chdir('sys-utils') 26 utils.make('readprofile') 27 28 29 def initialize(self): 30 self.job.require_gcc() 31 32 try: 33 utils.system('grep -iq " profile=" /proc/cmdline') 34 except error.CmdError: 35 raise error.AutotestError('readprofile not enabled') 36 37 self.cmd = self.srcdir + '/sys-utils/readprofile' 38 39 40 def start(self, test): 41 utils.system(self.cmd + ' -r') 42 43 44 def stop(self, test): 45 # There's no real way to stop readprofile, so we stash the 46 # raw data at this point instead. BAD EXAMPLE TO COPY! ;-) 47 self.rawprofile = test.profdir + '/profile.raw' 48 print "STOP" 49 shutil.copyfile('/proc/profile', self.rawprofile) 50 51 52 def report(self, test): 53 args = ' -n' 54 args += ' -m ' + utils.get_systemmap() 55 args += ' -p ' + self.rawprofile 56 cmd = self.cmd + ' ' + args 57 txtprofile = test.profdir + '/profile.text' 58 utils.system(cmd + ' | sort -nr > ' + txtprofile) 59 utils.system('bzip2 ' + self.rawprofile) 60