[libcamera-devel] utils: Provide lcdebug helper script
diff mbox series

Message ID 20220926152514.479598-1-kieran.bingham@ideasonboard.com
State New
Headers show
Series
  • [libcamera-devel] utils: Provide lcdebug helper script
Related show

Commit Message

Kieran Bingham Sept. 26, 2022, 3:25 p.m. UTC
Provide a utility script to make it easy to debug issues
using libcamera. The lcdebug can be prefixed to enable the
libcamera debug levels by default, while still allow customising them.

It makes it easy to identify the available debug levels from a libcamera
source tree with the -h/--help option.

Finally, it facilitates stracing ioctls to see what operations are
performed during the running of a libcamera based application to highlight
kernel interactions and calls.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---

Example usage:

  ./utils/lcdebug -s qcam -c1 -s pixelformat=RGB565

To help debugging pixel format selection issues.

This could be extended with a '-g' in the future to wrap with GDB too?


 utils/lcdebug | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100755 utils/lcdebug

Patch
diff mbox series

diff --git a/utils/lcdebug b/utils/lcdebug
new file mode 100755
index 000000000000..5477dba4cbe0
--- /dev/null
+++ b/utils/lcdebug
@@ -0,0 +1,45 @@ 
+#!/bin/bash
+
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Support debugging libcamera commands and applications.
+
+# We default to enabling the most debug
+# (that's why we're being used right)
+
+FILTER="*"
+LEVEL="0"
+STRACE=""
+
+while [[ $# -gt 0 ]]
+do
+case $1 in
+    -x)
+        set -x;
+        shift;
+        ;;
+    -s|--strace)
+	STRACE="strace -e ioctl -f --"
+	shift;
+	;;
+    -f|--filter)
+	FILTER="$2";
+	shift; shift;
+        ;;
+    -l|--level)
+	LEVEL="$2";
+	shift; shift;
+        ;;
+    -h|--help)
+	echo "The following filters are available:"
+	git grep "^LOG_DEFINE_CATEGORY" | \
+		awk -F '[()]' '{print $2}' | \
+		sort
+	exit
+	;;
+    *|--)  # unknown option, The rest belongs to the command
+	break;
+        ;;
+esac
+done
+
+LIBCAMERA_LOG_LEVELS=$FILTER:$LEVEL $STRACE "${@}"