time-strace.sh revision 7ec681f3
17ec681f3Smrg#!/bin/sh 27ec681f3Smrg 37ec681f3SmrgSTRACEDIR=meson-logs/strace/$(for i in $@; do basename -z -- $i; echo -n _; done) 47ec681f3Smrg 57ec681f3Smrgmkdir -p $STRACEDIR 67ec681f3Smrg 77ec681f3Smrg# If the test times out, meson sends SIGTERM to this process. 87ec681f3Smrg# Simply exec'ing "time" would result in no output from that in this case. 97ec681f3Smrg# Instead, we need to run "time" in the background, catch the signals and 107ec681f3Smrg# propagate them to the actual test process. 117ec681f3Smrg 127ec681f3Smrg/usr/bin/time -v strace -ff -tt -T -o $STRACEDIR/log "$@" & 137ec681f3SmrgTIMEPID=$! 147ec681f3SmrgSTRACEPID=$(ps --ppid $TIMEPID -o pid=) 157ec681f3SmrgTESTPID=$(ps --ppid $STRACEPID -o pid=) 167ec681f3Smrg 177ec681f3Smrgif test "x$TESTPID" != x; then 187ec681f3Smrg trap 'kill -TERM $TESTPID; wait $TIMEPID; exit $?' TERM 197ec681f3Smrgfi 207ec681f3Smrg 217ec681f3Smrgwait $TIMEPID 227ec681f3SmrgEXITCODE=$? 237ec681f3Smrg 247ec681f3Smrg# Only keep strace logs if the test timed out 257ec681f3Smrgrm -rf $STRACEDIR & 267ec681f3Smrg 277ec681f3Smrgexit $EXITCODE 28