1*4882a593Smuzhiyunperf-record(1) 2*4882a593Smuzhiyun============== 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunNAME 5*4882a593Smuzhiyun---- 6*4882a593Smuzhiyunperf-record - Run a command and record its profile into perf.data 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunSYNOPSIS 9*4882a593Smuzhiyun-------- 10*4882a593Smuzhiyun[verse] 11*4882a593Smuzhiyun'perf record' [-e <EVENT> | --event=EVENT] [-a] <command> 12*4882a593Smuzhiyun'perf record' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>] 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunDESCRIPTION 15*4882a593Smuzhiyun----------- 16*4882a593SmuzhiyunThis command runs a command and gathers a performance counter profile 17*4882a593Smuzhiyunfrom it, into perf.data - without displaying anything. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunThis file can then be inspected later on, using 'perf report'. 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunOPTIONS 23*4882a593Smuzhiyun------- 24*4882a593Smuzhiyun<command>...:: 25*4882a593Smuzhiyun Any command you can specify in a shell. 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun-e:: 28*4882a593Smuzhiyun--event=:: 29*4882a593Smuzhiyun Select the PMU event. Selection can be: 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun - a symbolic event name (use 'perf list' to list all events) 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun - a raw PMU event (eventsel+umask) in the form of rNNN where NNN is a 34*4882a593Smuzhiyun hexadecimal event descriptor. 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun - a symbolic or raw PMU event followed by an optional colon 37*4882a593Smuzhiyun and a list of event modifiers, e.g., cpu-cycles:p. See the 38*4882a593Smuzhiyun linkperf:perf-list[1] man page for details on event modifiers. 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun - a symbolically formed PMU event like 'pmu/param1=0x3,param2/' where 41*4882a593Smuzhiyun 'param1', 'param2', etc are defined as formats for the PMU in 42*4882a593Smuzhiyun /sys/bus/event_source/devices/<pmu>/format/*. 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun - a symbolically formed event like 'pmu/config=M,config1=N,config3=K/' 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun where M, N, K are numbers (in decimal, hex, octal format). Acceptable 47*4882a593Smuzhiyun values for each of 'config', 'config1' and 'config2' are defined by 48*4882a593Smuzhiyun corresponding entries in /sys/bus/event_source/devices/<pmu>/format/* 49*4882a593Smuzhiyun param1 and param2 are defined as formats for the PMU in: 50*4882a593Smuzhiyun /sys/bus/event_source/devices/<pmu>/format/* 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun There are also some parameters which are not defined in .../<pmu>/format/*. 53*4882a593Smuzhiyun These params can be used to overload default config values per event. 54*4882a593Smuzhiyun Here are some common parameters: 55*4882a593Smuzhiyun - 'period': Set event sampling period 56*4882a593Smuzhiyun - 'freq': Set event sampling frequency 57*4882a593Smuzhiyun - 'time': Disable/enable time stamping. Acceptable values are 1 for 58*4882a593Smuzhiyun enabling time stamping. 0 for disabling time stamping. 59*4882a593Smuzhiyun The default is 1. 60*4882a593Smuzhiyun - 'call-graph': Disable/enable callgraph. Acceptable str are "fp" for 61*4882a593Smuzhiyun FP mode, "dwarf" for DWARF mode, "lbr" for LBR mode and 62*4882a593Smuzhiyun "no" for disable callgraph. 63*4882a593Smuzhiyun - 'stack-size': user stack size for dwarf mode 64*4882a593Smuzhiyun - 'name' : User defined event name. Single quotes (') may be used to 65*4882a593Smuzhiyun escape symbols in the name from parsing by shell and tool 66*4882a593Smuzhiyun like this: name=\'CPU_CLK_UNHALTED.THREAD:cmask=0x1\'. 67*4882a593Smuzhiyun - 'aux-output': Generate AUX records instead of events. This requires 68*4882a593Smuzhiyun that an AUX area event is also provided. 69*4882a593Smuzhiyun - 'aux-sample-size': Set sample size for AUX area sampling. If the 70*4882a593Smuzhiyun '--aux-sample' option has been used, set aux-sample-size=0 to disable 71*4882a593Smuzhiyun AUX area sampling for the event. 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun See the linkperf:perf-list[1] man page for more parameters. 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun Note: If user explicitly sets options which conflict with the params, 76*4882a593Smuzhiyun the value set by the parameters will be overridden. 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun Also not defined in .../<pmu>/format/* are PMU driver specific 79*4882a593Smuzhiyun configuration parameters. Any configuration parameter preceded by 80*4882a593Smuzhiyun the letter '@' is not interpreted in user space and sent down directly 81*4882a593Smuzhiyun to the PMU driver. For example: 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun perf record -e some_event/@cfg1,@cfg2=config/ ... 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun will see 'cfg1' and 'cfg2=config' pushed to the PMU driver associated 86*4882a593Smuzhiyun with the event for further processing. There is no restriction on 87*4882a593Smuzhiyun what the configuration parameters are, as long as their semantic is 88*4882a593Smuzhiyun understood and supported by the PMU driver. 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun - a hardware breakpoint event in the form of '\mem:addr[/len][:access]' 91*4882a593Smuzhiyun where addr is the address in memory you want to break in. 92*4882a593Smuzhiyun Access is the memory access type (read, write, execute) it can 93*4882a593Smuzhiyun be passed as follows: '\mem:addr[:[r][w][x]]'. len is the range, 94*4882a593Smuzhiyun number of bytes from specified addr, which the breakpoint will cover. 95*4882a593Smuzhiyun If you want to profile read-write accesses in 0x1000, just set 96*4882a593Smuzhiyun 'mem:0x1000:rw'. 97*4882a593Smuzhiyun If you want to profile write accesses in [0x1000~1008), just set 98*4882a593Smuzhiyun 'mem:0x1000/8:w'. 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun - a BPF source file (ending in .c) or a precompiled object file (ending 101*4882a593Smuzhiyun in .o) selects one or more BPF events. 102*4882a593Smuzhiyun The BPF program can attach to various perf events based on the ELF section 103*4882a593Smuzhiyun names. 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun When processing a '.c' file, perf searches an installed LLVM to compile it 106*4882a593Smuzhiyun into an object file first. Optional clang options can be passed via the 107*4882a593Smuzhiyun '--clang-opt' command line option, e.g.: 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \ 110*4882a593Smuzhiyun -e tests/bpf-script-example.c 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun Note: '--clang-opt' must be placed before '--event/-e'. 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun - a group of events surrounded by a pair of brace ("{event1,event2,...}"). 115*4882a593Smuzhiyun Each event is separated by commas and the group should be quoted to 116*4882a593Smuzhiyun prevent the shell interpretation. You also need to use --group on 117*4882a593Smuzhiyun "perf report" to view group events together. 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun--filter=<filter>:: 120*4882a593Smuzhiyun Event filter. This option should follow an event selector (-e) which 121*4882a593Smuzhiyun selects either tracepoint event(s) or a hardware trace PMU 122*4882a593Smuzhiyun (e.g. Intel PT or CoreSight). 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun - tracepoint filters 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun In the case of tracepoints, multiple '--filter' options are combined 127*4882a593Smuzhiyun using '&&'. 128*4882a593Smuzhiyun 129*4882a593Smuzhiyun - address filters 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun A hardware trace PMU advertises its ability to accept a number of 132*4882a593Smuzhiyun address filters by specifying a non-zero value in 133*4882a593Smuzhiyun /sys/bus/event_source/devices/<pmu>/nr_addr_filters. 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun Address filters have the format: 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun filter|start|stop|tracestop <start> [/ <size>] [@<file name>] 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun Where: 140*4882a593Smuzhiyun - 'filter': defines a region that will be traced. 141*4882a593Smuzhiyun - 'start': defines an address at which tracing will begin. 142*4882a593Smuzhiyun - 'stop': defines an address at which tracing will stop. 143*4882a593Smuzhiyun - 'tracestop': defines a region in which tracing will stop. 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun <file name> is the name of the object file, <start> is the offset to the 146*4882a593Smuzhiyun code to trace in that file, and <size> is the size of the region to 147*4882a593Smuzhiyun trace. 'start' and 'stop' filters need not specify a <size>. 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun If no object file is specified then the kernel is assumed, in which case 150*4882a593Smuzhiyun the start address must be a current kernel memory address. 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun <start> can also be specified by providing the name of a symbol. If the 153*4882a593Smuzhiyun symbol name is not unique, it can be disambiguated by inserting #n where 154*4882a593Smuzhiyun 'n' selects the n'th symbol in address order. Alternately #0, #g or #G 155*4882a593Smuzhiyun select only a global symbol. <size> can also be specified by providing 156*4882a593Smuzhiyun the name of a symbol, in which case the size is calculated to the end 157*4882a593Smuzhiyun of that symbol. For 'filter' and 'tracestop' filters, if <size> is 158*4882a593Smuzhiyun omitted and <start> is a symbol, then the size is calculated to the end 159*4882a593Smuzhiyun of that symbol. 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun If <size> is omitted and <start> is '*', then the start and size will 162*4882a593Smuzhiyun be calculated from the first and last symbols, i.e. to trace the whole 163*4882a593Smuzhiyun file. 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun If symbol names (or '*') are provided, they must be surrounded by white 166*4882a593Smuzhiyun space. 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun The filter passed to the kernel is not necessarily the same as entered. 169*4882a593Smuzhiyun To see the filter that is passed, use the -v option. 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun The kernel may not be able to configure a trace region if it is not 172*4882a593Smuzhiyun within a single mapping. MMAP events (or /proc/<pid>/maps) can be 173*4882a593Smuzhiyun examined to determine if that is a possibility. 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun Multiple filters can be separated with space or comma. 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun--exclude-perf:: 178*4882a593Smuzhiyun Don't record events issued by perf itself. This option should follow 179*4882a593Smuzhiyun an event selector (-e) which selects tracepoint event(s). It adds a 180*4882a593Smuzhiyun filter expression 'common_pid != $PERFPID' to filters. If other 181*4882a593Smuzhiyun '--filter' exists, the new filter expression will be combined with 182*4882a593Smuzhiyun them by '&&'. 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun-a:: 185*4882a593Smuzhiyun--all-cpus:: 186*4882a593Smuzhiyun System-wide collection from all CPUs (default if no target is specified). 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun-p:: 189*4882a593Smuzhiyun--pid=:: 190*4882a593Smuzhiyun Record events on existing process ID (comma separated list). 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun-t:: 193*4882a593Smuzhiyun--tid=:: 194*4882a593Smuzhiyun Record events on existing thread ID (comma separated list). 195*4882a593Smuzhiyun This option also disables inheritance by default. Enable it by adding 196*4882a593Smuzhiyun --inherit. 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun-u:: 199*4882a593Smuzhiyun--uid=:: 200*4882a593Smuzhiyun Record events in threads owned by uid. Name or number. 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun-r:: 203*4882a593Smuzhiyun--realtime=:: 204*4882a593Smuzhiyun Collect data with this RT SCHED_FIFO priority. 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun--no-buffering:: 207*4882a593Smuzhiyun Collect data without buffering. 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun-c:: 210*4882a593Smuzhiyun--count=:: 211*4882a593Smuzhiyun Event period to sample. 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun-o:: 214*4882a593Smuzhiyun--output=:: 215*4882a593Smuzhiyun Output file name. 216*4882a593Smuzhiyun 217*4882a593Smuzhiyun-i:: 218*4882a593Smuzhiyun--no-inherit:: 219*4882a593Smuzhiyun Child tasks do not inherit counters. 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun-F:: 222*4882a593Smuzhiyun--freq=:: 223*4882a593Smuzhiyun Profile at this frequency. Use 'max' to use the currently maximum 224*4882a593Smuzhiyun allowed frequency, i.e. the value in the kernel.perf_event_max_sample_rate 225*4882a593Smuzhiyun sysctl. Will throttle down to the currently maximum allowed frequency. 226*4882a593Smuzhiyun See --strict-freq. 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun--strict-freq:: 229*4882a593Smuzhiyun Fail if the specified frequency can't be used. 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun-m:: 232*4882a593Smuzhiyun--mmap-pages=:: 233*4882a593Smuzhiyun Number of mmap data pages (must be a power of two) or size 234*4882a593Smuzhiyun specification with appended unit character - B/K/M/G. The 235*4882a593Smuzhiyun size is rounded up to have nearest pages power of two value. 236*4882a593Smuzhiyun Also, by adding a comma, the number of mmap pages for AUX 237*4882a593Smuzhiyun area tracing can be specified. 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun--group:: 240*4882a593Smuzhiyun Put all events in a single event group. This precedes the --event 241*4882a593Smuzhiyun option and remains only for backward compatibility. See --event. 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun-g:: 244*4882a593Smuzhiyun Enables call-graph (stack chain/backtrace) recording for both 245*4882a593Smuzhiyun kernel space and user space. 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun--call-graph:: 248*4882a593Smuzhiyun Setup and enable call-graph (stack chain/backtrace) recording, 249*4882a593Smuzhiyun implies -g. Default is "fp" (for user space). 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun The unwinding method used for kernel space is dependent on the 252*4882a593Smuzhiyun unwinder used by the active kernel configuration, i.e 253*4882a593Smuzhiyun CONFIG_UNWINDER_FRAME_POINTER (fp) or CONFIG_UNWINDER_ORC (orc) 254*4882a593Smuzhiyun 255*4882a593Smuzhiyun Any option specified here controls the method used for user space. 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun Valid options are "fp" (frame pointer), "dwarf" (DWARF's CFI - 258*4882a593Smuzhiyun Call Frame Information) or "lbr" (Hardware Last Branch Record 259*4882a593Smuzhiyun facility). 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun In some systems, where binaries are build with gcc 262*4882a593Smuzhiyun --fomit-frame-pointer, using the "fp" method will produce bogus 263*4882a593Smuzhiyun call graphs, using "dwarf", if available (perf tools linked to 264*4882a593Smuzhiyun the libunwind or libdw library) should be used instead. 265*4882a593Smuzhiyun Using the "lbr" method doesn't require any compiler options. It 266*4882a593Smuzhiyun will produce call graphs from the hardware LBR registers. The 267*4882a593Smuzhiyun main limitation is that it is only available on new Intel 268*4882a593Smuzhiyun platforms, such as Haswell. It can only get user call chain. It 269*4882a593Smuzhiyun doesn't work with branch stack sampling at the same time. 270*4882a593Smuzhiyun 271*4882a593Smuzhiyun When "dwarf" recording is used, perf also records (user) stack dump 272*4882a593Smuzhiyun when sampled. Default size of the stack dump is 8192 (bytes). 273*4882a593Smuzhiyun User can change the size by passing the size after comma like 274*4882a593Smuzhiyun "--call-graph dwarf,4096". 275*4882a593Smuzhiyun 276*4882a593Smuzhiyun-q:: 277*4882a593Smuzhiyun--quiet:: 278*4882a593Smuzhiyun Don't print any message, useful for scripting. 279*4882a593Smuzhiyun 280*4882a593Smuzhiyun-v:: 281*4882a593Smuzhiyun--verbose:: 282*4882a593Smuzhiyun Be more verbose (show counter open errors, etc). 283*4882a593Smuzhiyun 284*4882a593Smuzhiyun-s:: 285*4882a593Smuzhiyun--stat:: 286*4882a593Smuzhiyun Record per-thread event counts. Use it with 'perf report -T' to see 287*4882a593Smuzhiyun the values. 288*4882a593Smuzhiyun 289*4882a593Smuzhiyun-d:: 290*4882a593Smuzhiyun--data:: 291*4882a593Smuzhiyun Record the sample virtual addresses. 292*4882a593Smuzhiyun 293*4882a593Smuzhiyun--phys-data:: 294*4882a593Smuzhiyun Record the sample physical addresses. 295*4882a593Smuzhiyun 296*4882a593Smuzhiyun-T:: 297*4882a593Smuzhiyun--timestamp:: 298*4882a593Smuzhiyun Record the sample timestamps. Use it with 'perf report -D' to see the 299*4882a593Smuzhiyun timestamps, for instance. 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun-P:: 302*4882a593Smuzhiyun--period:: 303*4882a593Smuzhiyun Record the sample period. 304*4882a593Smuzhiyun 305*4882a593Smuzhiyun--sample-cpu:: 306*4882a593Smuzhiyun Record the sample cpu. 307*4882a593Smuzhiyun 308*4882a593Smuzhiyun-n:: 309*4882a593Smuzhiyun--no-samples:: 310*4882a593Smuzhiyun Don't sample. 311*4882a593Smuzhiyun 312*4882a593Smuzhiyun-R:: 313*4882a593Smuzhiyun--raw-samples:: 314*4882a593SmuzhiyunCollect raw sample records from all opened counters (default for tracepoint counters). 315*4882a593Smuzhiyun 316*4882a593Smuzhiyun-C:: 317*4882a593Smuzhiyun--cpu:: 318*4882a593SmuzhiyunCollect samples only on the list of CPUs provided. Multiple CPUs can be provided as a 319*4882a593Smuzhiyuncomma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2. 320*4882a593SmuzhiyunIn per-thread mode with inheritance mode on (default), samples are captured only when 321*4882a593Smuzhiyunthe thread executes on the designated CPUs. Default is to monitor all CPUs. 322*4882a593Smuzhiyun 323*4882a593Smuzhiyun-B:: 324*4882a593Smuzhiyun--no-buildid:: 325*4882a593SmuzhiyunDo not save the build ids of binaries in the perf.data files. This skips 326*4882a593Smuzhiyunpost processing after recording, which sometimes makes the final step in 327*4882a593Smuzhiyunthe recording process to take a long time, as it needs to process all 328*4882a593Smuzhiyunevents looking for mmap records. The downside is that it can misresolve 329*4882a593Smuzhiyunsymbols if the workload binaries used when recording get locally rebuilt 330*4882a593Smuzhiyunor upgraded, because the only key available in this case is the 331*4882a593Smuzhiyunpathname. You can also set the "record.build-id" config variable to 332*4882a593Smuzhiyun'skip to have this behaviour permanently. 333*4882a593Smuzhiyun 334*4882a593Smuzhiyun-N:: 335*4882a593Smuzhiyun--no-buildid-cache:: 336*4882a593SmuzhiyunDo not update the buildid cache. This saves some overhead in situations 337*4882a593Smuzhiyunwhere the information in the perf.data file (which includes buildids) 338*4882a593Smuzhiyunis sufficient. You can also set the "record.build-id" config variable to 339*4882a593Smuzhiyun'no-cache' to have the same effect. 340*4882a593Smuzhiyun 341*4882a593Smuzhiyun-G name,...:: 342*4882a593Smuzhiyun--cgroup name,...:: 343*4882a593Smuzhiyunmonitor only in the container (cgroup) called "name". This option is available only 344*4882a593Smuzhiyunin per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to 345*4882a593Smuzhiyuncontainer "name" are monitored when they run on the monitored CPUs. Multiple cgroups 346*4882a593Smuzhiyuncan be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup 347*4882a593Smuzhiyunto first event, second cgroup to second event and so on. It is possible to provide 348*4882a593Smuzhiyunan empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have 349*4882a593Smuzhiyuncorresponding events, i.e., they always refer to events defined earlier on the command 350*4882a593Smuzhiyunline. If the user wants to track multiple events for a specific cgroup, the user can 351*4882a593Smuzhiyunuse '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'. 352*4882a593Smuzhiyun 353*4882a593SmuzhiyunIf wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this 354*4882a593Smuzhiyuncommand line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'. 355*4882a593Smuzhiyun 356*4882a593Smuzhiyun-b:: 357*4882a593Smuzhiyun--branch-any:: 358*4882a593SmuzhiyunEnable taken branch stack sampling. Any type of taken branch may be sampled. 359*4882a593SmuzhiyunThis is a shortcut for --branch-filter any. See --branch-filter for more infos. 360*4882a593Smuzhiyun 361*4882a593Smuzhiyun-j:: 362*4882a593Smuzhiyun--branch-filter:: 363*4882a593SmuzhiyunEnable taken branch stack sampling. Each sample captures a series of consecutive 364*4882a593Smuzhiyuntaken branches. The number of branches captured with each sample depends on the 365*4882a593Smuzhiyununderlying hardware, the type of branches of interest, and the executed code. 366*4882a593SmuzhiyunIt is possible to select the types of branches captured by enabling filters. The 367*4882a593Smuzhiyunfollowing filters are defined: 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun - any: any type of branches 370*4882a593Smuzhiyun - any_call: any function call or system call 371*4882a593Smuzhiyun - any_ret: any function return or system call return 372*4882a593Smuzhiyun - ind_call: any indirect branch 373*4882a593Smuzhiyun - call: direct calls, including far (to/from kernel) calls 374*4882a593Smuzhiyun - u: only when the branch target is at the user level 375*4882a593Smuzhiyun - k: only when the branch target is in the kernel 376*4882a593Smuzhiyun - hv: only when the target is at the hypervisor level 377*4882a593Smuzhiyun - in_tx: only when the target is in a hardware transaction 378*4882a593Smuzhiyun - no_tx: only when the target is not in a hardware transaction 379*4882a593Smuzhiyun - abort_tx: only when the target is a hardware transaction abort 380*4882a593Smuzhiyun - cond: conditional branches 381*4882a593Smuzhiyun - save_type: save branch type during sampling in case binary is not available later 382*4882a593Smuzhiyun 383*4882a593Smuzhiyun+ 384*4882a593SmuzhiyunThe option requires at least one branch type among any, any_call, any_ret, ind_call, cond. 385*4882a593SmuzhiyunThe privilege levels may be omitted, in which case, the privilege levels of the associated 386*4882a593Smuzhiyunevent are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege 387*4882a593Smuzhiyunlevels are subject to permissions. When sampling on multiple events, branch stack sampling 388*4882a593Smuzhiyunis enabled for all the sampling events. The sampled branch type is the same for all events. 389*4882a593SmuzhiyunThe various filters must be specified as a comma separated list: --branch-filter any_ret,u,k 390*4882a593SmuzhiyunNote that this feature may not be available on all processors. 391*4882a593Smuzhiyun 392*4882a593Smuzhiyun--weight:: 393*4882a593SmuzhiyunEnable weightened sampling. An additional weight is recorded per sample and can be 394*4882a593Smuzhiyundisplayed with the weight and local_weight sort keys. This currently works for TSX 395*4882a593Smuzhiyunabort events and some memory events in precise mode on modern Intel CPUs. 396*4882a593Smuzhiyun 397*4882a593Smuzhiyun--namespaces:: 398*4882a593SmuzhiyunRecord events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key. 399*4882a593Smuzhiyun 400*4882a593Smuzhiyun--all-cgroups:: 401*4882a593SmuzhiyunRecord events of type PERF_RECORD_CGROUP. This enables 'cgroup' sort key. 402*4882a593Smuzhiyun 403*4882a593Smuzhiyun--transaction:: 404*4882a593SmuzhiyunRecord transaction flags for transaction related events. 405*4882a593Smuzhiyun 406*4882a593Smuzhiyun--per-thread:: 407*4882a593SmuzhiyunUse per-thread mmaps. By default per-cpu mmaps are created. This option 408*4882a593Smuzhiyunoverrides that and uses per-thread mmaps. A side-effect of that is that 409*4882a593Smuzhiyuninheritance is automatically disabled. --per-thread is ignored with a warning 410*4882a593Smuzhiyunif combined with -a or -C options. 411*4882a593Smuzhiyun 412*4882a593Smuzhiyun-D:: 413*4882a593Smuzhiyun--delay=:: 414*4882a593SmuzhiyunAfter starting the program, wait msecs before measuring (-1: start with events 415*4882a593Smuzhiyundisabled). This is useful to filter out the startup phase of the program, which 416*4882a593Smuzhiyunis often very different. 417*4882a593Smuzhiyun 418*4882a593Smuzhiyun-I:: 419*4882a593Smuzhiyun--intr-regs:: 420*4882a593SmuzhiyunCapture machine state (registers) at interrupt, i.e., on counter overflows for 421*4882a593Smuzhiyuneach sample. List of captured registers depends on the architecture. This option 422*4882a593Smuzhiyunis off by default. It is possible to select the registers to sample using their 423*4882a593Smuzhiyunsymbolic names, e.g. on x86, ax, si. To list the available registers use 424*4882a593Smuzhiyun--intr-regs=\?. To name registers, pass a comma separated list such as 425*4882a593Smuzhiyun--intr-regs=ax,bx. The list of register is architecture dependent. 426*4882a593Smuzhiyun 427*4882a593Smuzhiyun--user-regs:: 428*4882a593SmuzhiyunSimilar to -I, but capture user registers at sample time. To list the available 429*4882a593Smuzhiyunuser registers use --user-regs=\?. 430*4882a593Smuzhiyun 431*4882a593Smuzhiyun--running-time:: 432*4882a593SmuzhiyunRecord running and enabled time for read events (:S) 433*4882a593Smuzhiyun 434*4882a593Smuzhiyun-k:: 435*4882a593Smuzhiyun--clockid:: 436*4882a593SmuzhiyunSets the clock id to use for the various time fields in the perf_event_type 437*4882a593Smuzhiyunrecords. See clock_gettime(). In particular CLOCK_MONOTONIC and 438*4882a593SmuzhiyunCLOCK_MONOTONIC_RAW are supported, some events might also allow 439*4882a593SmuzhiyunCLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI. 440*4882a593Smuzhiyun 441*4882a593Smuzhiyun-S:: 442*4882a593Smuzhiyun--snapshot:: 443*4882a593SmuzhiyunSelect AUX area tracing Snapshot Mode. This option is valid only with an 444*4882a593SmuzhiyunAUX area tracing event. Optionally, certain snapshot capturing parameters 445*4882a593Smuzhiyuncan be specified in a string that follows this option: 446*4882a593Smuzhiyun 'e': take one last snapshot on exit; guarantees that there is at least one 447*4882a593Smuzhiyun snapshot in the output file; 448*4882a593Smuzhiyun <size>: if the PMU supports this, specify the desired snapshot size. 449*4882a593Smuzhiyun 450*4882a593SmuzhiyunIn Snapshot Mode trace data is captured only when signal SIGUSR2 is received 451*4882a593Smuzhiyunand on exit if the above 'e' option is given. 452*4882a593Smuzhiyun 453*4882a593Smuzhiyun--aux-sample[=OPTIONS]:: 454*4882a593SmuzhiyunSelect AUX area sampling. At least one of the events selected by the -e option 455*4882a593Smuzhiyunmust be an AUX area event. Samples on other events will be created containing 456*4882a593Smuzhiyundata from the AUX area. Optionally sample size may be specified, otherwise it 457*4882a593Smuzhiyundefaults to 4KiB. 458*4882a593Smuzhiyun 459*4882a593Smuzhiyun--proc-map-timeout:: 460*4882a593SmuzhiyunWhen processing pre-existing threads /proc/XXX/mmap, it may take a long time, 461*4882a593Smuzhiyunbecause the file may be huge. A time out is needed in such cases. 462*4882a593SmuzhiyunThis option sets the time out limit. The default value is 500 ms. 463*4882a593Smuzhiyun 464*4882a593Smuzhiyun--switch-events:: 465*4882a593SmuzhiyunRecord context switch events i.e. events of type PERF_RECORD_SWITCH or 466*4882a593SmuzhiyunPERF_RECORD_SWITCH_CPU_WIDE. In some cases (e.g. Intel PT or CoreSight) 467*4882a593Smuzhiyunswitch events will be enabled automatically, which can be suppressed by 468*4882a593Smuzhiyunby the option --no-switch-events. 469*4882a593Smuzhiyun 470*4882a593Smuzhiyun--clang-path=PATH:: 471*4882a593SmuzhiyunPath to clang binary to use for compiling BPF scriptlets. 472*4882a593Smuzhiyun(enabled when BPF support is on) 473*4882a593Smuzhiyun 474*4882a593Smuzhiyun--clang-opt=OPTIONS:: 475*4882a593SmuzhiyunOptions passed to clang when compiling BPF scriptlets. 476*4882a593Smuzhiyun(enabled when BPF support is on) 477*4882a593Smuzhiyun 478*4882a593Smuzhiyun--vmlinux=PATH:: 479*4882a593SmuzhiyunSpecify vmlinux path which has debuginfo. 480*4882a593Smuzhiyun(enabled when BPF prologue is on) 481*4882a593Smuzhiyun 482*4882a593Smuzhiyun--buildid-all:: 483*4882a593SmuzhiyunRecord build-id of all DSOs regardless whether it's actually hit or not. 484*4882a593Smuzhiyun 485*4882a593Smuzhiyun--aio[=n]:: 486*4882a593SmuzhiyunUse <n> control blocks in asynchronous (Posix AIO) trace writing mode (default: 1, max: 4). 487*4882a593SmuzhiyunAsynchronous mode is supported only when linking Perf tool with libc library 488*4882a593Smuzhiyunproviding implementation for Posix AIO API. 489*4882a593Smuzhiyun 490*4882a593Smuzhiyun--affinity=mode:: 491*4882a593SmuzhiyunSet affinity mask of trace reading thread according to the policy defined by 'mode' value: 492*4882a593Smuzhiyun node - thread affinity mask is set to NUMA node cpu mask of the processed mmap buffer 493*4882a593Smuzhiyun cpu - thread affinity mask is set to cpu of the processed mmap buffer 494*4882a593Smuzhiyun 495*4882a593Smuzhiyun--mmap-flush=number:: 496*4882a593Smuzhiyun 497*4882a593SmuzhiyunSpecify minimal number of bytes that is extracted from mmap data pages and 498*4882a593Smuzhiyunprocessed for output. One can specify the number using B/K/M/G suffixes. 499*4882a593Smuzhiyun 500*4882a593SmuzhiyunThe maximal allowed value is a quarter of the size of mmaped data pages. 501*4882a593Smuzhiyun 502*4882a593SmuzhiyunThe default option value is 1 byte which means that every time that the output 503*4882a593Smuzhiyunwriting thread finds some new data in the mmaped buffer the data is extracted, 504*4882a593Smuzhiyunpossibly compressed (-z) and written to the output, perf.data or pipe. 505*4882a593Smuzhiyun 506*4882a593SmuzhiyunLarger data chunks are compressed more effectively in comparison to smaller 507*4882a593Smuzhiyunchunks so extraction of larger chunks from the mmap data pages is preferable 508*4882a593Smuzhiyunfrom the perspective of output size reduction. 509*4882a593Smuzhiyun 510*4882a593SmuzhiyunAlso at some cases executing less output write syscalls with bigger data size 511*4882a593Smuzhiyuncan take less time than executing more output write syscalls with smaller data 512*4882a593Smuzhiyunsize thus lowering runtime profiling overhead. 513*4882a593Smuzhiyun 514*4882a593Smuzhiyun-z:: 515*4882a593Smuzhiyun--compression-level[=n]:: 516*4882a593SmuzhiyunProduce compressed trace using specified level n (default: 1 - fastest compression, 517*4882a593Smuzhiyun22 - smallest trace) 518*4882a593Smuzhiyun 519*4882a593Smuzhiyun--all-kernel:: 520*4882a593SmuzhiyunConfigure all used events to run in kernel space. 521*4882a593Smuzhiyun 522*4882a593Smuzhiyun--all-user:: 523*4882a593SmuzhiyunConfigure all used events to run in user space. 524*4882a593Smuzhiyun 525*4882a593Smuzhiyun--kernel-callchains:: 526*4882a593SmuzhiyunCollect callchains only from kernel space. I.e. this option sets 527*4882a593Smuzhiyunperf_event_attr.exclude_callchain_user to 1. 528*4882a593Smuzhiyun 529*4882a593Smuzhiyun--user-callchains:: 530*4882a593SmuzhiyunCollect callchains only from user space. I.e. this option sets 531*4882a593Smuzhiyunperf_event_attr.exclude_callchain_kernel to 1. 532*4882a593Smuzhiyun 533*4882a593SmuzhiyunDon't use both --kernel-callchains and --user-callchains at the same time or no 534*4882a593Smuzhiyuncallchains will be collected. 535*4882a593Smuzhiyun 536*4882a593Smuzhiyun--timestamp-filename 537*4882a593SmuzhiyunAppend timestamp to output file name. 538*4882a593Smuzhiyun 539*4882a593Smuzhiyun--timestamp-boundary:: 540*4882a593SmuzhiyunRecord timestamp boundary (time of first/last samples). 541*4882a593Smuzhiyun 542*4882a593Smuzhiyun--switch-output[=mode]:: 543*4882a593SmuzhiyunGenerate multiple perf.data files, timestamp prefixed, switching to a new one 544*4882a593Smuzhiyunbased on 'mode' value: 545*4882a593Smuzhiyun "signal" - when receiving a SIGUSR2 (default value) or 546*4882a593Smuzhiyun <size> - when reaching the size threshold, size is expected to 547*4882a593Smuzhiyun be a number with appended unit character - B/K/M/G 548*4882a593Smuzhiyun <time> - when reaching the time threshold, size is expected to 549*4882a593Smuzhiyun be a number with appended unit character - s/m/h/d 550*4882a593Smuzhiyun 551*4882a593Smuzhiyun Note: the precision of the size threshold hugely depends 552*4882a593Smuzhiyun on your configuration - the number and size of your ring 553*4882a593Smuzhiyun buffers (-m). It is generally more precise for higher sizes 554*4882a593Smuzhiyun (like >5M), for lower values expect different sizes. 555*4882a593Smuzhiyun 556*4882a593SmuzhiyunA possible use case is to, given an external event, slice the perf.data file 557*4882a593Smuzhiyunthat gets then processed, possibly via a perf script, to decide if that 558*4882a593Smuzhiyunparticular perf.data snapshot should be kept or not. 559*4882a593Smuzhiyun 560*4882a593SmuzhiyunImplies --timestamp-filename, --no-buildid and --no-buildid-cache. 561*4882a593SmuzhiyunThe reason for the latter two is to reduce the data file switching 562*4882a593Smuzhiyunoverhead. You can still switch them on with: 563*4882a593Smuzhiyun 564*4882a593Smuzhiyun --switch-output --no-no-buildid --no-no-buildid-cache 565*4882a593Smuzhiyun 566*4882a593Smuzhiyun--switch-output-event:: 567*4882a593SmuzhiyunEvents that will cause the switch of the perf.data file, auto-selecting 568*4882a593Smuzhiyun--switch-output=signal, the results are similar as internally the side band 569*4882a593Smuzhiyunthread will also send a SIGUSR2 to the main one. 570*4882a593Smuzhiyun 571*4882a593SmuzhiyunUses the same syntax as --event, it will just not be recorded, serving only to 572*4882a593Smuzhiyunswitch the perf.data file as soon as the --switch-output event is processed by 573*4882a593Smuzhiyuna separate sideband thread. 574*4882a593Smuzhiyun 575*4882a593SmuzhiyunThis sideband thread is also used to other purposes, like processing the 576*4882a593SmuzhiyunPERF_RECORD_BPF_EVENT records as they happen, asking the kernel for extra BPF 577*4882a593Smuzhiyuninformation, etc. 578*4882a593Smuzhiyun 579*4882a593Smuzhiyun--switch-max-files=N:: 580*4882a593Smuzhiyun 581*4882a593SmuzhiyunWhen rotating perf.data with --switch-output, only keep N files. 582*4882a593Smuzhiyun 583*4882a593Smuzhiyun--dry-run:: 584*4882a593SmuzhiyunParse options then exit. --dry-run can be used to detect errors in cmdline 585*4882a593Smuzhiyunoptions. 586*4882a593Smuzhiyun 587*4882a593Smuzhiyun'perf record --dry-run -e' can act as a BPF script compiler if llvm.dump-obj 588*4882a593Smuzhiyunin config file is set to true. 589*4882a593Smuzhiyun 590*4882a593Smuzhiyun--tail-synthesize:: 591*4882a593SmuzhiyunInstead of collecting non-sample events (for example, fork, comm, mmap) at 592*4882a593Smuzhiyunthe beginning of record, collect them during finalizing an output file. 593*4882a593SmuzhiyunThe collected non-sample events reflects the status of the system when 594*4882a593Smuzhiyunrecord is finished. 595*4882a593Smuzhiyun 596*4882a593Smuzhiyun--overwrite:: 597*4882a593SmuzhiyunMakes all events use an overwritable ring buffer. An overwritable ring 598*4882a593Smuzhiyunbuffer works like a flight recorder: when it gets full, the kernel will 599*4882a593Smuzhiyunoverwrite the oldest records, that thus will never make it to the 600*4882a593Smuzhiyunperf.data file. 601*4882a593Smuzhiyun 602*4882a593SmuzhiyunWhen '--overwrite' and '--switch-output' are used perf records and drops 603*4882a593Smuzhiyunevents until it receives a signal, meaning that something unusual was 604*4882a593Smuzhiyundetected that warrants taking a snapshot of the most current events, 605*4882a593Smuzhiyunthose fitting in the ring buffer at that moment. 606*4882a593Smuzhiyun 607*4882a593Smuzhiyun'overwrite' attribute can also be set or canceled for an event using 608*4882a593Smuzhiyunconfig terms. For example: 'cycles/overwrite/' and 'instructions/no-overwrite/'. 609*4882a593Smuzhiyun 610*4882a593SmuzhiyunImplies --tail-synthesize. 611*4882a593Smuzhiyun 612*4882a593Smuzhiyun--kcore:: 613*4882a593SmuzhiyunMake a copy of /proc/kcore and place it into a directory with the perf data file. 614*4882a593Smuzhiyun 615*4882a593Smuzhiyun--max-size=<size>:: 616*4882a593SmuzhiyunLimit the sample data max size, <size> is expected to be a number with 617*4882a593Smuzhiyunappended unit character - B/K/M/G 618*4882a593Smuzhiyun 619*4882a593Smuzhiyun--num-thread-synthesize:: 620*4882a593Smuzhiyun The number of threads to run when synthesizing events for existing processes. 621*4882a593Smuzhiyun By default, the number of threads equals 1. 622*4882a593Smuzhiyun 623*4882a593Smuzhiyunifdef::HAVE_LIBPFM[] 624*4882a593Smuzhiyun--pfm-events events:: 625*4882a593SmuzhiyunSelect a PMU event using libpfm4 syntax (see http://perfmon2.sf.net) 626*4882a593Smuzhiyunincluding support for event filters. For example '--pfm-events 627*4882a593Smuzhiyuninst_retired:any_p:u:c=1:i'. More than one event can be passed to the 628*4882a593Smuzhiyunoption using the comma separator. Hardware events and generic hardware 629*4882a593Smuzhiyunevents cannot be mixed together. The latter must be used with the -e 630*4882a593Smuzhiyunoption. The -e option and this one can be mixed and matched. Events 631*4882a593Smuzhiyuncan be grouped using the {} notation. 632*4882a593Smuzhiyunendif::HAVE_LIBPFM[] 633*4882a593Smuzhiyun 634*4882a593Smuzhiyun--control=fifo:ctl-fifo[,ack-fifo]:: 635*4882a593Smuzhiyun--control=fd:ctl-fd[,ack-fd]:: 636*4882a593Smuzhiyunctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as follows. 637*4882a593SmuzhiyunListen on ctl-fd descriptor for command to control measurement ('enable': enable events, 638*4882a593Smuzhiyun'disable': disable events, 'snapshot': AUX area tracing snapshot). Measurements can be 639*4882a593Smuzhiyunstarted with events disabled using --delay=-1 option. Optionally send control command 640*4882a593Smuzhiyuncompletion ('ack\n') to ack-fd descriptor to synchronize with the controlling process. 641*4882a593SmuzhiyunExample of bash shell script to enable and disable events during measurements: 642*4882a593Smuzhiyun 643*4882a593Smuzhiyun #!/bin/bash 644*4882a593Smuzhiyun 645*4882a593Smuzhiyun ctl_dir=/tmp/ 646*4882a593Smuzhiyun 647*4882a593Smuzhiyun ctl_fifo=${ctl_dir}perf_ctl.fifo 648*4882a593Smuzhiyun test -p ${ctl_fifo} && unlink ${ctl_fifo} 649*4882a593Smuzhiyun mkfifo ${ctl_fifo} 650*4882a593Smuzhiyun exec {ctl_fd}<>${ctl_fifo} 651*4882a593Smuzhiyun 652*4882a593Smuzhiyun ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo 653*4882a593Smuzhiyun test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo} 654*4882a593Smuzhiyun mkfifo ${ctl_ack_fifo} 655*4882a593Smuzhiyun exec {ctl_fd_ack}<>${ctl_ack_fifo} 656*4882a593Smuzhiyun 657*4882a593Smuzhiyun perf record -D -1 -e cpu-cycles -a \ 658*4882a593Smuzhiyun --control fd:${ctl_fd},${ctl_fd_ack} \ 659*4882a593Smuzhiyun -- sleep 30 & 660*4882a593Smuzhiyun perf_pid=$! 661*4882a593Smuzhiyun 662*4882a593Smuzhiyun sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})" 663*4882a593Smuzhiyun sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})" 664*4882a593Smuzhiyun 665*4882a593Smuzhiyun exec {ctl_fd_ack}>&- 666*4882a593Smuzhiyun unlink ${ctl_ack_fifo} 667*4882a593Smuzhiyun 668*4882a593Smuzhiyun exec {ctl_fd}>&- 669*4882a593Smuzhiyun unlink ${ctl_fifo} 670*4882a593Smuzhiyun 671*4882a593Smuzhiyun wait -n ${perf_pid} 672*4882a593Smuzhiyun exit $? 673*4882a593Smuzhiyun 674*4882a593Smuzhiyun 675*4882a593SmuzhiyunSEE ALSO 676*4882a593Smuzhiyun-------- 677*4882a593Smuzhiyunlinkperf:perf-stat[1], linkperf:perf-list[1], linkperf:perf-intel-pt[1] 678