• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2readprofile - a tool to read kernel profiling information
3
4The readprofile command uses the /proc/profile information to print ascii data
5on standard output. The output is organized in three columns: the first is the
6number of clock ticks, the second is the name of the C function in the kernel
7where those many ticks occurred, and the third is the normalized `load' of the
8procedure, calculated as a ratio between the number of ticks and the length of
9the procedure. The output is filled with blanks to ease readability.
10"""
11import os, shutil
12from autotest_lib.client.bin import utils, profiler
13from autotest_lib.client.common_lib import error
14
15class 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