Bug 1788332 [wpt PR 35694] - Only fire togglechange events when value changes., a...
[gecko.git] / docs / performance / jit_profiling_with_perf.md
blob43e6f8bf032061a74509805160ac0a332d6e708f
1 # JIT Profiling with perf
3 perf is a performance profiling tool available on Linux that is capable of measuring performance events such as cycles, instructions executed, cache misses, etc and providing assembly and source code annotation.
4 It is possible to collect performance profiles of the SpiderMonkey JIT using perf on Linux and also annotate the generated assembly with the IR opcodes that were used during compilation as shown below.
6 ![](img/annotation.png)
8 ### Build setup
10 To enable JIT profiling with perf jitdump, you must build Firefox or the JS shell with the following flag:
12 ```
13 ac_add_options --enable-perf
14 ```
16 ### Environment Variables
18 Two environment variables are available for perf JIT profiling:
20 The first environment variable must be defined for SpiderMonkey to generate the necessary jitdump binary files for JIT profiling.
21 The supported values are "ir", "src" and "func".  `IONPERF=ir` will enable IR annotation, `IONPERF=src` will enable source code annotation **only if** perf can read the source file locally.  `IONPERF=func` will disable all annotation and only function names will be available.  It is recommended to use `IONPERF=ir` for most situations.
23 The second environment variable is optional, but is highly recommended to avoid polluting your cwd by putting all jitdump files into a separate directory:
24 ```
25 mkdir output
26 export PERF_SPEW_DIR=output
27 ```
29 ### Profiling the JS shell
31 Profiling the JS shell requires the following commands but is very straight forward.
33 Begin by removing any pre-existing jitdump files:
35 `rm -rf output` or `rm -f jitted-*.so jit.data perf.data jit-*.dump jitdump-*.txt`
37 Next define environment variables:
38 ```
39 export IONPERF=ir
40 export PERF_SPEW_DIR=output
41 ```
43 Run your test case with perf attached:
44 ```
45 perf record -g -k 1 /home/denis/src/mozilla-central/obj-js/dist/bin/js test.js
46 ```
48 Inject the jitdump files into your perf.data file:
49 ```
50 perf inject -j -i perf.data -o jit.data
51 ```
53 View the profile:
54 ```
55 perf report --no-children -i jit.data
56 ```
58 All of the above commands can be put into a single shell script.
60 ### Profiling the Browser
62 Profiling the browser is less straight forward than the shell, but the only main difference is that perf must attach to the content process while it is running.
64 Begin by removing any pre-existing jitdump files:
66 `rm -rf output` or `rm -f jitted-*.so jit.data perf.data jit-*.dump jitdump-*.txt`
68 Next define environment variables:
69 ```
70 export IONPERF=ir
71 export PERF_SPEW_DIR=output
72 export MOZ_DISABLE_CONTENT_SANDBOX=1
73 ```
75 Run the Firefox browser
76 ```
77 ~/mozilla-central/obj-opt64/dist/bin/firefox -no-remote -profile ~/mozilla-central/obj-opt64/tmp/profile-default &
78 ```
80 Navigate to the test case, but do not start it yet.  Then hover over the tab to get the content process PID.
82 ![](img/pid.png)
84 Attach perf to begin profiling:
85 ```
86 perf record -g -k 1 -p <pid>
87 ```
89 Close the browser when finished benchmarking.
91 Inject the jitdump files into your perf.data file:
92 ```
93 perf inject -j -i perf.data -o jit.data
94 ```
96 View the profile:
97 ```
98 perf report --no-children -i jit.data
99 ```