intel_dump_gpu.in revision 9f464c52
1#!/bin/bash
2# -*- mode: sh -*-
3
4function show_help() {
5    cat <<EOF
6Usage: intel_dump_gpu [OPTION]... [--] COMMAND ARGUMENTS
7
8Run COMMAND with ARGUMENTS and dump an AUB file that captures buffer
9contents 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  -v                  Enable verbose output
20
21  -vv                 Enable extra verbosity - dumps gtt mappings
22
23      --help          Display this help message and exit
24
25EOF
26
27    exit 0
28}
29
30ld_preload="@install_libexecdir@/libintel_dump_gpu.so${LD_PPRELOAD:+:$LD_PRELOAD}"
31args=""
32file=""
33gdb=""
34
35function add_arg() {
36    arg=$1
37    args="$args$arg\n"
38}
39
40while true; do
41    case "$1" in
42        -v)
43            add_arg "verbose=1"
44            shift 1
45            ;;
46        -vv)
47            add_arg "verbose=2"
48            shift 1
49            ;;
50        -o)
51            file=$2
52            add_arg "file=${file:-$(basename ${file}).aub}"
53            shift 2
54            ;;
55        -o*)
56            file=${1##-o}
57            add_arg "file=${file:-$(basename ${file}).aub}"
58            shift
59            ;;
60        --output=*)
61            file=${1##--output=}
62            add_arg "file=${file:-$(basename ${file}).aub}"
63            shift
64            ;;
65        --device=*)
66            add_arg "device=${1##--device=}"
67            shift
68            ;;
69        -p)
70            platform=$2
71            add_arg "platform=${platform}"
72            shift 2
73            ;;
74        -p*)
75            platform=${1##-p}
76            add_arg "platform=${platform}"
77            shift
78            ;;
79        --platform=*)
80            platform=${1##-p}
81            add_arg "platform=${platform}"
82            shift
83            ;;
84        --gdb)
85            gdb=1
86            shift
87            ;;
88        -g)
89            gdb=1
90            shift
91            ;;
92        --help)
93            show_help
94            ;;
95        --)
96            shift
97            break
98            ;;
99        -*)
100            echo "intel_aubdump: invalid option: $1"
101            echo
102            show_help
103            ;;
104        *)
105            break
106            ;;
107    esac
108done
109
110[ -z $1 ] && show_help
111
112[ -z $file ] && add_arg "file=intel.aub"
113
114tmp_file=`mktemp`
115echo -e $args > $tmp_file
116
117if [ -z $gdb ]; then
118    LD_PRELOAD="$ld_preload" INTEL_DUMP_GPU_CONFIG=$tmp_file $@
119else
120    gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_DUMP_GPU_CONFIG=$tmp_file" --args $@
121fi
122
123ret=$?
124rm $tmp_file
125exit $ret
126