• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2##########################################################################
3#
4# Copyright 2011 Jose Fonseca
5# All Rights Reserved.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24#
25##########################################################################/
26
27set -e
28
29PROGNAME="$(basename "$0")"
30TRACEDUMP="${TRACEDUMP:-$(dirname "$0")/dump.py}"
31
32
33
34###
35### Helper functions
36###
37fatal()
38{
39  echo "ERROR: $1"
40  exit 1
41}
42
43
44print_version()
45{
46  echo "TraceDiff - Compare two Gallium trace files"
47  echo "(C) Copyright 2011 Jose Fonseca"
48  echo ""
49}
50
51
52print_help()
53{
54  echo "Usage: ${PROGNAME} [options] <tracefile1> <tracefile2>"
55  echo ""
56  echo "  -h, --help         display this help and exit"
57  echo "  -V, --version      output version information and exit"
58  echo ""
59  echo "  -m, --meld         use Meld for diffing (default is sdiff)"
60  echo ""
61  echo "dump.py options:"
62  echo "  -N, --named        generate symbolic names for raw pointer values"
63  echo "  -M, --method-only  output only call names without arguments"
64  echo ""
65  echo "sdiff options:"
66  echo "  -d, --minimal      try hard to find a smaller set of changes"
67  echo ""
68}
69
70
71do_cleanup()
72{
73  if test -d "$TEMPDIR"; then
74    rm -rf "$TEMPDIR"
75  fi
76}
77
78
79strip_dump()
80{
81  INFILE="$1"
82  OUTFILE="$2"
83
84  python3 "$TRACEDUMP" --plain --suppress --ignore-junk \
85    "${DUMP_ARGS[@]}" "$INFILE" \
86  | sed \
87    -e 's/\r$//g' \
88    -e 's/, /,\n\t/g' \
89    -e 's/) = /)\n\t= /' \
90  > "$OUTFILE"
91}
92
93
94###
95### Main code starts
96###
97trap do_cleanup HUP INT TERM
98DUMP_ARGS=()
99SDIFF_ARGS=()
100USE_MELD=0
101
102while test -n "$1"
103do
104  case "$1" in
105    --version|-V)
106      print_version
107      exit 0
108      ;;
109    --help|-h)
110      print_version
111      print_help
112      exit 0
113      ;;
114    -N|--named|-M|--method-only)
115      DUMP_ARGS+=("$1")
116      shift
117      ;;
118    -d|--minimal)
119      SDIFF_ARGS+=("$1")
120      shift
121      ;;
122    -m|--meld)
123      USE_MELD=1
124      shift
125      ;;
126    *)
127      if test "x$INFILE1" = "x"; then
128        INFILE1="$1";
129      elif test "x$INFILE2" = "x"; then
130        INFILE2="$1";
131      else
132        fatal "Too many input filenames specified."
133      fi
134      shift
135      ;;
136  esac
137done
138
139
140if test "x$INFILE1" = "x" -o "x$INFILE2" = "x"; then
141  print_help
142  fatal "Not enough input file(s) specified!"
143fi
144
145
146TEMPDIR="$(mktemp -d)"
147TEMP1="${TEMPDIR}/1"
148TEMP2="${TEMPDIR}/2"
149
150if test $USE_MELD -ne 0; then
151  strip_dump "$INFILE1" "$TEMP1" "$@" || fatal "Could not dump '${INFILE1}."
152  strip_dump "$INFILE2" "$TEMP2" "$@" || fatal "Could not dump '${INFILE2}."
153  meld "$TEMP1" "$TEMP2"
154else
155  mkfifo "$TEMP1" || fatal "Could not create fifo 1"
156  mkfifo "$TEMP2" || fatal "Could not create fifo 2"
157
158  strip_dump "$INFILE1" "$TEMP1" "$@" &
159  strip_dump "$INFILE2" "$TEMP2" "$@" &
160
161  sdiff \
162    --left-column \
163    --width="$(tput cols)" \
164    --speed-large-files \
165    "${SDIFF_ARGS[@]}" \
166    "$TEMP1" "$TEMP2" \
167  | less
168fi
169