On Mon, 2010-09-13 at 14:49 -0700, Gregory P. Smith wrote:
> Add ftrace profiler. Uses trace-cmd unpacked from trace-cmd.tar.bz2 into
> /home/ftrace to set up tracepoints and filters, and record a trace.dat.
> 
> Signed-off-by: David Sharp <[email protected]>

I will check with David and Steve Rosted how to best handle ftrace build
and install. It seems to me that unpacking the tarball
under /home/frtrace is not a very satisfactory solution, let's see if
there is a better way.

Thanks!

> 
> --- /dev/null 2009-12-17 12:29:38.000000000 -0800
> +++ autotest/client/profilers/ftrace/control  2010-09-07 14:02:55.000000000 
> -0700
> @@ -0,0 +1,3 @@
> +job.profilers.add('ftrace', tracepoints=['syscalls'])
> +job.run_test('sleeptest', seconds=1)
> +job.profilers.delete('ftrace')
> --- /dev/null 2009-12-17 12:29:38.000000000 -0800
> +++ autotest/client/profilers/ftrace/ftrace.py        2010-09-07 
> 14:02:55.000000000 -0700
> @@ -0,0 +1,71 @@
> +import os
> +import signal
> +import subprocess
> +from autotest_lib.client.bin import profiler
> +from autotest_lib.client.bin import utils
> +
> +class ftrace(profiler.profiler):
> +    version = 1
> +
> +    mountpoint = '/sys/kernel/debug'
> +    tracing_dir = os.path.join(mountpoint, 'tracing')
> +    trace_cmd = '/home/ftrace/bin/trace-cmd'
> +
> +    @staticmethod
> +    def join_command(cmd):
> +        """Shell escape the command for BgJob. grmbl."""
> +        result = []
> +        for arg in cmd:
> +            arg = '"%s"' % utils.sh_escape(arg)
> +            result += [arg]
> +        return ' '.join(result)
> +
> +    def setup(self, tarball='trace-cmd.tar.bz2', **kwargs):
> +        self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
> +        # can't use utils.extract_tarball_to_dir(tarball, '/'), 
> +        # because it will 'rm -rf /'. Fun.
> +        os.chdir('/')
> +        utils.system('tar xjf %s -C /' % self.tarball)
> +
> +    def initialize(self, tracepoints, buffer_size_kb=1408, **kwargs):
> +        """Initialize ftrace profiler.
> +
> +        Args:
> +            tracepoints: list containing a mix of tracpoint names and
> +                (tracepoint name, filter) tuples. Tracepoint names are as
> +                accepted by trace-cmd -e, eg "syscalls", or
> +                "syscalls:sys_enter_read". Filters are as accepted by
> +                trace-cmd -f, eg "((sig >= 10 && sig < 15) || sig == 17)"
> +            buffer_size_kb: Set the size of the ring buffer (per cpu).
> +        """
> +        # Make sure debugfs is mounted.
> +        utils.system('%s reset' % self.trace_cmd)
> +
> +        self.trace_cmd_args = ['-b', str(buffer_size_kb)]
> +        for tracepoint in tracepoints:
> +            if isinstance(tracepoint, tuple):
> +                tracepoint, event_filter = tracepoint
> +            else:
> +                event_filter = None
> +            self.trace_cmd_args += ['-e', tracepoint]
> +            if event_filter:
> +                self.trace_cmd_args += ['-f', event_filter]
> +
> +    def start(self, test):
> +        output_dir = os.path.join(test.profdir, 'ftrace')
> +        if not os.path.isdir(output_dir):
> +            os.makedirs(output_dir)
> +        self.output = os.path.join(output_dir, 'trace.dat')
> +        cmd = [self.trace_cmd, 'record', '-o', self.output]
> +        cmd += self.trace_cmd_args
> +        self.record_job = utils.BgJob(self.join_command(cmd))
> +
> +    def stop(self, test):
> +        os.kill(self.record_job.sp.pid, signal.SIGINT)
> +        utils.join_bg_jobs([self.record_job])
> +        # shrink the buffer to free memory.
> +        utils.system('%s reset -b 1' % self.trace_cmd)
> +        utils.system('bzip2 %s' % self.output)
> +
> +    
> +# vim: set sts=4 sw=4 ai et :
> _______________________________________________
> Autotest mailing list
> [email protected]
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest


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

Reply via email to