From patchwork Thu Oct 6 12:01:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17536 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 5B5FEC0DA4 for ; Thu, 6 Oct 2022 12:01:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2153562CFD; Thu, 6 Oct 2022 14:01:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665057686; bh=SSXu8Blp2anhjs1wkvhoOZvB0DTiqluNwgnzmvqUjQ0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tRUZ8tdHodCNqiHAKnGVxdJ8TAvZnOv70Duy9/A7kCTBgaqqzNZrG/tn5BvZdK4eO e4AK6sOj/5x2q5tXQmq/jnGV5/uoDAXGHt2aI6Xdiqn2z/nvE0vuobDNKzLaTEdSDf dvuEZxpkQ+7aymJRXXltpRDjHH0Hqx5J5Dm/n4dnZAqPOeJ4HZ2Y/cbEs0y6B1HKEx AelOIyvRbVrX4AP65x3BRQSzjLAglnfS9QwAp61nuDqdE9KuJ+F/O+yq50cMUM1DEb 9xiB1pnPqCi5pqof/8hhNNCjljWp3teLZJ0Kg9SO9oqHycBp+rfpYByOj4IuUHb2QY cFcFmFR6Cr9cQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30CBC62CF7 for ; Thu, 6 Oct 2022 14:01:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="m148hrkF"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BB24FA1C; Thu, 6 Oct 2022 14:01:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665057683; bh=SSXu8Blp2anhjs1wkvhoOZvB0DTiqluNwgnzmvqUjQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m148hrkFK6AKYM89dPpx9rJKlknMSXjXJaKt5mN4f7cNx6HjJmC0VAJSizmrDEGLm h64m72n0ndf5WxjgmylKE2JAfXdaup6fm/vn473IbkFghGB98kcSf/JVqvwd4VAhwB Qlbd5Wh3nGscIOEr27q4N12cMvMqHfTD2vqeq3IQ= To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 21:01:01 +0900 Message-Id: <20221006120105.3861831-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221006120105.3861831-1-paul.elder@ideasonboard.com> References: <20221006120105.3861831-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/7] utils: libtuning: parsers: Add raspberrypi 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a parser to libtuning for parsing configuration files that are the same format as raspberrypi's ctt's configuration files. Signed-off-by: Paul Elder --- utils/tuning/libtuning/parsers/__init__.py | 1 + .../libtuning/parsers/raspberrypi_parser.py | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 utils/tuning/libtuning/parsers/raspberrypi_parser.py diff --git a/utils/tuning/libtuning/parsers/__init__.py b/utils/tuning/libtuning/parsers/__init__.py index e69de29b..ba829161 100644 --- a/utils/tuning/libtuning/parsers/__init__.py +++ b/utils/tuning/libtuning/parsers/__init__.py @@ -0,0 +1 @@ +from libtuning.parsers.raspberrypi_parser import RaspberryPiParser diff --git a/utils/tuning/libtuning/parsers/raspberrypi_parser.py b/utils/tuning/libtuning/parsers/raspberrypi_parser.py new file mode 100644 index 00000000..1a7d4c0a --- /dev/null +++ b/utils/tuning/libtuning/parsers/raspberrypi_parser.py @@ -0,0 +1,82 @@ +from .parser import Parser + +import json +import numbers + +import libtuning.utils as utils + + +class RaspberryPiParser(Parser): + def __init__(self): + super().__init__() + + # The string in the 'disable' and 'plot' lists are formatted as + # 'rpi.{module_name}'. + # @brief Enumerate, as a module, @a listt if its value exists in @a dictt + # and it is the name of a valid module in @a modules + def enumerate_rpi_modules(listt, dictt, modules): + for x in listt: + name = x.replace('rpi.', '') + if name not in dictt: + continue + module = utils.getModuleByName(modules, name) + if module is not None: + yield module + + def _validMacbethOption(value): + if not isinstance(value, dict): + return False + + if list(value.keys()) != ['small', 'show']: + return False + + for val in value.values(): + if not isinstance(val, numbers.Number): + return False + + return True + + def __parse__(self, config_file, modules): + with open(config_file, 'r') as config_json: + config = json.load(config_json) + + disable = [] + for module in enumerate_rpi_modules(config['disable'], config, modules): + disable.append(module) + # Remove the disabled module's config too + config.pop(module.name) + config.pop('disable') + + # The raspberrypi config format has 'plot' map to a list of module + # names which should be plotted. libtuning has each module contain the + # plot information in itself so do this conversion. + + for module in enumerate_rpi_modules(config['plot'], config, modules): + # It's fine to set the value of a potentially disabled module, as + # the object still exists at this point + module.appendValue('debug', 'plot') + config.pop('plot') + + # Convert the keys from module name to module instance + + for module_name in config: + module = utils.getModuleByName(modules, module_name) + if module is not None and \ + module.validateConfig(config[module_name]): + new_config[module] = config.pop(module_name) + + new_config['general'] = {} + + if 'blacklevel' in config: + if not isinstance(config['blacklevel'], numbers.Number): + raise TypeError('Config "blacklevel" must be a number') + new_config['general']['blacklevel'] = config['blacklevel'] + + if 'macbeth' in config: + if not _validMacbethOption(config['macbeth']): + raise TypeError('Config "macbeth" must be a dict: {"small": number, "show": number}') + new_config['general']['macbeth'] = config['macbeth'] + else: + new_config['general']['macbeth'] = {'small': 0, 'show': 0} + + return new_config, disable