[{"id":13561,"web_url":"https://patchwork.libcamera.org/comment/13561/","msgid":"<20201030011123.GO15024@pendragon.ideasonboard.com>","date":"2020-10-30T01:11:23","subject":"Re: [libcamera-devel] [PATCH v3 5/6] utils: tracepoints: Add simple\n\tstatistics script","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Thu, Oct 29, 2020 at 07:16:28PM +0900, Paul Elder wrote:\n> Add a script that scans a trace for IPA call tracepoints, and returns\n> statistics on the time taken for IPA calls.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> ---\n> I'll fix output indentation in the next version.\n> \n> Changes in v3:\n> - check for the new tracepoint names, ipa_call_begin and ipa_call_end\n> - fix babeltrace2 parsing in the case that the event doesn't have a\n>   pipeline_name field\n> - change script description\n> - add argparse description\n> - add example for trace_path argument\n> - change double quotes to single quotes\n> \n> New in v2\n> ---\n>  utils/tracepoints/analyze.py | 66 ++++++++++++++++++++++++++++++++++++\n>  1 file changed, 66 insertions(+)\n>  create mode 100755 utils/tracepoints/analyze.py\n> \n> diff --git a/utils/tracepoints/analyze.py b/utils/tracepoints/analyze.py\n> new file mode 100755\n> index 00000000..43da9b1f\n> --- /dev/null\n> +++ b/utils/tracepoints/analyze.py\n\nI didn't notice when reviewing v2, but the script name seems very\ngeneric. Maybe analyze-ipa-trace.py ?\n\nWith the alignment fix if you have time and think it's worth it, this\nwill be good.\n\n> @@ -0,0 +1,66 @@\n> +#!/usr/bin/env python3\n> +# SPDX-License-Identifier: GPL-2.0-or-later\n> +# Copyright (C) 2020, Google Inc.\n> +#\n> +# Author: Paul Elder <paul.elder@ideasonboard.com>\n> +#\n> +# analyze.py - Example of how to extract information from libcamera lttng traces\n> +\n> +import argparse\n> +import bt2\n> +import statistics as stats\n> +import sys\n> +\n> +# pipeline -> {function -> stack(timestamps)}\n> +timestamps = {}\n> +\n> +# pipeline:function -> samples[]\n> +samples = {}\n> +\n> +def main(argv):\n> +    parser = argparse.ArgumentParser(\n> +            description='A simple analysis script to get statistics on time taken for IPA calls')\n> +    parser.add_argument('-p', '--pipeline', type=str,\n> +                        help='Name of pipeline to filter for')\n> +    parser.add_argument('trace_path', type=str,\n> +                        help='Path to lttng trace (eg. ~/lttng-traces/demo-20201029-184003)')\n> +    args = parser.parse_args(argv[1:])\n> +\n> +    traces = bt2.TraceCollectionMessageIterator(args.trace_path)\n> +    for msg in traces:\n> +        if type(msg) is not bt2._EventMessageConst or \\\n> +           'pipeline_name' not in msg.event.payload_field or \\\n> +           (args.pipeline is not None and \\\n> +            msg.event.payload_field['pipeline_name'] != args.pipeline):\n> +            continue\n> +\n> +        pipeline = msg.event.payload_field['pipeline_name']\n> +        event = msg.event.name\n> +        func = msg.event.payload_field['function_name']\n> +        timestamp_ns = msg.default_clock_snapshot.ns_from_origin\n> +\n> +        if event == 'libcamera:ipa_call_begin':\n> +            if pipeline not in timestamps:\n> +                timestamps[pipeline] = {}\n> +            if func not in timestamps[pipeline]:\n> +                timestamps[pipeline][func] = []\n> +            timestamps[pipeline][func].append(timestamp_ns)\n> +\n> +        if event == 'libcamera:ipa_call_end':\n> +            ts = timestamps[pipeline][func].pop()\n> +            key = f'{pipeline}:{func}'\n> +            if key not in samples:\n> +                samples[key] = []\n> +            samples[key].append(timestamp_ns - ts)\n> +\n> +    print('pipeline:function\\t:\\tmin\\tmax\\tmean\\tstddev')\n> +    for k, v in samples.items():\n> +        mean = int(stats.mean(v))\n> +        stddev = int(stats.stdev(v))\n> +        minv = min(v)\n> +        maxv = max(v)\n> +        print(f'{k}\\t:\\t{minv}\\t{maxv}\\t{mean}\\t{stddev}')\n> +\n> +\n> +if __name__ == '__main__':\n> +    sys.exit(main(sys.argv))","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CDB8EBDB1E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 30 Oct 2020 01:12:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6BA4B628A5;\n\tFri, 30 Oct 2020 02:12:14 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3461E60349\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 30 Oct 2020 02:12:13 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A1E3B9B7;\n\tFri, 30 Oct 2020 02:12:12 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VP18I3/F\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1604020332;\n\tbh=G5dZChHYoZC1rHgW4eL/0zzLnD3/6kcnCnfCgbCwszs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VP18I3/FDfyYYKpFDFkpGIYPTGpN4xs7qG4+LA53zoQqnmZITUDGwUShTp54Y8x1d\n\tQRQGpWfc0l/0KgG5HAn46fWsnwaLeBLVeKy+lBw8eCzhei8sQJtdge1bR6AOTl7wHi\n\tYybXqnRiP+GI3ocqOcT3S2mQZ8tk6b2ftPz1oDPQ=","Date":"Fri, 30 Oct 2020 03:11:23 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20201030011123.GO15024@pendragon.ideasonboard.com>","References":"<20201029101629.61798-1-paul.elder@ideasonboard.com>\n\t<20201029101629.61798-6-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201029101629.61798-6-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 5/6] utils: tracepoints: Add simple\n\tstatistics script","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]