Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /docs /linux /profiling.md
blob: 4c6d6b2849c55f3288aa20a3d84f3a41ff6bf3d9 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:09[diff] [blame]1# Linux Profiling
2
qyearsleyc0dc6f42016-12-02 22:13:39[diff] [blame]3How to profile Chromium on Linux.
andybons3322f762015-08-24 21:37:09[diff] [blame]4
andybonsad92aa32015-08-31 02:27:44[diff] [blame]5See
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:09[diff] [blame]8
9## CPU Profiling
10
11gprof: reported not to work (taking an hour to load on our large binary).
12
andybonsad92aa32015-08-31 02:27:44[diff] [blame]13oprofile: 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:09[diff] [blame]16
17TODO(willchan): Talk more about oprofile, gprof, etc.
18
andybonsad92aa32015-08-31 02:27:44[diff] [blame]19Also see
20https://sites.google.com/a/chromium.org/dev/developers/profiling-chromium-and-webkit
andybons3322f762015-08-24 21:37:09[diff] [blame]21
22### perf
23
andybonsad92aa32015-08-31 02:27:44[diff] [blame]24`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:09[diff] [blame]26
27To capture data, you use `perf record`. Some examples:
andybonsad92aa32015-08-31 02:27:44[diff] [blame]28
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:09[diff] [blame]36```
37
Daniel Cheng3e1b9942024-03-01 18:36:08[diff] [blame]38> ⚠️ 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:44[diff] [blame]42Some 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:09[diff] [blame]49
andybonsad92aa32015-08-31 02:27:44[diff] [blame]50The 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:09[diff] [blame]53
54To look at the data, you use:
andybonsad92aa32015-08-31 02:27:44[diff] [blame]55
56 perf report
andybons3322f762015-08-24 21:37:09[diff] [blame]57
58This will use the previously captured data (`perf.data`).
59
andybons3322f762015-08-24 21:37:09[diff] [blame]60## Heap Profiling
61
andybons3322f762015-08-24 21:37:09[diff] [blame]62#### Dumping a profile of a running process
63
Thiabaud Engelbrecht6d443612022-02-11 00:22:18[diff] [blame]64To programmatically generate a heap profile before exit, you can use gdb to
65attach at any point:
andybons3322f762015-08-24 21:37:09[diff] [blame]66
andybonsad92aa32015-08-31 02:27:44[diff] [blame]671. Attach gdb to the process: `$ gdb -p 12345`
Thiabaud Engelbrecht6d443612022-02-11 00:22:18[diff] [blame]682. 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:44[diff] [blame]70 "`Dumping heap profile to heap.0001.heap (foobar)`"
andybons3322f762015-08-24 21:37:09[diff] [blame]71
72#### Analyzing dumps
73
andybonsad92aa32015-08-31 02:27:44[diff] [blame]74You 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:09[diff] [blame]77
andybonsad92aa32015-08-31 02:27:44[diff] [blame]78 pprof --gv out/Release/chrome /tmp/heapprofile
andybons3322f762015-08-24 21:37:09[diff] [blame]79
andybonsad92aa32015-08-31 02:27:44[diff] [blame]80This 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:09[diff] [blame]83
andybonsad92aa32015-08-31 02:27:44[diff] [blame]84(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:09[diff] [blame]86
87#### Sandbox
88
andybonsad92aa32015-08-31 02:27:44[diff] [blame]89Sandboxed 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:09[diff] [blame]91
andybons3322f762015-08-24 21:37:09[diff] [blame]92#### More reading
93
andybonsad92aa32015-08-31 02:27:44[diff] [blame]94For further information, please refer to
95http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html.
andybons3322f762015-08-24 21:37:09[diff] [blame]96
andybons3322f762015-08-24 21:37:09[diff] [blame]97## Paint profiling
98
andybonsad92aa32015-08-31 02:27:44[diff] [blame]99You 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:09[diff] [blame]102
andybonsad92aa32015-08-31 02:27:44[diff] [blame]103 export XEPHYR_PAUSE=10000
104 Xephyr :1 -ac -screen 800x600 &
105 DISPLAY=:1 out/Debug/chrome
andybons3322f762015-08-24 21:37:09[diff] [blame]106
andybonsad92aa32015-08-31 02:27:44[diff] [blame]107When ready to start debugging issue the following command, which will tell
108Xephyr to start drawing red rectangles:
andybons3322f762015-08-24 21:37:09[diff] [blame]109
andybonsad92aa32015-08-31 02:27:44[diff] [blame]110 kill -USR1 `pidof Xephyr`
andybons3322f762015-08-24 21:37:09[diff] [blame]111
andybonsad92aa32015-08-31 02:27:44[diff] [blame]112For further information, please refer to
113http://cgit.freedesktop.org/xorg/xserver/tree/hw/kdrive/ephyr/README.

[8]ページ先頭

©2009-2025 Movatter.jp