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 \ 85 "${DUMP_ARGS[@]}" "$INFILE" \ 86 | sed \ 87 -e '/pipe_screen::is_format_supported/d' \ 88 -e '/pipe_screen::get_\(shader_\)\?paramf\?/d' \ 89 -e 's/\r$//g' \ 90 -e 's/, /,\n\t/g' \ 91 -e 's/) = /)\n\t= /' \ 92 > "$OUTFILE" 93} 94 95 96### 97### Main code starts 98### 99trap do_cleanup HUP INT TERM 100DUMP_ARGS=() 101SDIFF_ARGS=() 102USE_MELD=0 103 104while test -n "$1" 105do 106 case "$1" in 107 --version|-V) 108 print_version 109 exit 0 110 ;; 111 --help|-h) 112 print_version 113 print_help 114 exit 0 115 ;; 116 -N|--named|-M|--method-only) 117 DUMP_ARGS+=("$1") 118 shift 119 ;; 120 -d|--minimal) 121 SDIFF_ARGS+=("$1") 122 shift 123 ;; 124 -m|--meld) 125 USE_MELD=1 126 shift 127 ;; 128 *) 129 if test "x$INFILE1" = "x"; then 130 INFILE1="$1"; 131 elif test "x$INFILE2" = "x"; then 132 INFILE2="$1"; 133 else 134 fatal "Too many input filenames specified." 135 fi 136 shift 137 ;; 138 esac 139done 140 141 142if test "x$INFILE1" = "x" -o "x$INFILE2" = "x"; then 143 print_help 144 fatal "Not enough input file(s) specified!" 145fi 146 147 148TEMPDIR="$(mktemp -d)" 149TEMP1="${TEMPDIR}/1" 150TEMP2="${TEMPDIR}/2" 151 152if test $USE_MELD -ne 0; then 153 strip_dump "$INFILE1" "$TEMP1" "$@" || fatal "Could not dump '${INFILE1}." 154 strip_dump "$INFILE2" "$TEMP2" "$@" || fatal "Could not dump '${INFILE2}." 155 meld "$TEMP1" "$TEMP2" 156else 157 mkfifo "$TEMP1" || fatal "Could not create fifo 1" 158 mkfifo "$TEMP2" || fatal "Could not create fifo 2" 159 160 strip_dump "$INFILE1" "$TEMP1" "$@" & 161 strip_dump "$INFILE2" "$TEMP2" "$@" & 162 163 sdiff \ 164 --left-column \ 165 --width="$(tput cols)" \ 166 --speed-large-files \ 167 "${SDIFF_ARGS[@]}" \ 168 "$TEMP1" "$TEMP2" \ 169 | less 170fi 171