Mesa (main): gallium/tools: improve tracediff.sh argument handling

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 7 15:57:51 UTC 2021


Module: Mesa
Branch: main
Commit: 0112e3c7eacab09159f1a950648bd425dfb44f9b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0112e3c7eacab09159f1a950648bd425dfb44f9b

Author: Matti Hamalainen <ccr at tnsp.org>
Date:   Wed Apr 21 13:23:57 2021 +0300

gallium/tools: improve tracediff.sh argument handling

Implement better argument parsing/handling in tracediff.sh
so that the options passed to dump.py and sdiff are not required
to be positional.

Signed-off-by: Matti Hamalainen <ccr at tnsp.org>
Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10648>

---

 src/gallium/tools/trace/tracediff.sh | 143 +++++++++++++++++++++++++----------
 1 file changed, 102 insertions(+), 41 deletions(-)

diff --git a/src/gallium/tools/trace/tracediff.sh b/src/gallium/tools/trace/tracediff.sh
index 04c33298026..f5c8ae39db3 100755
--- a/src/gallium/tools/trace/tracediff.sh
+++ b/src/gallium/tools/trace/tracediff.sh
@@ -26,70 +26,131 @@
 
 set -e
 
+PROGNAME="$(basename "$0")"
+TRACEDUMP="${TRACEDUMP:-$(dirname "$0")/dump.py}"
+
 
+
+###
+### Helper functions
+###
 fatal()
 {
-	echo "ERROR: $1"
-	exit 1
+  echo "ERROR: $1"
+  exit 1
+}
+
+
+print_version()
+{
+  echo "TraceDiff - Compare two Gallium trace files"
+  echo "(C) Copyright 2011 Jose Fonseca"
+  echo ""
+}
+
+
+print_help()
+{
+  echo "Usage: ${PROGNAME} [options] <tracefile1> <tracefile2>"
+  echo ""
+  echo "  -h, --help         display this help and exit"
+  echo "  -V, --version      output version information and exit"
+  echo ""
+  echo "dump.py options:"
+  echo "  -N, --named        generate symbolic names for raw pointer values"
+  echo ""
+  echo "sdiff options:"
+  echo "  -d, --minimal      try hard to find a smaller set of changes"
+  echo ""
 }
 
 
 do_cleanup()
 {
-	if test -d "$FIFODIR"; then
-		rm -rf "$FIFODIR"
-	fi
+  if test -d "$TEMPDIR"; then
+    rm -rf "$TEMPDIR"
+  fi
 }
 
 
 strip_dump()
 {
-	INFILE="$1"
-	shift
-	OUTFILE="$1"
-	shift
-
-	python3 "$TRACEDUMP" --plain --suppress "$@" "$INFILE" \
-	| sed \
-		-e '/pipe_screen::is_format_supported/d' \
-		-e '/pipe_screen::get_\(shader_\)\?paramf\?/d' \
-		-e 's/\r$//g' \
-		-e 's/pipe = \w\+/pipe/g' \
-		-e 's/screen = \w\+/screen/g' \
-		-e 's/, /,\n\t/g' \
-		-e 's/) = /)\n\t= /' \
-	> "$OUTFILE"
+  INFILE="$1"
+  OUTFILE="$2"
+
+  python3 "$TRACEDUMP" --plain --suppress \
+    "${DUMP_ARGS[@]}" "$INFILE" \
+  | sed \
+    -e '/pipe_screen::is_format_supported/d' \
+    -e '/pipe_screen::get_\(shader_\)\?paramf\?/d' \
+    -e 's/\r$//g' \
+    -e 's/, /,\n\t/g' \
+    -e 's/) = /)\n\t= /' \
+  > "$OUTFILE"
 }
 
 
+###
 ### Main code starts
+###
 trap do_cleanup HUP INT TERM
-
-TRACEDUMP="${TRACEDUMP:-$(dirname "$0")/dump.py}"
-
-if test $# -lt 2; then
-	echo "Usage: $0 <tracefile1> <tracefile2> [extra dump.py args]"
-	exit 0
+DUMP_ARGS=()
+SDIFF_ARGS=()
+
+while test -n "$1"
+do
+  case "$1" in
+    --version|-V)
+      print_version
+      exit 0
+      ;;
+    --help|-h)
+      print_version
+      print_help
+      exit 0
+      ;;
+    -N|--named)
+      DUMP_ARGS+=("$1")
+      shift
+      ;;
+    -d|--minimal)
+      SDIFF_ARGS+=("$1")
+      shift
+      ;;
+    *)
+      if test "x$INFILE1" = "x"; then
+        INFILE1="$1";
+      elif test "x$INFILE2" = "x"; then
+        INFILE2="$1";
+      else
+        fatal "Too many input filenames specified."
+      fi
+      shift
+      ;;
+  esac
+done
+
+
+if test "x$INFILE1" = "x" -o "x$INFILE2" = "x"; then
+  print_help
+  fatal "Not enough input file(s) specified!"
 fi
 
-FIFODIR="$(mktemp -d)"
-FIFO1="${FIFODIR}/1"
-FIFO2="${FIFODIR}/2"
 
-mkfifo "$FIFO1" || fatal "Could not create fifo 1"
-mkfifo "$FIFO2" || fatal "Could not create fifo 2"
+TEMPDIR="$(mktemp -d)"
+TEMP1="${TEMPDIR}/1"
+TEMP2="${TEMPDIR}/2"
 
-INFILE1="$1"
-shift
-INFILE2="$1"
-shift
+mkfifo "$TEMP1" || fatal "Could not create fifo 1"
+mkfifo "$TEMP2" || fatal "Could not create fifo 2"
 
-strip_dump "$INFILE1" "$FIFO1" "$@" &
-strip_dump "$INFILE2" "$FIFO2" "$@" &
+strip_dump "$INFILE1" "$TEMP1" "$@" &
+strip_dump "$INFILE2" "$TEMP2" "$@" &
 
 sdiff \
-	--left-column \
-	--width="$(tput cols)" \
-	--speed-large-files \
-	"$FIFO1" "$FIFO2" \
+  --left-column \
+  --width="$(tput cols)" \
+  --speed-large-files \
+  "${SDIFF_ARGS[@]}" \
+  "$TEMP1" "$TEMP2" \
 | less



More information about the mesa-commit mailing list