Home | History | Annotate | Line # | Download | only in i386
      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 --script --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|\
     41 model*:\ 92|\
     42 model*:\ 95|\
     43 model*:\ 87|\
     44 model*:\ 133|\
     45 model*:\ 122) E="cpu/event=0xC4,umask=0xFE/p$FLAGS" ;;
     46 model*:\ 42|\
     47 model*:\ 45|\
     48 model*:\ 58|\
     49 model*:\ 62|\
     50 model*:\ 60|\
     51 model*:\ 69|\
     52 model*:\ 70|\
     53 model*:\ 63|\
     54 model*:\ 61|\
     55 model*:\ 71|\
     56 model*:\ 79|\
     57 model*:\ 86|\
     58 model*:\ 78|\
     59 model*:\ 94|\
     60 model*:\ 142|\
     61 model*:\ 158|\
     62 model*:\ 165|\
     63 model*:\ 166|\
     64 model*:\ 85|\
     65 model*:\ 85) E="cpu/event=0xC4,umask=0x20/p$FLAGS" ;;
     66 model*:\ 46|\
     67 model*:\ 30|\
     68 model*:\ 31|\
     69 model*:\ 26|\
     70 model*:\ 47|\
     71 model*:\ 37|\
     72 model*:\ 44) E="cpu/event=0x88,umask=0x40/p$FLAGS" ;;
     73 model*:\ 28|\
     74 model*:\ 38|\
     75 model*:\ 39|\
     76 model*:\ 54|\
     77 model*:\ 53) E="cpu/event=0x88,umask=0x41/p$FLAGS" ;;
     78 model*:\ 126|\
     79 model*:\ 140|\
     80 model*:\ 141|\
     81 model*:\ 106|\
     82 model*:\ 108) E="cpu/event=0xc4,umask=0x20/p$FLAGS" ;;
     83 *)
     84 echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script."
     85 	exit 1 ;;
     86 esac
     87 set -x
     88 if ! perf record -e $E -b "$@" ; then
     89   # PEBS may not actually be working even if the processor supports it
     90   # (e.g., in a virtual machine). Trying to run without /p.
     91   set +x
     92   echo >&2 "Retrying without /p."
     93   E="$(echo "${E}" | sed -e 's/\/p/\//')"
     94   set -x
     95   exec perf record -e $E -b "$@"
     96  set +x
     97 fi
     98