/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * camera-sensor.cpp - Camera sensor tests */ #include #include #include #include #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/v4l2_subdevice.h" #include "test.h" using namespace std; using namespace libcamera; class CameraSensorTest : public Test { protected: int init() { enumerator_ = DeviceEnumerator::create(); if (!enumerator_) { cerr << "Failed to create device enumerator" << endl; return TestFail; } if (enumerator_->enumerate()) { cerr << "Failed to enumerate media devices" << endl; return TestFail; } DeviceMatch dm("vimc"); media_ = enumerator_->search(dm); if (!media_) { cerr << "Unable to find \'vimc\' media device node" << endl; return TestSkip; } MediaEntity *entity = media_->getEntityByName("Sensor A"); if (!entity) { cerr << "Unable to find media entity 'Sensor A'" << endl; return TestFail; } sensor_ = new CameraSensor(entity); if (sensor_->init() < 0) { cerr << "Unable to initialise camera sensor" << endl; return TestFail; } return TestPass; } int run() { if (sensor_->model() != "Sensor A") { cerr << "Incorrect sensor model '" << sensor_->model() << "'" << endl; return TestFail; } const std::vector &codes = sensor_->mbusCodes(); auto iter = std::find(codes.begin(), codes.end(), MEDIA_BUS_FMT_ARGB8888_1X32); if (iter == codes.end()) { cerr << "Sensor doesn't support ARGB8888_1X32" << endl; return TestFail; } const std::vector &sizes = sensor_->sizes(*iter); auto iter2 = std::find(sizes.begin(), sizes.end(), Size(4096, 2160)); if (iter2 == sizes.end()) { cerr << "Sensor doesn't support 4096x2160" << endl; return TestFail; } const Size &resolution = sensor_->resolution(); if (resolution != Size(4096, 2160)) { cerr << "Incorrect sensor resolution " << resolution.toString() << endl; return TestFail; } /* Use an invalid format and make sure it's not selected. */ V4L2SubdeviceFormat format = sensor_->getFormat({ 0xdeadbeef, MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_BGR888_1X24 }, Size(1024, 768)); if (format.mbus_code != MEDIA_BUS_FMT_SBGGR10_1X10 || format.size != Size(4096, 2160)) { cerr << "Failed to get a suitable format, expected 4096x2160-0x" << utils::hex(MEDIA_BUS_FMT_SBGGR10_1X10) << ", got " << format.toString() << endl; return TestFail; } return TestPass; } void cleanup() { delete sensor_; } private: std::unique_ptr enumerator_; std::shared_ptr media_; CameraSensor *sensor_; }; TEST_REGISTER(CameraSensorTest) 2c7663ff6c516141eb714c2a5dd8e'>analyze-ipa-trace.py
blob: 50fbbf4299705dfc9b0ee774e0a03e1f5b754dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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))