Home | History | Annotate | Line # | Download | only in tools
      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   -f, --frame=ID      Only dump objects for frame ID
     24 
     25   -v                  Enable verbose output
     26 
     27   -vv                 Enable extra verbosity - dumps gtt mappings
     28 
     29       --help          Display this help message and exit
     30 
     31 EOF
     32 
     33     exit 0
     34 }
     35 
     36 ld_preload="@install_libexecdir@/libintel_dump_gpu.so${LD_PRELOAD:+:$LD_PRELOAD}"
     37 args=""
     38 file=""
     39 gdb=""
     40 capture_only=""
     41 frame=""
     42 
     43 function add_arg() {
     44     arg=$1
     45     args="$args$arg\n"
     46 }
     47 
     48 while true; do
     49     case "$1" in
     50         -v)
     51             add_arg "verbose=1"
     52             shift 1
     53             ;;
     54         -vv)
     55             add_arg "verbose=2"
     56             shift 1
     57             ;;
     58         -o)
     59             file=$2
     60             add_arg "file=${file:-$(basename ${file}).aub}"
     61             shift 2
     62             ;;
     63         -o*)
     64             file=${1##-o}
     65             add_arg "file=${file:-$(basename ${file}).aub}"
     66             shift
     67             ;;
     68         --output=*)
     69             file=${1##--output=}
     70             add_arg "file=${file:-$(basename ${file}).aub}"
     71             shift
     72             ;;
     73         --device=*)
     74             add_arg "device=${1##--device=}"
     75             shift
     76             ;;
     77         -p)
     78             platform=$2
     79             add_arg "platform=${platform}"
     80             shift 2
     81             ;;
     82         -p*)
     83             platform=${1##-p}
     84             add_arg "platform=${platform}"
     85             shift
     86             ;;
     87         --platform=*)
     88             platform=${1##--platform=}
     89             add_arg "platform=${platform}"
     90             shift
     91             ;;
     92         -f)
     93             frame=$2
     94             add_arg "frame=${frame}"
     95             shift 2
     96             ;;
     97         -f*)
     98             frame=${1##-f}
     99             add_arg "frame=${frame}"
    100             shift
    101             ;;
    102         --frame=*)
    103             frame=${1##--frame=}
    104             add_arg "frame=${frame}"
    105             shift
    106             ;;
    107         --gdb)
    108             gdb=1
    109             shift
    110             ;;
    111         -g)
    112             gdb=1
    113             shift
    114             ;;
    115         -c)
    116             add_arg "capture_only=1"
    117             shift
    118             ;;
    119         --only-capture)
    120             add_arg "capture_only=1"
    121             shift
    122             ;;
    123         --help)
    124             show_help
    125             ;;
    126         --)
    127             shift
    128             break
    129             ;;
    130         -*)
    131             echo "intel_aubdump: invalid option: $1"
    132             echo
    133             show_help
    134             ;;
    135         *)
    136             break
    137             ;;
    138     esac
    139 done
    140 
    141 [ -z $1 ] && show_help
    142 
    143 [ -z $file ] && add_arg "file=intel.aub"
    144 
    145 tmp_file=`mktemp`
    146 echo -e $args > $tmp_file
    147 
    148 if [ -z $gdb ]; then
    149     LD_PRELOAD="$ld_preload" INTEL_DUMP_GPU_CONFIG=$tmp_file "$@"
    150 else
    151     gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_DUMP_GPU_CONFIG=$tmp_file" --args "$@"
    152 fi
    153 
    154 ret=$?
    155 rm $tmp_file
    156 exit $ret
    157