1 #!/bin/sh 2 # profile workload for gcc profile feedback (autofdo) using Linux perf 3 # auto generated. to regenerate for new CPUs run 4 # contrib/gen_autofdo_event.py --shell --all in gcc source 5 6 # usages: 7 # gcc-auto-profile program (profile program and children) 8 # gcc-auto-profile -a sleep X (profile all for X secs, may need root) 9 # gcc-auto-profile -p PID sleep X (profile PID) 10 # gcc-auto-profile --kernel -a sleep X (profile kernel) 11 # gcc-auto-profile --all -a sleep X (profile kernel and user space) 12 13 # identify branches taken event for CPU 14 # 15 16 FLAGS=u 17 18 if [ "$1" = "--kernel" ] ; then 19 FLAGS=k 20 shift 21 fi 22 if [ "$1" = "--all" ] ; then 23 FLAGS=uk 24 shift 25 fi 26 27 if ! grep -q Intel /proc/cpuinfo ; then 28 echo >&2 "Only Intel CPUs supported" 29 exit 1 30 fi 31 32 if grep -q hypervisor /proc/cpuinfo ; then 33 echo >&2 "Warning: branch profiling may not be functional in VMs" 34 fi 35 36 case `egrep -q "^cpu family\s*: 6" /proc/cpuinfo && 37 egrep "^model\s*:" /proc/cpuinfo | head -n1` in 38 model*:\ 55|\ 39 model*:\ 77|\ 40 model*:\ 76) E="cpu/event=0xC4,umask=0xFE/p$FLAGS" ;; 41 model*:\ 42|\ 42 model*:\ 45|\ 43 model*:\ 58|\ 44 model*:\ 62|\ 45 model*:\ 60|\ 46 model*:\ 69|\ 47 model*:\ 70|\ 48 model*:\ 63|\ 49 model*:\ 61|\ 50 model*:\ 71|\ 51 model*:\ 86|\ 52 model*:\ 78|\ 53 model*:\ 94) E="cpu/event=0xC4,umask=0x20/p$FLAGS" ;; 54 model*:\ 46|\ 55 model*:\ 30|\ 56 model*:\ 31|\ 57 model*:\ 26|\ 58 model*:\ 47|\ 59 model*:\ 37|\ 60 model*:\ 44) E="cpu/event=0x88,umask=0x40/p$FLAGS" ;; 61 model*:\ 28|\ 62 model*:\ 38|\ 63 model*:\ 39|\ 64 model*:\ 54|\ 65 model*:\ 53) E="cpu/event=0x88,umask=0x41/p$FLAGS" ;; 66 *) 67 echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script." 68 exit 1 ;; 69 esac 70 exec perf record -e $E -b "$@" 71