Patch Detail
Show a patch.
GET /api/1.1/patches/21541/?format=api
{ "id": 21541, "url": "https://patchwork.libcamera.org/api/1.1/patches/21541/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21541/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20241008153031.429906-4-stefan.klug@ideasonboard.com>", "date": "2024-10-08T15:29:41", "name": "[v3,3/7] utils: Add script to generate control_ids_debug.yaml", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "b8497e530cd48c21e0c141a23039313f1dcf6972", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21541/mbox/", "series": [ { "id": 4667, "url": "https://patchwork.libcamera.org/api/1.1/series/4667/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4667", "date": "2024-10-08T15:29:38", "name": "Add support for IPA debugging metadata", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4667/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21541/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21541/checks/", "tags": {}, "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 E2866BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 8 Oct 2024 15:30:47 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9E2726536E;\n\tTue, 8 Oct 2024 17:30:47 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9A89B65369\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 8 Oct 2024 17:30:44 +0200 (CEST)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:d:f30b:aa60:fabf])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EDDC1514;\n\tTue, 8 Oct 2024 17:29:07 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"dvAxXQCp\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728401348;\n\tbh=YV95Co6rlo7QJYIhiN997feMCPkkLZnyIwy0hYKcxaQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=dvAxXQCpWXTRQXQABLzKbYoZFMqA+1sswaxR/Lwxq6ITaOdMnXZH+S7zLcsKxmxk2\n\tPtgLq66vfDmMon1v/waQfvUm33z06KGoASH4bqCPC2KAASJcIlb+ukomobwJGQt/R6\n\tyqOyYObgp+Al6qvGvVKI+G/wog06YIh9YBpM6hnc=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v3 3/7] utils: Add script to generate control_ids_debug.yaml", "Date": "Tue, 8 Oct 2024 17:29:41 +0200", "Message-ID": "<20241008153031.429906-4-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20241008153031.429906-1-stefan.klug@ideasonboard.com>", "References": "<20241008153031.429906-1-stefan.klug@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "For flexible debugging it is helpful to minimize the roundtrip time.\nThis script parses the source tree and looks for usages of\n\nset<type>(controls::debug::Something,\n\nand adds (or removes) the controls as necessary from the yaml\ndescription. It is meant to be used during development to ease the\ncreation of the correct yaml entries.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\nChanges in v3:\n- Remove superfluous comma and args variable\n- Default to ruamel.yaml instead of ruyaml\n- Small fixes on layout/comments\n\nChanges in v2:\n- Search only until the first comma of the set() call, to allow\n linebreaks there.\n- Support ruamel.yaml as fallback\n- Rename output to ctrl_file\n- Add \"generated by\" comment in yaml file\n---\n utils/gen-debug-controls.py | 162 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 162 insertions(+)\n create mode 100755 utils/gen-debug-controls.py", "diff": "diff --git a/utils/gen-debug-controls.py b/utils/gen-debug-controls.py\nnew file mode 100755\nindex 000000000000..025850731c0b\n--- /dev/null\n+++ b/utils/gen-debug-controls.py\n@@ -0,0 +1,162 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Copyright (C) 2024, Google Inc.\n+#\n+# Author: Stefan Klug <stefan.klug@ideasonboard.com>\n+#\n+# This script looks for occurrences of the debug metadata controls in the source\n+# tree and updates src/libcamera/control_ids_debug.yaml accordingly. It is meant\n+# to be used during development to ease updating of the yaml file while\n+# debugging.\n+\n+import argparse\n+import logging\n+import os\n+import re\n+import sys\n+from dataclasses import dataclass\n+from pathlib import Path\n+\n+logger = logging.getLogger(__name__)\n+logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')\n+\n+try:\n+ import ruamel.yaml as ruyaml\n+except:\n+ logger.error(\n+ f'Failed to import ruamel.yaml. Please install the ruamel.yaml package.')\n+ sys.exit(1)\n+\n+@dataclass\n+class FoundMatch:\n+ file: os.PathLike\n+ whole_match: str\n+ line: int\n+ type: str\n+ name: str\n+ size: str = None\n+\n+\n+def get_control_name(control):\n+ k = list(control.keys())\n+ if len(k) != 1:\n+ raise Exception(f\"Can't handle control entry with {len(k)} keys\")\n+ return k[0]\n+\n+\n+def find_debug_controls(dir):\n+ extensions = ['.cpp', '.h']\n+ files = [p for p in dir.rglob('*') if p.suffix in extensions]\n+\n+ # The following regex was tested on\n+ # set<Span<type>>( controls::debug::something , static_cast<type>(var) )\n+ # set<>( controls::debug::something , static_cast<type>(var) )\n+ # set( controls::debug::something , static_cast<type> (var) )\n+ exp = re.compile(r'set' # set function\n+ r'(?:\\<((?:[^)(])*)\\>)?' # followed by a optional template param\n+ r'\\(\\s*controls::debug::(\\w+)\\s*,' # referencing a debug control\n+ )\n+ matches = []\n+ for p in files:\n+ with p.open('r') as f:\n+ for idx, line in enumerate(f):\n+ match = exp.search(line)\n+ if match:\n+ m = FoundMatch(file=p, line=idx, type=match.group(1),\n+ name=match.group(2), whole_match=match.group(0))\n+ if m.type is not None and m.type.startswith('Span'):\n+ # Simple span type detection treating the last word\n+ # inside <> as type.\n+ r = re.match(r'Span<(?:.*\\s+)(.*)>', m.type)\n+ m.type = r.group(1)\n+ m.size = '[n]'\n+ matches.append(m)\n+ return matches\n+\n+\n+def main(argv):\n+ parser = argparse.ArgumentParser(\n+ description='Automatically updates control_ids_debug.yaml')\n+ parser.parse_args(argv[1:])\n+\n+ yaml = ruyaml.YAML()\n+ root_dir = Path(__file__).resolve().parent.parent\n+ ctrl_file = root_dir.joinpath('src/libcamera/control_ids_debug.yaml')\n+\n+ matches = find_debug_controls(root_dir.joinpath('src'))\n+\n+ doc = yaml.load(ctrl_file)\n+\n+ controls = doc['controls']\n+\n+ # Create a map of names in the existing yaml for easier updating.\n+ controls_map = {}\n+ for control in controls:\n+ for k, v in control.items():\n+ controls_map[k] = v\n+\n+ obsolete_names = list(controls_map.keys())\n+\n+ for m in matches:\n+ if not m.type:\n+ p = m.file.relative_to(Path.cwd(), walk_up=True)\n+ logger.warning(\n+ f'{p}:{m.line + 1}: Failed to deduce type from {m.whole_match} ... skipping')\n+ continue\n+\n+ p = m.file.relative_to(root_dir)\n+ desc = {'type': m.type,\n+ 'description': f'Debug control {m.name} found in {p}:{m.line}'}\n+ if m.size is not None:\n+ desc['size'] = m.size\n+\n+ if m.name in controls_map:\n+ # Can't use == for modified check because of the special yaml dicts.\n+ update_needed = False\n+ if list(controls_map[m.name].keys()) != list(desc.keys()):\n+ update_needed = True\n+ else:\n+ for k, v in controls_map[m.name].items():\n+ if v != desc[k]:\n+ update_needed = True\n+ break\n+\n+ if update_needed:\n+ logger.info(f\"Update control '{m.name}'\")\n+ controls_map[m.name].clear()\n+ controls_map[m.name].update(desc)\n+\n+ obsolete_names.remove(m.name)\n+ else:\n+ logger.info(f\"Add control '{m.name}'\")\n+ insert_before = len(controls)\n+ for idx, control in enumerate(controls):\n+ if get_control_name(control).lower() > m.name.lower():\n+ insert_before = idx\n+ break\n+ controls.insert(insert_before, {m.name: desc})\n+\n+ # Remove elements from controls without recreating the list (to keep\n+ # comments etc.).\n+ idx = 0\n+ while idx < len(controls):\n+ name = get_control_name(controls[idx])\n+ if name in obsolete_names:\n+ logger.info(f\"Remove control '{name}'\")\n+ controls.pop(idx)\n+ else:\n+ idx += 1\n+\n+ with ctrl_file.open('w') as f:\n+ # Ruyaml looses the header.\n+ f.write((\"# SPDX-License-Identifier: LGPL-2.1-or-later\\n\"\n+ \"#\\n\"\n+ \"# This file was generated by utils/gen-debug-controls.py\\n\"\n+ \"#\\n\"))\n+ yaml.dump(doc, f)\n+\n+ return 0\n+\n+\n+if __name__ == '__main__':\n+ sys.exit(main(sys.argv))\n", "prefixes": [ "v3", "3/7" ] }