On Mon, Sep 13, 2010 at 2:49 PM, Gregory P. Smith <[email protected]> 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]>
>
>
Obviously this patch also needs a trace-cmd.tar.bz2 for whatever
architecture you'll be running it on.  Ask [email protected] for details on
how he built that.  In ours, I see the following in the tarball, but it'd be
good to have this documented as to what version and where it came from if
the profiler isn't going to include code to build it itself.

% tar -tjf client/profilers/ftrace/trace-cmd.tar.bz2
./
./home/
./home/ftrace/
./home/ftrace/share/
./home/ftrace/share/trace-cmd/
./home/ftrace/share/trace-cmd/plugins/
./home/ftrace/share/trace-cmd/plugins/plugin_sched_switch.so
./home/ftrace/share/trace-cmd/plugins/plugin_jbd2.so
./home/ftrace/share/trace-cmd/plugins/plugin_python.so
./home/ftrace/share/trace-cmd/plugins/plugin_kmem.so
./home/ftrace/share/trace-cmd/plugins/plugin_hrtimer.so
./home/ftrace/share/trace-cmd/plugins/plugin_function.so
./home/ftrace/share/trace-cmd/plugins/plugin_mac80211.so
./home/ftrace/share/trace-cmd/python/
./home/ftrace/share/trace-cmd/python/ctracecmd.so
./home/ftrace/share/trace-cmd/python/event-viewer.py
./home/ftrace/share/trace-cmd/python/tracecmdgui.py
./home/ftrace/share/trace-cmd/python/tracecmd.py
./home/ftrace/bin/
./home/ftrace/bin/trace-cmd



> --- /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

Reply via email to