intel: tools: import intel_aubdump
[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 -o, --output=FILE Name of AUB file. Defaults to COMMAND.aub
12
13 -c, --command=CMD Execute CMD and write the AUB file's content to its
14 standard input
15
16 --device=ID Override PCI ID of the reported device
17
18 -v Enable verbose output
19
20 --help Display this help message and exit
21
22 EOF
23
24 exit 0
25 }
26
27 args=""
28 command=""
29 file=""
30
31 function add_arg() {
32 arg=$1
33 args="$args$arg\n"
34 }
35
36 function build_command () {
37 command=""
38 for i in $1; do
39 if [ -z $command ]; then
40 command=$i
41 else
42 command="$command,$i"
43 fi;
44 done
45 }
46
47 while true; do
48 case "$1" in
49 -o)
50 file=$2
51 add_arg "file=${file:-$(basename ${file}).aub}"
52 shift 2
53 ;;
54 -v)
55 add_arg "verbose=1"
56 shift 1
57 ;;
58 -o*)
59 file=${1##-o}
60 add_arg "file=${file:-$(basename ${file}).aub}"
61 shift
62 ;;
63 --output=*)
64 file=${1##--output=}
65 add_arg "file=${file:-$(basename ${file}).aub}"
66 shift
67 ;;
68 -c)
69 build_command "$2"
70 add_arg "command=$command"
71 shift 2
72 ;;
73 --command=*)
74 build_command "${1##--command=}"
75 add_arg "command=$command"
76 shift
77 ;;
78 --device=*)
79 add_arg "device=${1##--device=}"
80 shift
81 ;;
82 --help)
83 show_help
84 ;;
85 --)
86 shift
87 break
88 ;;
89 -*)
90 echo "intel_aubdump: invalid option: $1"
91 echo
92 show_help
93 ;;
94 *)
95 break
96 ;;
97 esac
98 done
99
100 [ -z $1 ] && show_help
101
102 [ -z $file ] && [ -z $command ] && add_arg "file=intel.aub"
103
104 LD_PRELOAD="@install_libexecdir@/libintel_dump_gpu.so${LD_PPRELOAD:+:$LD_PRELOAD}" \
105 exec -- "$@" 3<<EOF
106 `echo -e $args`
107 EOF