From patchwork Mon Mar 1 13:31:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11414 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3BC7DBD1F1 for ; Mon, 1 Mar 2021 13:32:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A5F168A96; Mon, 1 Mar 2021 14:32:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="t13eMd1B"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4594F68A7F for ; Mon, 1 Mar 2021 14:32:07 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id f12so12359473wrx.8 for ; Mon, 01 Mar 2021 05:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a67QPnmZ/7naEtWkLMtX0KKvq0VldgvuT1P9Ujvt2t0=; b=t13eMd1B+9jr8JL6hnpZPpV56DEfUV47YANyp0XbeozyeWbCsgPWUnQC3Vftmb78dW 4CKvc3XXoCvP8pSAEciw3THHbrHtCD3P7yQOfP1r9yu9FA2b9aWt+WRtUyslHMucV39F 8o8CCVpTU1Q8Wl/hAah3AQPCPX7n0ljvsDz0JKjw33vbci0gloNh/FbG2onCM4mj4Ysw WTjo9Tb2izCZvIaPL9TjC26Tbemhbrcss1HjZe5OivXQVXh7Af2SfcsAc3ait/K3D2cr VfdgliMjitXRiTUby88Mbg096HMHyq4A0o+RTBHRvOXcP8Z7wip1fmaUvpigB4TPcIYS EQmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a67QPnmZ/7naEtWkLMtX0KKvq0VldgvuT1P9Ujvt2t0=; b=jo4glPd1z47JO9QIGJHgPs7xF2a6QkDR7h8RyeP95Xe4IlpMmjzWPIODWkML9PL9A2 m5xqGYckWa6GnBkmufJ2QNTeL2jCI6Wp4GcNnvHIRygOJlfLvaOSuZ5NucbM0aLyfuPx r4GWImNLoA3WpxGW8N5wolbQ9ixqa/5QRpIHifLxcYGpc1NHtP9ckJr1llg8c1+s1FbU 0TRa7yPsZ+0SHmOqMLXZgPBwOz/r4hiaGa15U7ZY+Vw9o2y2I6BgqrLvhsoaiJ+PC9wM 8q6a+/NAoCaroA7lBnUOYJl/eM66qFYAYFwucyybBu6CxoX6m7EbXsxJbgz+4EhySFqn P+AA== X-Gm-Message-State: AOAM5335iIKjPLuoIonLYtA/ueRkgiFCkDXZy3k1ylcryBAX2Crw1k+R hZIOC9rWm5h1ALsPDzW46GSke5cGAUTvxYoC X-Google-Smtp-Source: ABdhPJxGMcMmTNyxy7Rbdyw2Uy0Xptx9qEa4cJjB7xm8ZH/4DOl/1qyhrkNU4oM3f77Vh+axZ6IHGA== X-Received: by 2002:a05:6000:114b:: with SMTP id d11mr16477710wrx.318.1614605526480; Mon, 01 Mar 2021 05:32:06 -0800 (PST) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id a75sm11263630wme.10.2021.03.01.05.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 05:32:06 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 13:31:56 +0000 Message-Id: <20210301133159.4179129-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210301133159.4179129-1-naush@raspberrypi.com> References: <20210301133159.4179129-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/5] utils: raspberrypi: Add a DelayedControls log parser X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This script will parse log output from the DelayedControls helper, when enabled with: LIBCAMERA_LOG_LEVELS=DelayedControls:0 It tabulates all control queuing/writing/getting per frame and warns about potential issues related to frame delays not being account for, or writes that are lagging behind or missed. Run with the following command: python3 ./delayedctrls_parse.py Signed-off-by: Naushir Patuck Tested-by: David Plowman Acked-by: Paul Elder --- utils/raspberrypi/delayedctrls_parse.py | 111 ++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 utils/raspberrypi/delayedctrls_parse.py diff --git a/utils/raspberrypi/delayedctrls_parse.py b/utils/raspberrypi/delayedctrls_parse.py new file mode 100644 index 000000000000..3965b86daaaf --- /dev/null +++ b/utils/raspberrypi/delayedctrls_parse.py @@ -0,0 +1,111 @@ +import re +import sys +import os + +if len(sys.argv) != 2: + print("Usage: {} ".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('frame (\d+) started') + +delays = { + 'Analogue Gain': 1, + 'Exposure': 2, + 'Vertical Blanking': 2 +} + +ctrl_action = { + 'Write': {}, + 'Get': {}, + 'Queue': {}, + 'No-op': {} +} + +ctrl_re = { + 'Write': re.compile('Setting (.*?) to (\d+) at index (\d+)'), + 'No-op': re.compile('Queue is empty, (.*?) (.*?) (.*?)'), + 'Get': re.compile('Reading (.*?) to (\d+) at index (\d+)'), + 'Queue': re.compile('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))