Re: ping Re: [PATCH] perf script: Add stackcollapse.py script

From: Jiri Olsa
Date: Thu Jun 16 2016 - 03:49:15 EST


On Fri, May 20, 2016 at 01:01:41PM +0200, Paolo Bonzini wrote:
>
>

SNIP

> >>> new file mode 100755
> >>> index 000000000000..356b9656393d
> >>> --- /dev/null
> >>> +++ b/tools/perf/scripts/python/bin/stackcollapse-report
> >>> @@ -0,0 +1,3 @@
> >>> +#!/bin/sh
> >>> +# description: produce callgraphs in short form for scripting use
> >>> +perf script -s "$PERF_EXEC_PATH"/scripts/python/stackcollapse.py -- "$@"
> >>> diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
> >>> new file mode 100755
> >>> index 000000000000..a2dfcda41ae6
> >>> --- /dev/null
> >>> +++ b/tools/perf/scripts/python/stackcollapse.py
> >>> @@ -0,0 +1,127 @@
> >>> +#!/usr/bin/perl -w
> >>> +#
> >>> +# stackcollapse.py - format perf samples with one line per distinct call stack
> >>> +#
> >>> +# This script's output has two space-separated fields. The first is a semicolon
> >>> +# separated stack including the program name (from the "comm" field) and the
> >>> +# function names from the call stack. The second is a count:
> >>> +#
> >>> +# swapper;start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 2
> >>> +#
> >>> +# The file is sorted according to the first field.
> >>> +#
> >>> +# Input may be created and processed using:
> >>> +#
> >>> +# perf record -a -g -F 99 sleep 60
> >>> +# perf script report stackcollapse > out.stacks-folded
> >>> +#
> >>> +# (perf script record stackcollapse works too).
> >
> > IIRC Namhyung added -g folded option recently for report
> > so you could do:
> >
> > perf report -g folded --stdio
> >
> > however we dont seem to have it for perf script, so this might
> > be useful until we add the --call-graph support into perf script
>
> While "perf report -g folded" is indeed similar in spirit, it doesn't
> provide exactly the same output as expected by the flame graph tools.
> The point of this patch is to talk directly to them, and to provide an
> example of looking at call stacks from Python.

as I said, while I rather see the --call-graph option support,
there's no harm in having this done by the script meanwhile

Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>

jirka