intel-pt.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. Intel Processor Trace
  2. =====================
  3. Overview
  4. ========
  5. Intel Processor Trace (Intel PT) is an extension of Intel Architecture that
  6. collects information about software execution such as control flow, execution
  7. modes and timings and formats it into highly compressed binary packets.
  8. Technical details are documented in the Intel 64 and IA-32 Architectures
  9. Software Developer Manuals, Chapter 36 Intel Processor Trace.
  10. Intel PT is first supported in Intel Core M and 5th generation Intel Core
  11. processors that are based on the Intel micro-architecture code name Broadwell.
  12. Trace data is collected by 'perf record' and stored within the perf.data file.
  13. See below for options to 'perf record'.
  14. Trace data must be 'decoded' which involves walking the object code and matching
  15. the trace data packets. For example a TNT packet only tells whether a
  16. conditional branch was taken or not taken, so to make use of that packet the
  17. decoder must know precisely which instruction was being executed.
  18. Decoding is done on-the-fly. The decoder outputs samples in the same format as
  19. samples output by perf hardware events, for example as though the "instructions"
  20. or "branches" events had been recorded. Presently 3 tools support this:
  21. 'perf script', 'perf report' and 'perf inject'. See below for more information
  22. on using those tools.
  23. The main distinguishing feature of Intel PT is that the decoder can determine
  24. the exact flow of software execution. Intel PT can be used to understand why
  25. and how did software get to a certain point, or behave a certain way. The
  26. software does not have to be recompiled, so Intel PT works with debug or release
  27. builds, however the executed images are needed - which makes use in JIT-compiled
  28. environments, or with self-modified code, a challenge. Also symbols need to be
  29. provided to make sense of addresses.
  30. A limitation of Intel PT is that it produces huge amounts of trace data
  31. (hundreds of megabytes per second per core) which takes a long time to decode,
  32. for example two or three orders of magnitude longer than it took to collect.
  33. Another limitation is the performance impact of tracing, something that will
  34. vary depending on the use-case and architecture.
  35. Quickstart
  36. ==========
  37. It is important to start small. That is because it is easy to capture vastly
  38. more data than can possibly be processed.
  39. The simplest thing to do with Intel PT is userspace profiling of small programs.
  40. Data is captured with 'perf record' e.g. to trace 'ls' userspace-only:
  41. perf record -e intel_pt//u ls
  42. And profiled with 'perf report' e.g.
  43. perf report
  44. To also trace kernel space presents a problem, namely kernel self-modifying
  45. code. A fairly good kernel image is available in /proc/kcore but to get an
  46. accurate image a copy of /proc/kcore needs to be made under the same conditions
  47. as the data capture. A script perf-with-kcore can do that, but beware that the
  48. script makes use of 'sudo' to copy /proc/kcore. If you have perf installed
  49. locally from the source tree you can do:
  50. ~/libexec/perf-core/perf-with-kcore record pt_ls -e intel_pt// -- ls
  51. which will create a directory named 'pt_ls' and put the perf.data file and
  52. copies of /proc/kcore, /proc/kallsyms and /proc/modules into it. Then to use
  53. 'perf report' becomes:
  54. ~/libexec/perf-core/perf-with-kcore report pt_ls
  55. Because samples are synthesized after-the-fact, the sampling period can be
  56. selected for reporting. e.g. sample every microsecond
  57. ~/libexec/perf-core/perf-with-kcore report pt_ls --itrace=i1usge
  58. See the sections below for more information about the --itrace option.
  59. Beware the smaller the period, the more samples that are produced, and the
  60. longer it takes to process them.
  61. Also note that the coarseness of Intel PT timing information will start to
  62. distort the statistical value of the sampling as the sampling period becomes
  63. smaller.
  64. To represent software control flow, "branches" samples are produced. By default
  65. a branch sample is synthesized for every single branch. To get an idea what
  66. data is available you can use the 'perf script' tool with no parameters, which
  67. will list all the samples.
  68. perf record -e intel_pt//u ls
  69. perf script
  70. An interesting field that is not printed by default is 'flags' which can be
  71. displayed as follows:
  72. perf script -Fcomm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr,symoff,flags
  73. The flags are "bcrosyiABEx" which stand for branch, call, return, conditional,
  74. system, asynchronous, interrupt, transaction abort, trace begin, trace end, and
  75. in transaction, respectively.
  76. While it is possible to create scripts to analyze the data, an alternative
  77. approach is available to export the data to a postgresql database. Refer to
  78. script export-to-postgresql.py for more details, and to script
  79. call-graph-from-postgresql.py for an example of using the database.
  80. As mentioned above, it is easy to capture too much data. One way to limit the
  81. data captured is to use 'snapshot' mode which is explained further below.
  82. Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
  83. Another problem that will be experienced is decoder errors. They can be caused
  84. by inability to access the executed image, self-modified or JIT-ed code, or the
  85. inability to match side-band information (such as context switches and mmaps)
  86. which results in the decoder not knowing what code was executed.
  87. There is also the problem of perf not being able to copy the data fast enough,
  88. resulting in data lost because the buffer was full. See 'Buffer handling' below
  89. for more details.
  90. perf record
  91. ===========
  92. new event
  93. ---------
  94. The Intel PT kernel driver creates a new PMU for Intel PT. PMU events are
  95. selected by providing the PMU name followed by the "config" separated by slashes.
  96. An enhancement has been made to allow default "config" e.g. the option
  97. -e intel_pt//
  98. will use a default config value. Currently that is the same as
  99. -e intel_pt/tsc,noretcomp=0/
  100. which is the same as
  101. -e intel_pt/tsc=1,noretcomp=0/
  102. Note there are now new config terms - see section 'config terms' further below.
  103. The config terms are listed in /sys/devices/intel_pt/format. They are bit
  104. fields within the config member of the struct perf_event_attr which is
  105. passed to the kernel by the perf_event_open system call. They correspond to bit
  106. fields in the IA32_RTIT_CTL MSR. Here is a list of them and their definitions:
  107. $ grep -H . /sys/bus/event_source/devices/intel_pt/format/*
  108. /sys/bus/event_source/devices/intel_pt/format/cyc:config:1
  109. /sys/bus/event_source/devices/intel_pt/format/cyc_thresh:config:19-22
  110. /sys/bus/event_source/devices/intel_pt/format/mtc:config:9
  111. /sys/bus/event_source/devices/intel_pt/format/mtc_period:config:14-17
  112. /sys/bus/event_source/devices/intel_pt/format/noretcomp:config:11
  113. /sys/bus/event_source/devices/intel_pt/format/psb_period:config:24-27
  114. /sys/bus/event_source/devices/intel_pt/format/tsc:config:10
  115. Note that the default config must be overridden for each term i.e.
  116. -e intel_pt/noretcomp=0/
  117. is the same as:
  118. -e intel_pt/tsc=1,noretcomp=0/
  119. So, to disable TSC packets use:
  120. -e intel_pt/tsc=0/
  121. It is also possible to specify the config value explicitly:
  122. -e intel_pt/config=0x400/
  123. Note that, as with all events, the event is suffixed with event modifiers:
  124. u userspace
  125. k kernel
  126. h hypervisor
  127. G guest
  128. H host
  129. p precise ip
  130. 'h', 'G' and 'H' are for virtualization which is not supported by Intel PT.
  131. 'p' is also not relevant to Intel PT. So only options 'u' and 'k' are
  132. meaningful for Intel PT.
  133. perf_event_attr is displayed if the -vv option is used e.g.
  134. ------------------------------------------------------------
  135. perf_event_attr:
  136. type 6
  137. size 112
  138. config 0x400
  139. { sample_period, sample_freq } 1
  140. sample_type IP|TID|TIME|CPU|IDENTIFIER
  141. read_format ID
  142. disabled 1
  143. inherit 1
  144. exclude_kernel 1
  145. exclude_hv 1
  146. enable_on_exec 1
  147. sample_id_all 1
  148. ------------------------------------------------------------
  149. sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8
  150. sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8
  151. sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8
  152. sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8
  153. ------------------------------------------------------------
  154. config terms
  155. ------------
  156. The June 2015 version of Intel 64 and IA-32 Architectures Software Developer
  157. Manuals, Chapter 36 Intel Processor Trace, defined new Intel PT features.
  158. Some of the features are reflect in new config terms. All the config terms are
  159. described below.
  160. tsc Always supported. Produces TSC timestamp packets to provide
  161. timing information. In some cases it is possible to decode
  162. without timing information, for example a per-thread context
  163. that does not overlap executable memory maps.
  164. The default config selects tsc (i.e. tsc=1).
  165. noretcomp Always supported. Disables "return compression" so a TIP packet
  166. is produced when a function returns. Causes more packets to be
  167. produced but might make decoding more reliable.
  168. The default config does not select noretcomp (i.e. noretcomp=0).
  169. psb_period Allows the frequency of PSB packets to be specified.
  170. The PSB packet is a synchronization packet that provides a
  171. starting point for decoding or recovery from errors.
  172. Support for psb_period is indicated by:
  173. /sys/bus/event_source/devices/intel_pt/caps/psb_cyc
  174. which contains "1" if the feature is supported and "0"
  175. otherwise.
  176. Valid values are given by:
  177. /sys/bus/event_source/devices/intel_pt/caps/psb_periods
  178. which contains a hexadecimal value, the bits of which represent
  179. valid values e.g. bit 2 set means value 2 is valid.
  180. The psb_period value is converted to the approximate number of
  181. trace bytes between PSB packets as:
  182. 2 ^ (value + 11)
  183. e.g. value 3 means 16KiB bytes between PSBs
  184. If an invalid value is entered, the error message
  185. will give a list of valid values e.g.
  186. $ perf record -e intel_pt/psb_period=15/u uname
  187. Invalid psb_period for intel_pt. Valid values are: 0-5
  188. If MTC packets are selected, the default config selects a value
  189. of 3 (i.e. psb_period=3) or the nearest lower value that is
  190. supported (0 is always supported). Otherwise the default is 0.
  191. If decoding is expected to be reliable and the buffer is large
  192. then a large PSB period can be used.
  193. Because a TSC packet is produced with PSB, the PSB period can
  194. also affect the granularity to timing information in the absence
  195. of MTC or CYC.
  196. mtc Produces MTC timing packets.
  197. MTC packets provide finer grain timestamp information than TSC
  198. packets. MTC packets record time using the hardware crystal
  199. clock (CTC) which is related to TSC packets using a TMA packet.
  200. Support for this feature is indicated by:
  201. /sys/bus/event_source/devices/intel_pt/caps/mtc
  202. which contains "1" if the feature is supported and
  203. "0" otherwise.
  204. The frequency of MTC packets can also be specified - see
  205. mtc_period below.
  206. mtc_period Specifies how frequently MTC packets are produced - see mtc
  207. above for how to determine if MTC packets are supported.
  208. Valid values are given by:
  209. /sys/bus/event_source/devices/intel_pt/caps/mtc_periods
  210. which contains a hexadecimal value, the bits of which represent
  211. valid values e.g. bit 2 set means value 2 is valid.
  212. The mtc_period value is converted to the MTC frequency as:
  213. CTC-frequency / (2 ^ value)
  214. e.g. value 3 means one eighth of CTC-frequency
  215. Where CTC is the hardware crystal clock, the frequency of which
  216. can be related to TSC via values provided in cpuid leaf 0x15.
  217. If an invalid value is entered, the error message
  218. will give a list of valid values e.g.
  219. $ perf record -e intel_pt/mtc_period=15/u uname
  220. Invalid mtc_period for intel_pt. Valid values are: 0,3,6,9
  221. The default value is 3 or the nearest lower value
  222. that is supported (0 is always supported).
  223. cyc Produces CYC timing packets.
  224. CYC packets provide even finer grain timestamp information than
  225. MTC and TSC packets. A CYC packet contains the number of CPU
  226. cycles since the last CYC packet. Unlike MTC and TSC packets,
  227. CYC packets are only sent when another packet is also sent.
  228. Support for this feature is indicated by:
  229. /sys/bus/event_source/devices/intel_pt/caps/psb_cyc
  230. which contains "1" if the feature is supported and
  231. "0" otherwise.
  232. The number of CYC packets produced can be reduced by specifying
  233. a threshold - see cyc_thresh below.
  234. cyc_thresh Specifies how frequently CYC packets are produced - see cyc
  235. above for how to determine if CYC packets are supported.
  236. Valid cyc_thresh values are given by:
  237. /sys/bus/event_source/devices/intel_pt/caps/cycle_thresholds
  238. which contains a hexadecimal value, the bits of which represent
  239. valid values e.g. bit 2 set means value 2 is valid.
  240. The cyc_thresh value represents the minimum number of CPU cycles
  241. that must have passed before a CYC packet can be sent. The
  242. number of CPU cycles is:
  243. 2 ^ (value - 1)
  244. e.g. value 4 means 8 CPU cycles must pass before a CYC packet
  245. can be sent. Note a CYC packet is still only sent when another
  246. packet is sent, not at, e.g. every 8 CPU cycles.
  247. If an invalid value is entered, the error message
  248. will give a list of valid values e.g.
  249. $ perf record -e intel_pt/cyc,cyc_thresh=15/u uname
  250. Invalid cyc_thresh for intel_pt. Valid values are: 0-12
  251. CYC packets are not requested by default.
  252. new snapshot option
  253. -------------------
  254. The difference between full trace and snapshot from the kernel's perspective is
  255. that in full trace we don't overwrite trace data that the user hasn't collected
  256. yet (and indicated that by advancing aux_tail), whereas in snapshot mode we let
  257. the trace run and overwrite older data in the buffer so that whenever something
  258. interesting happens, we can stop it and grab a snapshot of what was going on
  259. around that interesting moment.
  260. To select snapshot mode a new option has been added:
  261. -S
  262. Optionally it can be followed by the snapshot size e.g.
  263. -S0x100000
  264. The default snapshot size is the auxtrace mmap size. If neither auxtrace mmap size
  265. nor snapshot size is specified, then the default is 4MiB for privileged users
  266. (or if /proc/sys/kernel/perf_event_paranoid < 0), 128KiB for unprivileged users.
  267. If an unprivileged user does not specify mmap pages, the mmap pages will be
  268. reduced as described in the 'new auxtrace mmap size option' section below.
  269. The snapshot size is displayed if the option -vv is used e.g.
  270. Intel PT snapshot size: %zu
  271. new auxtrace mmap size option
  272. ---------------------------
  273. Intel PT buffer size is specified by an addition to the -m option e.g.
  274. -m,16
  275. selects a buffer size of 16 pages i.e. 64KiB.
  276. Note that the existing functionality of -m is unchanged. The auxtrace mmap size
  277. is specified by the optional addition of a comma and the value.
  278. The default auxtrace mmap size for Intel PT is 4MiB/page_size for privileged users
  279. (or if /proc/sys/kernel/perf_event_paranoid < 0), 128KiB for unprivileged users.
  280. If an unprivileged user does not specify mmap pages, the mmap pages will be
  281. reduced from the default 512KiB/page_size to 256KiB/page_size, otherwise the
  282. user is likely to get an error as they exceed their mlock limit (Max locked
  283. memory as shown in /proc/self/limits). Note that perf does not count the first
  284. 512KiB (actually /proc/sys/kernel/perf_event_mlock_kb minus 1 page) per cpu
  285. against the mlock limit so an unprivileged user is allowed 512KiB per cpu plus
  286. their mlock limit (which defaults to 64KiB but is not multiplied by the number
  287. of cpus).
  288. In full-trace mode, powers of two are allowed for buffer size, with a minimum
  289. size of 2 pages. In snapshot mode, it is the same but the minimum size is
  290. 1 page.
  291. The mmap size and auxtrace mmap size are displayed if the -vv option is used e.g.
  292. mmap length 528384
  293. auxtrace mmap length 4198400
  294. Intel PT modes of operation
  295. ---------------------------
  296. Intel PT can be used in 2 modes:
  297. full-trace mode
  298. snapshot mode
  299. Full-trace mode traces continuously e.g.
  300. perf record -e intel_pt//u uname
  301. Snapshot mode captures the available data when a signal is sent e.g.
  302. perf record -v -e intel_pt//u -S ./loopy 1000000000 &
  303. [1] 11435
  304. kill -USR2 11435
  305. Recording AUX area tracing snapshot
  306. Note that the signal sent is SIGUSR2.
  307. Note that "Recording AUX area tracing snapshot" is displayed because the -v
  308. option is used.
  309. The 2 modes cannot be used together.
  310. Buffer handling
  311. ---------------
  312. There may be buffer limitations (i.e. single ToPa entry) which means that actual
  313. buffer sizes are limited to powers of 2 up to 4MiB (MAX_ORDER). In order to
  314. provide other sizes, and in particular an arbitrarily large size, multiple
  315. buffers are logically concatenated. However an interrupt must be used to switch
  316. between buffers. That has two potential problems:
  317. a) the interrupt may not be handled in time so that the current buffer
  318. becomes full and some trace data is lost.
  319. b) the interrupts may slow the system and affect the performance
  320. results.
  321. If trace data is lost, the driver sets 'truncated' in the PERF_RECORD_AUX event
  322. which the tools report as an error.
  323. In full-trace mode, the driver waits for data to be copied out before allowing
  324. the (logical) buffer to wrap-around. If data is not copied out quickly enough,
  325. again 'truncated' is set in the PERF_RECORD_AUX event. If the driver has to
  326. wait, the intel_pt event gets disabled. Because it is difficult to know when
  327. that happens, perf tools always re-enable the intel_pt event after copying out
  328. data.
  329. Intel PT and build ids
  330. ----------------------
  331. By default "perf record" post-processes the event stream to find all build ids
  332. for executables for all addresses sampled. Deliberately, Intel PT is not
  333. decoded for that purpose (it would take too long). Instead the build ids for
  334. all executables encountered (due to mmap, comm or task events) are included
  335. in the perf.data file.
  336. To see buildids included in the perf.data file use the command:
  337. perf buildid-list
  338. If the perf.data file contains Intel PT data, that is the same as:
  339. perf buildid-list --with-hits
  340. Snapshot mode and event disabling
  341. ---------------------------------
  342. In order to make a snapshot, the intel_pt event is disabled using an IOCTL,
  343. namely PERF_EVENT_IOC_DISABLE. However doing that can also disable the
  344. collection of side-band information. In order to prevent that, a dummy
  345. software event has been introduced that permits tracking events (like mmaps) to
  346. continue to be recorded while intel_pt is disabled. That is important to ensure
  347. there is complete side-band information to allow the decoding of subsequent
  348. snapshots.
  349. A test has been created for that. To find the test:
  350. perf test list
  351. ...
  352. 23: Test using a dummy software event to keep tracking
  353. To run the test:
  354. perf test 23
  355. 23: Test using a dummy software event to keep tracking : Ok
  356. perf record modes (nothing new here)
  357. ------------------------------------
  358. perf record essentially operates in one of three modes:
  359. per thread
  360. per cpu
  361. workload only
  362. "per thread" mode is selected by -t or by --per-thread (with -p or -u or just a
  363. workload).
  364. "per cpu" is selected by -C or -a.
  365. "workload only" mode is selected by not using the other options but providing a
  366. command to run (i.e. the workload).
  367. In per-thread mode an exact list of threads is traced. There is no inheritance.
  368. Each thread has its own event buffer.
  369. In per-cpu mode all processes (or processes from the selected cgroup i.e. -G
  370. option, or processes selected with -p or -u) are traced. Each cpu has its own
  371. buffer. Inheritance is allowed.
  372. In workload-only mode, the workload is traced but with per-cpu buffers.
  373. Inheritance is allowed. Note that you can now trace a workload in per-thread
  374. mode by using the --per-thread option.
  375. Privileged vs non-privileged users
  376. ----------------------------------
  377. Unless /proc/sys/kernel/perf_event_paranoid is set to -1, unprivileged users
  378. have memory limits imposed upon them. That affects what buffer sizes they can
  379. have as outlined above.
  380. Unless /proc/sys/kernel/perf_event_paranoid is set to -1, unprivileged users are
  381. not permitted to use tracepoints which means there is insufficient side-band
  382. information to decode Intel PT in per-cpu mode, and potentially workload-only
  383. mode too if the workload creates new processes.
  384. Note also, that to use tracepoints, read-access to debugfs is required. So if
  385. debugfs is not mounted or the user does not have read-access, it will again not
  386. be possible to decode Intel PT in per-cpu mode.
  387. sched_switch tracepoint
  388. -----------------------
  389. The sched_switch tracepoint is used to provide side-band data for Intel PT
  390. decoding. sched_switch events are automatically added. e.g. the second event
  391. shown below
  392. $ perf record -vv -e intel_pt//u uname
  393. ------------------------------------------------------------
  394. perf_event_attr:
  395. type 6
  396. size 112
  397. config 0x400
  398. { sample_period, sample_freq } 1
  399. sample_type IP|TID|TIME|CPU|IDENTIFIER
  400. read_format ID
  401. disabled 1
  402. inherit 1
  403. exclude_kernel 1
  404. exclude_hv 1
  405. enable_on_exec 1
  406. sample_id_all 1
  407. ------------------------------------------------------------
  408. sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8
  409. sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8
  410. sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8
  411. sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8
  412. ------------------------------------------------------------
  413. perf_event_attr:
  414. type 2
  415. size 112
  416. config 0x108
  417. { sample_period, sample_freq } 1
  418. sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER
  419. read_format ID
  420. inherit 1
  421. sample_id_all 1
  422. exclude_guest 1
  423. ------------------------------------------------------------
  424. sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8
  425. sys_perf_event_open: pid -1 cpu 1 group_fd -1 flags 0x8
  426. sys_perf_event_open: pid -1 cpu 2 group_fd -1 flags 0x8
  427. sys_perf_event_open: pid -1 cpu 3 group_fd -1 flags 0x8
  428. ------------------------------------------------------------
  429. perf_event_attr:
  430. type 1
  431. size 112
  432. config 0x9
  433. { sample_period, sample_freq } 1
  434. sample_type IP|TID|TIME|IDENTIFIER
  435. read_format ID
  436. disabled 1
  437. inherit 1
  438. exclude_kernel 1
  439. exclude_hv 1
  440. mmap 1
  441. comm 1
  442. enable_on_exec 1
  443. task 1
  444. sample_id_all 1
  445. mmap2 1
  446. comm_exec 1
  447. ------------------------------------------------------------
  448. sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8
  449. sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8
  450. sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8
  451. sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8
  452. mmap size 528384B
  453. AUX area mmap length 4194304
  454. perf event ring buffer mmapped per cpu
  455. Synthesizing auxtrace information
  456. Linux
  457. [ perf record: Woken up 1 times to write data ]
  458. [ perf record: Captured and wrote 0.042 MB perf.data ]
  459. Note, the sched_switch event is only added if the user is permitted to use it
  460. and only in per-cpu mode.
  461. Note also, the sched_switch event is only added if TSC packets are requested.
  462. That is because, in the absence of timing information, the sched_switch events
  463. cannot be matched against the Intel PT trace.
  464. perf script
  465. ===========
  466. By default, perf script will decode trace data found in the perf.data file.
  467. This can be further controlled by new option --itrace.
  468. New --itrace option
  469. -------------------
  470. Having no option is the same as
  471. --itrace
  472. which, in turn, is the same as
  473. --itrace=ibxe
  474. The letters are:
  475. i synthesize "instructions" events
  476. b synthesize "branches" events
  477. x synthesize "transactions" events
  478. c synthesize branches events (calls only)
  479. r synthesize branches events (returns only)
  480. e synthesize tracing error events
  481. d create a debug log
  482. g synthesize a call chain (use with i or x)
  483. l synthesize last branch entries (use with i or x)
  484. s skip initial number of events
  485. "Instructions" events look like they were recorded by "perf record -e
  486. instructions".
  487. "Branches" events look like they were recorded by "perf record -e branches". "c"
  488. and "r" can be combined to get calls and returns.
  489. "Transactions" events correspond to the start or end of transactions. The
  490. 'flags' field can be used in perf script to determine whether the event is a
  491. tranasaction start, commit or abort.
  492. Error events are new. They show where the decoder lost the trace. Error events
  493. are quite important. Users must know if what they are seeing is a complete
  494. picture or not.
  495. The "d" option will cause the creation of a file "intel_pt.log" containing all
  496. decoded packets and instructions. Note that this option slows down the decoder
  497. and that the resulting file may be very large.
  498. In addition, the period of the "instructions" event can be specified. e.g.
  499. --itrace=i10us
  500. sets the period to 10us i.e. one instruction sample is synthesized for each 10
  501. microseconds of trace. Alternatives to "us" are "ms" (milliseconds),
  502. "ns" (nanoseconds), "t" (TSC ticks) or "i" (instructions).
  503. "ms", "us" and "ns" are converted to TSC ticks.
  504. The timing information included with Intel PT does not give the time of every
  505. instruction. Consequently, for the purpose of sampling, the decoder estimates
  506. the time since the last timing packet based on 1 tick per instruction. The time
  507. on the sample is *not* adjusted and reflects the last known value of TSC.
  508. For Intel PT, the default period is 100us.
  509. Setting it to a zero period means "as often as possible".
  510. In the case of Intel PT that is the same as a period of 1 and a unit of
  511. 'instructions' (i.e. --itrace=i1i).
  512. Also the call chain size (default 16, max. 1024) for instructions or
  513. transactions events can be specified. e.g.
  514. --itrace=ig32
  515. --itrace=xg32
  516. Also the number of last branch entries (default 64, max. 1024) for instructions or
  517. transactions events can be specified. e.g.
  518. --itrace=il10
  519. --itrace=xl10
  520. Note that last branch entries are cleared for each sample, so there is no overlap
  521. from one sample to the next.
  522. To disable trace decoding entirely, use the option --no-itrace.
  523. It is also possible to skip events generated (instructions, branches, transactions)
  524. at the beginning. This is useful to ignore initialization code.
  525. --itrace=i0nss1000000
  526. skips the first million instructions.
  527. dump option
  528. -----------
  529. perf script has an option (-D) to "dump" the events i.e. display the binary
  530. data.
  531. When -D is used, Intel PT packets are displayed. The packet decoder does not
  532. pay attention to PSB packets, but just decodes the bytes - so the packets seen
  533. by the actual decoder may not be identical in places where the data is corrupt.
  534. One example of that would be when the buffer-switching interrupt has been too
  535. slow, and the buffer has been filled completely. In that case, the last packet
  536. in the buffer might be truncated and immediately followed by a PSB as the trace
  537. continues in the next buffer.
  538. To disable the display of Intel PT packets, combine the -D option with
  539. --no-itrace.
  540. perf report
  541. ===========
  542. By default, perf report will decode trace data found in the perf.data file.
  543. This can be further controlled by new option --itrace exactly the same as
  544. perf script, with the exception that the default is --itrace=igxe.
  545. perf inject
  546. ===========
  547. perf inject also accepts the --itrace option in which case tracing data is
  548. removed and replaced with the synthesized events. e.g.
  549. perf inject --itrace -i perf.data -o perf.data.new
  550. Below is an example of using Intel PT with autofdo. It requires autofdo
  551. (https://github.com/google/autofdo) and gcc version 5. The bubble
  552. sort example is from the AutoFDO tutorial (https://gcc.gnu.org/wiki/AutoFDO/Tutorial)
  553. amended to take the number of elements as a parameter.
  554. $ gcc-5 -O3 sort.c -o sort_optimized
  555. $ ./sort_optimized 30000
  556. Bubble sorting array of 30000 elements
  557. 2254 ms
  558. $ cat ~/.perfconfig
  559. [intel-pt]
  560. mispred-all
  561. $ perf record -e intel_pt//u ./sort 3000
  562. Bubble sorting array of 3000 elements
  563. 58 ms
  564. [ perf record: Woken up 2 times to write data ]
  565. [ perf record: Captured and wrote 3.939 MB perf.data ]
  566. $ perf inject -i perf.data -o inj --itrace=i100usle --strip
  567. $ ./create_gcov --binary=./sort --profile=inj --gcov=sort.gcov -gcov_version=1
  568. $ gcc-5 -O3 -fauto-profile=sort.gcov sort.c -o sort_autofdo
  569. $ ./sort_autofdo 30000
  570. Bubble sorting array of 30000 elements
  571. 2155 ms
  572. Note there is currently no advantage to using Intel PT instead of LBR, but
  573. that may change in the future if greater use is made of the data.