blob: 4c6d6b2849c55f3288aa20a3d84f3a41ff6bf3d9 [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
Daniel Cheng3e1b9942024-03-01 18:36:0838> ⚠️ Note: on virtualized systems, e.g. cloudtops, the PMU counters may not
39be available or may be broken. Use `-e cpu-clock` as a workaround.
40Googlers, see [b/313526654](https://b.corp.google.com/issues/313526654).
41
andybonsad92aa32015-08-31 02:27:4442Some versions of the perf command can be confused by process renames. Affected
43versions will be unable to resolve Chromium's symbols if it was started through
44perf, as in the first example above. It should work correctly if you attach to
45an existing Chromium process as shown in the second example. (This is known to
46be broken as late as 3.2.5 and fixed as early as 3.11.rc3.g36f571. The actual
47affected range is likely much smaller. You can download and build your own perf
48from source.)
andybons3322f762015-08-24 21:37:0949
andybonsad92aa32015-08-31 02:27:4450The last one is useful on limited systems with few cores and low memory
51bandwidth, where the CPU cycles are shared between several processes (e.g.
52chrome browser, renderer, plugin, X, pulseaudio, etc.)
andybons3322f762015-08-24 21:37:0953
54To look at the data, you use:
andybonsad92aa32015-08-31 02:27:4455
56 perf report
andybons3322f762015-08-24 21:37:0957
58This will use the previously captured data (`perf.data`).
59
andybons3322f762015-08-24 21:37:0960## Heap Profiling
61
andybons3322f762015-08-24 21:37:0962#### Dumping a profile of a running process
63
Thiabaud Engelbrecht6d443612022-02-11 00:22:1864To programmatically generate a heap profile before exit, you can use gdb to
65attach at any point:
andybons3322f762015-08-24 21:37:0966
andybonsad92aa32015-08-31 02:27:44671. Attach gdb to the process: `$ gdb -p 12345`
Thiabaud Engelbrecht6d443612022-02-11 00:22:18682. Cause it to dump a profile: `(gdb) p HeapProfilerDump("foobar")`
693. The filename will be printed on the console you started Chrome from; e.g.
andybonsad92aa32015-08-31 02:27:4470 "`Dumping heap profile to heap.0001.heap (foobar)`"
andybons3322f762015-08-24 21:37:0971
72#### Analyzing dumps
73
andybonsad92aa32015-08-31 02:27:4474You can then analyze dumps using the `pprof` script (distributed with
75google-perftools, installed by default on Googler Linux workstations; on Ubuntu
76it is called `google-pprof`). For example:
andybons3322f762015-08-24 21:37:0977
andybonsad92aa32015-08-31 02:27:4478 pprof --gv out/Release/chrome /tmp/heapprofile
andybons3322f762015-08-24 21:37:0979
andybonsad92aa32015-08-31 02:27:4480This will generate a visual representation of the heap profile as a postscript
81file and load it up using `gv`. For more powerful commands, please refer to the
82pprof help output and the google-perftools documentation.
andybons3322f762015-08-24 21:37:0983
andybonsad92aa32015-08-31 02:27:4484(pprof is slow. Googlers can try the not-open-source cpprof; Evan wrote an open
85source alternative [available on github](https://github.com/martine/hp).)
andybons3322f762015-08-24 21:37:0986
87#### Sandbox
88
andybonsad92aa32015-08-31 02:27:4489Sandboxed renderer subprocesses will fail to write out heap profiling dumps. To
90work around this, turn off the sandbox (via `export CHROME_DEVEL_SANDBOX=`).
andybons3322f762015-08-24 21:37:0991
andybons3322f762015-08-24 21:37:0992#### More reading
93
andybonsad92aa32015-08-31 02:27:4494For further information, please refer to
95http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html.
andybons3322f762015-08-24 21:37:0996
andybons3322f762015-08-24 21:37:0997## Paint profiling
98
andybonsad92aa32015-08-31 02:27:4499You can use Xephyr to profile how chrome repaints the screen. Xephyr is a
100virtual X server like Xnest with debugging options which draws red rectangles to
101where applications are drawing before drawing the actual information.
andybons3322f762015-08-24 21:37:09102
andybonsad92aa32015-08-31 02:27:44103 export XEPHYR_PAUSE=10000
104 Xephyr :1 -ac -screen 800x600 &
105 DISPLAY=:1 out/Debug/chrome
andybons3322f762015-08-24 21:37:09106
andybonsad92aa32015-08-31 02:27:44107When ready to start debugging issue the following command, which will tell
108Xephyr to start drawing red rectangles:
andybons3322f762015-08-24 21:37:09109
andybonsad92aa32015-08-31 02:27:44110 kill -USR1 `pidof Xephyr`
andybons3322f762015-08-24 21:37:09111
andybonsad92aa32015-08-31 02:27:44112For further information, please refer to
113http://cgit.freedesktop.org/xorg/xserver/tree/hw/kdrive/ephyr/README.