[libcamera-devel] [PATCH 6/6] utils: libtuning: Get debug parameters from cli arguments

Dan Scally dan.scally at ideasonboard.com
Sat May 4 23:24:53 CEST 2024


Hi Paul

On 24/11/2022 11:38, Paul Elder wrote:
> Get the debug parameters for enabling per-module debug from command line
> arguments.
>
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
>   utils/tuning/libtuning/libtuning.py | 40 ++++++++++++++++++++++++++---
>   1 file changed, 36 insertions(+), 4 deletions(-)
>
> diff --git a/utils/tuning/libtuning/libtuning.py b/utils/tuning/libtuning/libtuning.py
> index 469e6940..6d616ddb 100644
> --- a/utils/tuning/libtuning/libtuning.py
> +++ b/utils/tuning/libtuning/libtuning.py
> @@ -5,6 +5,7 @@
>   # libtuning.py - An infrastructure for camera tuning tools
>   
>   import argparse
> +from pathlib import Path
>   
>   import libtuning as lt
>   import libtuning.utils as utils
> @@ -20,10 +21,6 @@ class Color(IntEnum):
>       B = 3
>   
>   
> -class Debug(Enum):
> -    Plot = 1
> -
> -
>   # @brief What to do with the leftover pixels after dividing them into ALSC
>   #        sectors, when the division gradient is uniform
>   # @var Float Force floating point division so all sectors divide equally
> @@ -157,6 +154,23 @@ class Tuner(object):
>           # 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('-dd', '--debug_dir', type=str, default=None,
> +                            help='''Debug output directory (optional).
> +                                    If the directory does not exist, it will be
> +                                    created (including parent directories).  If
> +                                    the directory already exists, any existing
> +                                    contents will be overwritten.''')

I don't think this will create parent directories at present, as when you call debug_dir.mkdir() the 
default behaviour [1] is not to create parent directories.


[1] https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir

> +        module_list = [module.type for module in self.modules]
> +        module_list.append('macbeth')


Is this still relevant?

> +        module_list.sort()
> +        parser.add_argument('-do', '--debug_opt', type=str, default='',
> +                            help=f'''Debug option string (optional).
> +                                     Comma-separated (without spaces) list of module names
> +                                     for which debug output should be enabled. If this
> +                                     option is not provided but --debug_dir is, then all
> +                                     modules will have debug output enabled. This option
> +                                     will not do anything if --debug_dir is not specified.
> +                                     Available modules: {module_list}''')
>           return parser.parse_args(argv[1:])
>   
>       def run(self, argv):
> @@ -181,11 +195,29 @@ class Tuner(object):
>               if module in self.modules:
>                   self.modules.remove(module)
>   
> +        # Prepare debug
> +        module_debug_list = args.debug_opt.split(',')
> +        if '' in module_debug_list:
> +            module_debug_list.remove('')
> +
> +        if args.debug_dir is not None:
> +            debug_dir = Path(args.debug_dir)
> +            if not debug_dir.is_dir():
> +                debug_dir.mkdir()
> +
> +        # Validate modules and set debug
>           for module in self.modules:
>               if not module.validate_config(self.config):
>                   eprint(f'Config is invalid for module {module.type}')
>                   return -1
>   
> +            if args.debug_dir is not None and \
> +               (len(module_debug_list) == 0 or module.type in module_debug_list):
> +                module_debug_dir = debug_dir / module.type
> +                if not module_debug_dir.is_dir():
> +                    module_debug_dir.mkdir()
> +                module.enable_debug(module_debug_dir)
> +
>           has_lsc = any(isinstance(m, lt.modules.lsc.LSC) for m in self.modules)
>           # Only one LSC module allowed
>           has_only_lsc = has_lsc and len(self.modules) == 1


More information about the libcamera-devel mailing list