From patchwork Tue Nov 29 05:33:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17905 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 9C7F0BE08B for ; Tue, 29 Nov 2022 05:33:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DDCDD6333F; Tue, 29 Nov 2022 06:33:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669700023; bh=86DQt6YHZKxFRsOn+dGB7Nmhmi3E0D7IfPCUkr8iS4g=; 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=HsIG+eZfmT0jDHPWhKcGv89uKhIbOlFNM2IPyN3euLw2QrOKfGtHt4rMLv+GMaDKK RgX24kLnk9aDglcKCudqt3gXayjXjEfWap0LbZh6bXd3zZy/GZWQs5OgEn8fDlVmzs XSnFSo+xu82xh/WRYxC+oKKNhm+BVYys4bTVG2o9AORyNW9Yunp6pcJeITC8f32twC YgOQRrghi1J71pk/JzJzrnRayFbQSscAcf7CpbIAYnW3MSZ8GHAzoemLeZqHzlhmxm +7WXEnRc6q8he4x433HmIG6PZ7iIDETDj5GVnNYif2ZvoFlsWtM1ActXQ3AxpoVBC1 M+g84TrWdQuEA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A810A63334 for ; Tue, 29 Nov 2022 06:33:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BDv4KKyt"; dkim-atps=neutral Received: from pyrite.tail37cf.ts.net (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77C9E4E6; Tue, 29 Nov 2022 06:33:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1669700021; bh=86DQt6YHZKxFRsOn+dGB7Nmhmi3E0D7IfPCUkr8iS4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDv4KKytPlWg+SrjLy+Hc8K2O0lQshRmERCytxUrdD51Y4xo2LRMiOk/0xPqsjj6o /M9kxqAerm8wpEf7qCuALhwJjolnlFqtHGONSHVa6+O6dc7uOJilSsm2jD1pN17xIc aMVSDJE7YDVWotdd30aR3J8zDC1sO5ueSrZj9yCQ= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Nov 2022 14:33:26 +0900 Message-Id: <20221129053326.2858347-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221129053326.2858347-1-paul.elder@ideasonboard.com> References: <20221129053326.2858347-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] utils: libtuning: Add logging parameters to argparse 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 command line arguments for log levels and log output file. Signed-off-by: Paul Elder --- utils/tuning/libtuning/libtuning.py | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/utils/tuning/libtuning/libtuning.py b/utils/tuning/libtuning/libtuning.py index d34d98ab..b2c40ba4 100644 --- a/utils/tuning/libtuning/libtuning.py +++ b/utils/tuning/libtuning/libtuning.py @@ -6,6 +6,7 @@ import argparse from pathlib import Path +import sys import libtuning as lt from libtuning.logger import Logger @@ -150,10 +151,24 @@ class Tuner(object): # options, so simply return an empty configuration if none is provided. parser.add_argument('-c', '--config', type=str, default='', help='Config file (optional)') - # \todo Check if we really need this or if stderr is good enough, or if - # we want a better logging infrastructure with log levels - parser.add_argument('-l', '--log', type=str, default=None, - help='Output log file (optional)') + parser.add_argument('-l', '--log', type=str, default=sys.stderr, + help='Output log file (optional). Default is stderr.') + parser.add_argument('-ll', '--log_levels', type=str, default='', + help='''Output log levels (optional). + A comma-separated list of module names and + their log levels (in integer form, where + debug=0, info=1, warn=2, error=3, and + fatal=4), in the format: "{module name}:{log + level},{module name}:{log_level}...", and so + on. Any module that is not specified will use the + default log level, or the default can be + specified with the log name "*". For the + purposes of logging, module names are the + same as class names, or the file name for + components that are not classes. This + parameter can also be simply set to a + single integer to set the log levels for + all components.''') parser.add_argument('-dd', '--debug_dir', type=str, default=None, help='''Debug output directory (optional). If the directory does not exist, it will be @@ -205,6 +220,12 @@ class Tuner(object): if not debug_dir.is_dir(): debug_dir.mkdir() + # Prepare logging + if args.log is not sys.stderr: + Logger.log_file = open(args.log, mode='a') + + Logger.set_log_levels(args.log_levels) + # Validate modules and set debug for module in self.modules: if not module.validate_config(self.config): @@ -237,4 +258,7 @@ class Tuner(object): self.generator.write(args.output, self.output, self.output_order) + if Logger.log_file is not sys.stderr: + Logger.log_file.close() + return 0