1# This script is to be run on the KVM guest 2 3set -ex 4 5mkdir /waffle 6mount -t virtiofs waffle-tag /waffle 7 8mkdir /apitrace 9mount -t virtiofs apitrace-tag /apitrace 10 11mkdir /traces-db 12mount -t virtiofs traces-db-tag /traces-db 13 14mkdir /perfetto 15mount -t virtiofs perfetto-tag /perfetto 16 17echo 3 > /proc/sys/kernel/printk 18 19export PATH="/apitrace/build:$PATH" 20export PATH="/waffle/build/bin:$PATH" 21export LD_LIBRARY_PATH="/waffle/build/lib:$LD_LIBRARY_PATH" 22export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" 23export EGL_PLATFORM="surfaceless" 24export WAFFLE_PLATFORM="surfaceless_egl" 25export MESA_GL_VERSION_OVERRIDE="4.5" 26export DISPLAY= 27 28# Comment out any other sources, so it only syncs to the host via PTP 29sed -i '/pool/s/^/#/' /etc/chrony/chrony.conf 30echo refclock PHC /dev/ptp0 poll 1 dpoll -2 offset 0 >> /etc/chrony/chrony.conf 31echo cmdport 0 >> /etc/chrony/chrony.conf 32echo bindcmdaddress / >> /etc/chrony/chrony.conf 33 34mkdir -p /run/chrony 35time chronyd -q # Initial synchronization, will take some time 36chronyd # Keep clocks in sync 37 38# Get trace cached 39trace_no_ext=$(cat /traces-db/current_trace) 40if [ "x$trace_no_ext" = "x" ]; then 41 echo "No trace given, bailing out" 42 exit 1 43fi 44 45command=$(cat /traces-db/command) 46echo command=$command 47 48WAIT= 49RECORD= 50benchmark_loops=0 51perfetto_loops=10 52 53for c in $command; do 54 55 val=(${c//=/ }) 56 case "${val[0]}" in 57 benchmark) 58 benchmark_loops=${val[1]} 59 ;; 60 61 perfetto) 62 perfetto_loops=${val[1]} 63 ;; 64 65 wait-after-frame) 66 WAIT="--wait-after-frame" 67 ;; 68 69 record-frame) 70 RECORD="--snapshot" 71 ;; 72 73 esac 74done 75 76if [ -e /traces-db/wait_after_frame ]; then 77 WAIT=-wait-after-frame 78fi 79 80trace="/traces-db/${trace_no_ext}.trace" 81datadir="/traces-db/${trace_no_ext}-out" 82trace_base=$(basename ${trace_no_ext}) 83guest_perf="$datadir/${trace_base}-guest.perfetto" 84 85cat "$trace" > /dev/null 86 87# To keep Perfetto happy 88echo 0 > /sys/kernel/debug/tracing/tracing_on 89echo nop > /sys/kernel/debug/tracing/current_tracer 90 91echo "Guest:" 92wflinfo --platform surfaceless_egl --api gles2 -v 93 94if [ "x$perfetto_loops" != "x" -a "x$perfetto_loops" != "x0" ]; then 95 /perfetto/out/dist/traced & 96 /perfetto/out/dist/traced_probes & 97 sleep 1 98 99 /perfetto/out/dist/perfetto --txt -c /usr/local/perfetto-guest.cfg -o "$guest_perf" --detach=mykey 100 sleep 1 101 102 # The first virtio-gpu event has to be captured in the guest, so we correlate correctly to the host event 103 104 echo "Replaying for Perfetto:" 105 eglretrace --benchmark --singlethread --loop=$perfetto_loops $WAIT --headless "$trace" 106 sleep 1 107 108 /perfetto/out/dist/perfetto --attach=mykey --stop 109 chmod a+rw "$guest_perf" 110fi 111 112if [ "x$benchmark_loops" != "x0" ]; then 113 echo "Measuring rendering times:" 114 eglretrace --benchmark --loop=$benchmark_loops --headless "$trace" 115fi 116 117if [ "x$RECORD" != "x" ]; then 118 eglretrace --snapshot frame --snapshot-prefix=${datadir}/ --headless "$trace" 119fi 120