Content-Security-Policy: default-src 'none'
Content-Type: text/plain; charset=UTF-8
Content-Length: 2695
Content-Disposition: inline; filename="analyze-ipa-trace.py"
Last-Modified: Tue, 24 Dec 2024 23:02:19 GMT
Expires: Fri, 22 Dec 2034 23:02:19 GMT
ETag: "50fbbf4299705dfc9b0ee774e0a03e1f5b754dee"

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020, Google Inc.
#
# Author: Paul Elder <paul.elder@ideasonboard.com>
#
# analyze-ipa-trace.py - Example of how to extract information from libcamera lttng traces

import argparse
import bt2
import statistics as stats
import sys

# pipeline -> {function -> stack(timestamps)}
timestamps = {}

# pipeline:function -> samples[]
samples = {}

def main(argv):
    parser = argparse.ArgumentParser(
            description='A simple analysis script to get statistics on time taken for IPA calls')
    parser.add_argument('-p', '--pipeline', type=str,
                        help='Name of pipeline to filter for')
    parser.add_argument('trace_path', type=str,
                        help='Path to lttng trace (eg. ~/lttng-traces/demo-20201029-184003)')
    args = parser.parse_args(argv[1:])

    traces = bt2.TraceCollectionMessageIterator(args.trace_path)
    for msg in traces:
        if type(msg) is not bt2._EventMessageConst or \
           'pipeline_name' not in msg.event.payload_field or \
           (args.pipeline is not None and \
            msg.event.payload_field['pipeline_name'] != args.pipeline):
            continue

        pipeline = msg.event.payload_field['pipeline_name']
        event = msg.event.name
        func = msg.event.payload_field['function_name']
        timestamp_ns = msg.default_clock_snapshot.ns_from_origin

        if event == 'libcamera:ipa_call_begin':
            if pipeline not in timestamps:
                timestamps[pipeline] = {}
            if func not in timestamps[pipeline]:
                timestamps[pipeline][func] = []
            timestamps[pipeline][func].append(timestamp_ns)

        if event == 'libcamera:ipa_call_end':
            ts = timestamps[pipeline][func].pop()
            key = f'{pipeline}:{func}'
            if key not in samples:
                samples[key] = []
            samples[key].append(timestamp_ns - ts)

    # Compute stats
    rows = []
    rows.append(['pipeline:function', 'min', 'max', 'mean', 'stddev'])
    for k, v in samples.items():
        mean = int(stats.mean(v))
        stddev = int(stats.stdev(v))
        minv = min(v)
        maxv = max(v)
        rows.append([k, str(minv), str(maxv), str(mean), str(stddev)])

    # Get maximum string width for every column
    widths = []
    for i in range(len(rows[0])):
        widths.append(max([len(row[i]) for row in rows]))

    # Print stats table
    for row in rows:
        fmt = [row[i].rjust(widths[i]) for i in range(1, 5)]
        print('{} {} {} {} {}'.format(row[0].ljust(widths[0]), *fmt))

if __name__ == '__main__':
    sys.exit(main(sys.argv))
camera</td><td class='sub right'>git repository hosting on libcamera.org</td></tr></table>
<table class='tabs'><tr><td>
<a href='/libcamera/jmondi/libcamera.git/?h=jmondi/android/pinephonepro'>summary</a><a href='/libcamera/jmondi/libcamera.git/refs/?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>refs</a><a href='/libcamera/jmondi/libcamera.git/log/Documentation/theme/theme.conf?h=jmondi/android/pinephonepro'>log</a><a class='active' href='/libcamera/jmondi/libcamera.git/tree/Documentation/theme/theme.conf?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>tree</a><a href='/libcamera/jmondi/libcamera.git/commit/Documentation/theme/theme.conf?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>commit</a><a href='/libcamera/jmondi/libcamera.git/diff/Documentation/theme/theme.conf?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>diff</a></td><td class='form'><form class='right' method='get' action='/libcamera/jmondi/libcamera.git/log/Documentation/theme/theme.conf'>
<input type='hidden' name='h' value='jmondi/android/pinephonepro'/><input type='hidden' name='id' value='7d8604128ab0f11da459fdb43fd8366620afe7f5'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/libcamera/jmondi/libcamera.git/tree/?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>root</a>/<a href='/libcamera/jmondi/libcamera.git/tree/Documentation?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>Documentation</a>/<a href='/libcamera/jmondi/libcamera.git/tree/Documentation/theme?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>theme</a>/<a href='/libcamera/jmondi/libcamera.git/tree/Documentation/theme/theme.conf?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>theme.conf</a></div><div class='content'>blob: ba25a19211c7954eccff5c3179eda5471c7fbfe2 (<a href='/libcamera/jmondi/libcamera.git/plain/Documentation/theme/theme.conf?h=jmondi/android/pinephonepro&amp;id=7d8604128ab0f11da459fdb43fd8366620afe7f5'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
</pre></td>
<td class='lines'><pre><code>[theme]
<span class="hl kwa">inherit</span> = basic
<span class="hl kwa">stylesheet</span> = css<span class="hl kwc">/theme.css</span>

[options]
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.1</a> (<a href='https://git-scm.com/'>git 2.18.0</a>) at 2024-12-24 23:02:20 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
