Copyright (c) . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. t/refs/?h=v0.5.0&id=962df634bd0afe12e6f38464f5e602cf1460c430'>refslogtreecommitdiff
blob: e38145d8e98e743ccd7880d6834892af60b85475 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import re
import sys
import os

if len(sys.argv) != 2:
    print("Usage: {} <infile>".format(sys.argv[0]))
    sys.exit()

infile = sys.argv[1]
insplit = os.path.splitext(infile)
outfile = insplit[0] + '_parsed' + insplit[1]

frame_re = re.compile(r'frame (\d+) started')

delays = {
    'Analogue Gain': 1,
    'Exposure': 2,
    'Vertical Blanking': 2
}

ctrl_action = {
    'Write': {},
    'Get': {},
    'Queue': {},
    'No-op': {}
}

ctrl_re = {
    'Write': re.compile(r'Setting (.*?) to (\d+) at index (\d+)'),
    'No-op': re.compile(r'Queue is empty, (.*?) (.*?) (.*?)'),
    'Get': re.compile(r'Reading (.*?) to (\d+) at index (\d+)'),
    'Queue': re.compile(r'Queuing (.*?) to (\d+) at index (\d+)')
}

frame_num = -1

max_delay = 0
for k, d in delays.items():
    if max_delay < d:
        max_delay = d

with open(infile) as f:
    lines = f.readlines()

for line in lines:
    r = frame_re.search(line)
    if r:
        frame_num = int(r.group(1))

    for (key, re) in ctrl_re.items():
        r = re.search(line)
        if r:
            ctrl_action[key][(frame_num, r.group(1))] = (r.group(2), r.group(3))

with open(outfile, 'wt') as f:
    queueIndex = 1
    f.write('{:<10}{:<15}{:<12}{:<18}{}\n'.format('Frame', 'Action', 'Gain', 'Exposure', 'Vblank'))
    for frame in range(0, frame_num + 1):
        for (k, a) in ctrl_action.items():
            str = '{:<10}{:<10}'.format(frame, k)

            for c in delays.keys():
                # Tabulate all results
                str += '{:>5} {:<10}'.format(a[(frame, c)][0] if (frame, c) in a.keys() else '---',
                                             '[' + (a[(frame, c)][1] if (frame, c) in a.keys() else '-') + ']')

            f.write(str.strip() + '\n')

# Test the write -> get matches the set delay.
for (frame, c) in ctrl_action['Write'].keys():
    set_value = ctrl_action['Write'][(frame, c)][0]
    delay_frame = frame + delays[c]
    if (delay_frame <= frame_num):
        if (delay_frame, c) in ctrl_action['Get']:
            get_value = ctrl_action['Get'][(delay_frame, c)][0]
            if get_value != set_value:
                print('Error: {} written at frame {} to value {} != {} at frame {}'
                      .format(c, frame, set_value, get_value, delay_frame))
        else:
            print('Warning: {} written at frame {} to value {} did not get logged on frame {} - dropped frame?'
                  .format(c, frame, set_value, delay_frame))

# Test the queue -> write matches the set delay.
for (frame, c) in ctrl_action['Queue'].keys():
    set_value = ctrl_action['Queue'][(frame, c)][0]
    delay_frame = frame + max_delay - delays[c] + 1
    if (delay_frame <= frame_num):
        if (delay_frame, c) in ctrl_action['Write']:
            write_value = ctrl_action['Write'][(delay_frame, c)][0]
            if write_value != set_value:
                print('Info: {} queued at frame {} to value {} != {} written at frame {}'
                      ' - lagging behind or double queue on a single frame!'
                      .format(c, frame, set_value, write_value, delay_frame))
        else:
            print('Warning: {} queued at frame {} to value {} did not get logged on frame {} - dropped frame?'
                  .format(c, frame, set_value, delay_frame))

# Test the get -> write matches the set delay going backwards.
for (frame, c) in ctrl_action['Get'].keys():
    get_value = ctrl_action['Get'][(frame, c)][0]
    delay_frame = frame - delays[c]
    if (delay_frame >= 6):
        if (delay_frame, c) in ctrl_action['Write']:
            write_value = ctrl_action['Write'][(delay_frame, c)][0]
            if get_value != write_value:
                print('Info: {} got at frame {} to value {} != {} written at frame {}'
                      ' - lagging behind or double queue on a single frame!'
                      .format(c, frame, get_value, write_value, delay_frame))
        else:
            print('Warning: {} got at frame {} to value {} did not get written on frame {}'
                  .format(c, frame, get_value, delay_frame))