blob: 029fb974d47c044976b83dc600ebef655cd4fb94 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:091# Linux Profiling
2
qyearsleyc0dc6f42016-12-02 22:13:393How to profile Chromium on Linux.
andybons3322f762015-08-24 21:37:094
andybonsad92aa32015-08-31 02:27:445See
6[Profiling Chromium and WebKit](https://sites.google.com/a/chromium.org/dev/developers/profiling-chromium-and-webkit)
7for alternative discussion.
andybons3322f762015-08-24 21:37:098
9## CPU Profiling
10
11gprof: reported not to work (taking an hour to load on our large binary).
12
andybonsad92aa32015-08-31 02:27:4413oprofile: Dean uses it, says it's good. (As of 9/16/9 oprofile only supports
14timers on the new Z600 boxes, which doesn't give good granularity for profiling
15startup).
andybons3322f762015-08-24 21:37:0916
17TODO(willchan): Talk more about oprofile, gprof, etc.
18
andybonsad92aa32015-08-31 02:27:4419Also see
20https://sites.google.com/a/chromium.org/dev/developers/profiling-chromium-and-webkit
andybons3322f762015-08-24 21:37:0921
22### perf
23
andybonsad92aa32015-08-31 02:27:4424`perf` is the successor to `oprofile`. It's maintained in the kernel tree, it's
25available on Ubuntu in the package `linux-tools`.
andybons3322f762015-08-24 21:37:0926
27To capture data, you use `perf record`. Some examples:
andybonsad92aa32015-08-31 02:27:4428
29```shell
30# captures the full execution of the program
31perf record -f -g out/Release/chrome
32# captures a particular pid, you can start at the right time, and stop with
33# ctrl-C
34perf record -f -g -p 1234
35perf record -f -g -a # captures the whole system
andybons3322f762015-08-24 21:37:0936```
37
andybonsad92aa32015-08-31 02:27:4438Some versions of the perf command can be confused by process renames. Affected
39versions will be unable to resolve Chromium's symbols if it was started through
40perf, as in the first example above. It should work correctly if you attach to
41an existing Chromium process as shown in the second example. (This is known to
42be broken as late as 3.2.5 and fixed as early as 3.11.rc3.g36f571. The actual
43affected range is likely much smaller. You can download and build your own perf
44from source.)
andybons3322f762015-08-24 21:37:0945
andybonsad92aa32015-08-31 02:27:4446The last one is useful on limited systems with few cores and low memory
47bandwidth, where the CPU cycles are shared between several processes (e.g.
48chrome browser, renderer, plugin, X, pulseaudio, etc.)
andybons3322f762015-08-24 21:37:0949
50To look at the data, you use:
andybonsad92aa32015-08-31 02:27:4451
52 perf report
andybons3322f762015-08-24 21:37:0953
54This will use the previously captured data (`perf.data`).
55
andybons3322f762015-08-24 21:37:0956## Heap Profiling
57
andybons3322f762015-08-24 21:37:0958#### Dumping a profile of a running process
59
Thiabaud Engelbrecht6d443612022-02-11 00:22:1860To programmatically generate a heap profile before exit, you can use gdb to
61attach at any point:
andybons3322f762015-08-24 21:37:0962
andybonsad92aa32015-08-31 02:27:44631. Attach gdb to the process: `$ gdb -p 12345`
Thiabaud Engelbrecht6d443612022-02-11 00:22:18642. Cause it to dump a profile: `(gdb) p HeapProfilerDump("foobar")`
653. The filename will be printed on the console you started Chrome from; e.g.
andybonsad92aa32015-08-31 02:27:4466 "`Dumping heap profile to heap.0001.heap (foobar)`"
andybons3322f762015-08-24 21:37:0967
68#### Analyzing dumps
69
andybonsad92aa32015-08-31 02:27:4470You can then analyze dumps using the `pprof` script (distributed with
71google-perftools, installed by default on Googler Linux workstations; on Ubuntu
72it is called `google-pprof`). For example:
andybons3322f762015-08-24 21:37:0973
andybonsad92aa32015-08-31 02:27:4474 pprof --gv out/Release/chrome /tmp/heapprofile
andybons3322f762015-08-24 21:37:0975
andybonsad92aa32015-08-31 02:27:4476This will generate a visual representation of the heap profile as a postscript
77file and load it up using `gv`. For more powerful commands, please refer to the
78pprof help output and the google-perftools documentation.
andybons3322f762015-08-24 21:37:0979
andybonsad92aa32015-08-31 02:27:4480(pprof is slow. Googlers can try the not-open-source cpprof; Evan wrote an open
81source alternative [available on github](https://github.com/martine/hp).)
andybons3322f762015-08-24 21:37:0982
83#### Sandbox
84
andybonsad92aa32015-08-31 02:27:4485Sandboxed renderer subprocesses will fail to write out heap profiling dumps. To
86work around this, turn off the sandbox (via `export CHROME_DEVEL_SANDBOX=`).
andybons3322f762015-08-24 21:37:0987
andybons3322f762015-08-24 21:37:0988#### More reading
89
andybonsad92aa32015-08-31 02:27:4490For further information, please refer to
91http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html.
andybons3322f762015-08-24 21:37:0992
andybons3322f762015-08-24 21:37:0993## Paint profiling
94
andybonsad92aa32015-08-31 02:27:4495You can use Xephyr to profile how chrome repaints the screen. Xephyr is a
96virtual X server like Xnest with debugging options which draws red rectangles to
97where applications are drawing before drawing the actual information.
andybons3322f762015-08-24 21:37:0998
andybonsad92aa32015-08-31 02:27:4499 export XEPHYR_PAUSE=10000
100 Xephyr :1 -ac -screen 800x600 &
101 DISPLAY=:1 out/Debug/chrome
andybons3322f762015-08-24 21:37:09102
andybonsad92aa32015-08-31 02:27:44103When ready to start debugging issue the following command, which will tell
104Xephyr to start drawing red rectangles:
andybons3322f762015-08-24 21:37:09105
andybonsad92aa32015-08-31 02:27:44106 kill -USR1 `pidof Xephyr`
andybons3322f762015-08-24 21:37:09107
andybonsad92aa32015-08-31 02:27:44108For further information, please refer to
109http://cgit.freedesktop.org/xorg/xserver/tree/hw/kdrive/ephyr/README.