0395af0a8eb50a31dc7fd513be843d2f4ff1a8b1
[mesa.git] / src / intel / tools / intel_dump_gpu.in
1 #!/bin/bash
2 # -*- mode: sh -*-
3
4 function show_help() {
5 cat <<EOF
6 Usage: intel_dump_gpu [OPTION]... [--] COMMAND ARGUMENTS
7
8 Run COMMAND with ARGUMENTS and dump an AUB file that captures buffer
9 contents and execution of the GEM application.
10
11 -g, --gdb Launch GDB
12
13 -o, --output=FILE Name of AUB file. Defaults to COMMAND.aub
14
15 --device=ID Override PCI ID of the reported device
16
17 -p, --platform=NAME Override PCI ID using a platform name
18
19 -c, --only-capture Only write objects flagged with EXEC_OBJECT_CAPTURE into
20 the output aub file. This helps reducing output file
21 size greatly but won't produce a file replayable
22
23 -v Enable verbose output
24
25 -vv Enable extra verbosity - dumps gtt mappings
26
27 --help Display this help message and exit
28
29 EOF
30
31 exit 0
32 }
33
34 ld_preload="@install_libexecdir@/libintel_dump_gpu.so${LD_PRELOAD:+:$LD_PRELOAD}"
35 args=""
36 file=""
37 gdb=""
38 capture_only=""
39
40 function add_arg() {
41 arg=$1
42 args="$args$arg\n"
43 }
44
45 while true; do
46 case "$1" in
47 -v)
48 add_arg "verbose=1"
49 shift 1
50 ;;
51 -vv)
52 add_arg "verbose=2"
53 shift 1
54 ;;
55 -o)
56 file=$2
57 add_arg "file=${file:-$(basename ${file}).aub}"
58 shift 2
59 ;;
60 -o*)
61 file=${1##-o}
62 add_arg "file=${file:-$(basename ${file}).aub}"
63 shift
64 ;;
65 --output=*)
66 file=${1##--output=}
67 add_arg "file=${file:-$(basename ${file}).aub}"
68 shift
69 ;;
70 --device=*)
71 add_arg "device=${1##--device=}"
72 shift
73 ;;
74 -p)
75 platform=$2
76 add_arg "platform=${platform}"
77 shift 2
78 ;;
79 -p*)
80 platform=${1##-p}
81 add_arg "platform=${platform}"
82 shift
83 ;;
84 --platform=*)
85 platform=${1##--platform=}
86 add_arg "platform=${platform}"
87 shift
88 ;;
89 --gdb)
90 gdb=1
91 shift
92 ;;
93 -g)
94 gdb=1
95 shift
96 ;;
97 -c)
98 add_arg "capture_only=1"
99 shift
100 ;;
101 --only-capture)
102 add_arg "capture_only=1"
103 shift
104 ;;
105 --help)
106 show_help
107 ;;
108 --)
109 shift
110 break
111 ;;
112 -*)
113 echo "intel_aubdump: invalid option: $1"
114 echo
115 show_help
116 ;;
117 *)
118 break
119 ;;
120 esac
121 done
122
123 [ -z $1 ] && show_help
124
125 [ -z $file ] && add_arg "file=intel.aub"
126
127 tmp_file=`mktemp`
128 echo -e $args > $tmp_file
129
130 if [ -z $gdb ]; then
131 LD_PRELOAD="$ld_preload" INTEL_DUMP_GPU_CONFIG=$tmp_file "$@"
132 else
133 gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_DUMP_GPU_CONFIG=$tmp_file" --args "$@"
134 fi
135
136 ret=$?
137 rm $tmp_file
138 exit $ret