[libcamera-devel,6/6] utils: libtuning: Get debug parameters from cli arguments
diff mbox series

Message ID 20221124113849.2193579-7-paul.elder@ideasonboard.com
State New
Headers show
Series
  • utils: tuning: Add per-module debugging
Related show

Commit Message

Paul Elder Nov. 24, 2022, 11:38 a.m. UTC
Get the debug parameters for enabling per-module debug from command line
arguments.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 utils/tuning/libtuning/libtuning.py | 40 ++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

Patch
diff mbox series

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.''')
+        module_list = [module.type for module in self.modules]
+        module_list.append('macbeth')
+        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