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
16FLAGS=u
17
18if [ "$1" = "--kernel" ] ; then
19  FLAGS=k
20  shift
21fi
22if [ "$1" = "--all" ] ; then
23  FLAGS=uk
24  shift
25fi
26
27if ! grep -q Intel /proc/cpuinfo ; then
28  echo >&2 "Only Intel CPUs supported"
29  exit 1
30fi
31
32if grep -q hypervisor /proc/cpuinfo ; then
33  echo >&2 "Warning: branch profiling may not be functional in VMs"
34fi
35
36case `egrep -q "^cpu family\s*: 6" /proc/cpuinfo &&
37  egrep "^model\s*:" /proc/cpuinfo | head -n1` in
38model*:\ 55|\
39model*:\ 77|\
40model*:\ 76) E="cpu/event=0xC4,umask=0xFE/p$FLAGS" ;;
41model*:\ 42|\
42model*:\ 45|\
43model*:\ 58|\
44model*:\ 62|\
45model*:\ 60|\
46model*:\ 69|\
47model*:\ 70|\
48model*:\ 63|\
49model*:\ 61|\
50model*:\ 71|\
51model*:\ 86|\
52model*:\ 78|\
53model*:\ 94) E="cpu/event=0xC4,umask=0x20/p$FLAGS" ;;
54model*:\ 46|\
55model*:\ 30|\
56model*:\ 31|\
57model*:\ 26|\
58model*:\ 47|\
59model*:\ 37|\
60model*:\ 44) E="cpu/event=0x88,umask=0x40/p$FLAGS" ;;
61model*:\ 28|\
62model*:\ 38|\
63model*:\ 39|\
64model*:\ 54|\
65model*:\ 53) E="cpu/event=0x88,umask=0x41/p$FLAGS" ;;
66*)
67echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script."
68	exit 1 ;;
69esac
70exec perf record -e $E -b "$@"
71