1#!/bin/bash 2# Copyright 2019 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# This script is to be run on the KVM host, outside the container 7 8 9#set -ex 10 11# grab the pwd before changing it to this script's directory 12pwd="${PWD}" 13root_dir="$(pwd)" 14 15cd "${0%/*}" 16 17mesa_src="" 18virgl_src="" 19traces_db="" 20kernel_src="" 21benchmark_loops=0 22perfetto_loops=10 23wait_after_frame= 24 25print_help() { 26 echo "Run GL trace with perfetto" 27 echo "Usage mesa_wrapper.sh [options]" 28 echo "" 29 echo " --root, -r Path to a root directory that contains the sources for mesa, virglrenderer, and the trace-db" 30 echo " --mesa, -m Path to Mesa source code (overrides path generated from root)" 31 echo " --virgl, -v Path to virglrenderer source code (overrides path generated from root)" 32 echo " --kernel, -k Path to Linux kernel source code" 33 echo " --traces-db, -d Path to the directory containing the traces (overrides path generated from root)" 34 echo " --trace, -t Trace to be run (path relative to traces-db) (required)" 35 echo " --benchmark, -b Number of times the last frame should be run for benchmarking (default 0=disabled)" 36 echo " --perfetto, -p Number of times the last frame should be loop for perfetto (default 10; 0=run trace normally)" 37 echo " --snapshot, -s Make per-frame snapshots" 38 echo " --debug Enable extra logging" 39 echo "" 40 echo " --help, -h Print this help" 41} 42 43command="" 44 45while [ -n "$1" ] ; do 46 case "$1" in 47 48 --root|-r) 49 root_dir="$2" 50 shift 51 ;; 52 53 --mesa|-m) 54 mesa_src="$2" 55 shift 56 ;; 57 58 --virgl|-v) 59 virgl_src="$2" 60 shift 61 ;; 62 63 --traces-db|-d) 64 traces_db="$2" 65 shift 66 ;; 67 68 --kernel|-k) 69 kernel_src="$2" 70 shift 71 ;; 72 73 --help|-h) 74 print_help 75 exit 76 ;; 77 78 --trace|-t) 79 trace="$2" 80 shift 81 ;; 82 83 --benchmark|-b) 84 command="$command -b $2" 85 shift 86 ;; 87 88 --perfetto|-p) 89 command="$command -p $2" 90 shift 91 ;; 92 93 --wait-after-frame|-w) 94 command="$command -w" 95 ;; 96 97 --snapshot|-s) 98 command="$command -s" 99 ;; 100 101 --debug) 102 command="$command --debug" 103 ;; 104 *) 105 echo "Unknown option '$1' given, run with option --help to see supported options" 106 exit 107 ;; 108 esac 109 shift 110done 111 112if [ "x$mesa_src" = "x" ] ; then 113 mesa_src="$root_dir/mesa" 114fi 115 116if [ "x$virgl_src" = "x" ] ; then 117 virgl_src="$root_dir/virglrenderer" 118fi 119 120if [ "x$traces_db" = "x" ] ; then 121 traces_db="$root_dir/traces-db" 122fi 123 124can_run=1 125 126if [ "x$trace" = "x" ]; then 127 echo "No trace given" >&2; 128 can_run=0 129fi 130 131if [ "x$mesa_src" = "x" ]; then 132 echo "no mesa src dir given" >&2; 133 can_run=0 134fi 135 136if [ ! -d "$mesa_src/src/mesa" ]; then 137 echo "mesa src dir '$mesa_src' is not a mesa source tree" >&2; 138 can_run=0 139fi 140 141if [ "x$virgl_src" = "x" ]; then 142 echo "no virglrenderer src dir given" >&2; 143 can_run=0 144fi 145 146if [ ! -d "$virgl_src/vtest" ]; then 147 echo "virglrenderer src dir '$virgl_src' is not a virglrenderer source tree" >&2; 148 can_run=0 149fi 150 151if [ "x$traces_db" = "x" ]; then 152 echo "no traces_db dir given" >&2; 153 can_run=0 154fi 155 156if [ ! -f "$traces_db/$trace" ]; then 157 echo "Given trace file '$trace' doesn't exist in traces db dir '$traces_db'" >&2; 158 # check whether the trace has been given with a path relative to the root dir 159 # that can be removed 160 trace=${trace#*/} 161 echo "Trying $traces_db/$trace" >&2; 162 if [ ! -f "$traces_db/$trace" ]; then 163 echo "Given trace file '$trace' not found " >&2; 164 can_run=0 165 fi 166fi 167 168if [ "x$can_run" = "x0" ]; then 169 echo "Missing or command line options with errors were given" >&2; 170 exit 1 171fi 172 173re='^[0-9]+$' 174if ! [[ 1$benchmark_loops =~ $re ]] ; then 175 echo "error: benchmark_loops '" $benchmark_loops "'is not a number" >&2; 176 exit 1 177fi 178 179if ! [[ 1$perfetto_loops =~ $re ]] ; then 180 echo "error: perfetto_loops '" $perfetto_loops "' is not a number" >&2; 181 exit 1 182fi 183 184echo "command=$command" 185 186docker run -it --rm \ 187 --privileged \ 188 --ipc=host \ 189 -v /dev/log:/dev/log \ 190 -v /dev/vhost-net:/dev/vhost-net \ 191 -v /sys/kernel/debug:/sys/kernel/debug \ 192 -v "$mesa_src":/mesa \ 193 -v "$virgl_src":/virglrenderer \ 194 -v "$traces_db":/traces-db \ 195 -v "$kernel_src":/kernel \ 196 --volume "$pwd":/wd \ 197 --workdir /wd \ 198 mesa \ 199 -t "$trace" \ 200 $command 201