Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: docs/linux_profiling.md

Issue 1309473002: WIP: Migrate Wiki content over to src/docs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « docs/linux_printing.md ('k') | docs/linux_proxy_config.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Linux Profiling
2
3 How to profile chromium on Linux.
4
5 See [Profiling Chromium and WebKit](https://sites.google.com/a/chromium.org/dev/ developers/profiling-chromium-and-webkit) for alternative discussion.
6
7 ## CPU Profiling
8
9 gprof: reported not to work (taking an hour to load on our large binary).
10
11 oprofile: Dean uses it, says it's good. (As of 9/16/9 oprofile only supports tim ers on the new Z600 boxes, which doesn't give good granularity for profiling sta rtup).
12
13 TODO(willchan): Talk more about oprofile, gprof, etc.
14
15 Also see https://sites.google.com/a/chromium.org/dev/developers/profiling-chromi um-and-webkit
16
17 ### perf
18
19 `perf` is the successor to `oprofile`. It's maintained in the kernel tree, it's available on Ubuntu in the package `linux-tools`.
20
21 To capture data, you use `perf record`. Some examples:
22 ```
23 $ perf record -f -g out/Release/chrome # captures the full execution of the pro gram
24 $ perf record -f -g -p 1234 # captures a particular pid, you can start at the r ight time, and stop with ctrl-C
25 $ perf record -f -g -a # captures the whole system
26 ```
27
28 Some versions of the perf command can be confused by process renames. Affected versions will be unable to resolve Chromium's symbols if it was started through perf, as in the first example above. It should work correctly if you attach to an existing Chromium process as shown in the second example. (This is known to be broken as late as 3.2.5 and fixed as early as 3.11.rc3.g36f571. The actual a ffected range is likely much smaller. You can download and build your own perf from source.)
29
30 The last one is useful on limited systems with few cores and low memory bandwidt h, where the CPU cycles are shared between several processes (e.g. chrome browse r, renderer, plugin, X, pulseaudio, etc.)
31
32 To look at the data, you use:
33 ```
34 $ perf report
35 ```
36
37 This will use the previously captured data (`perf.data`).
38
39 ### google-perftools
40
41 google-perftools code is enabled when the `use_allocator` variable in gyp is set to `tcmalloc` (currently the default). That will build the tcmalloc library, i ncluding the cpu profiling and heap profiling code into Chromium. In order to g et stacktraces in release builds on 64 bit, you will need to build with some ext ra flags enabled by setting `profiling=1` in gyp.
42
43 If the stack traces in your profiles are incomplete, this may be due to missing frame pointers in some of the libraries. A workaround is to use the `linux_keep_ shadow_stacks=1` gyp option. This will keep a shadow stack using the -finstrumen t-functions option of gcc and consult the stack when unwinding.
44
45 In order to enable cpu profiling, run Chromium with the environment variable CPU PROFILE set to a filename. For example:
46
47 ```
48 $ CPUPROFILE=/tmp/cpuprofile out/Release/chrome
49 ```
50
51 After the program exits successfully, the cpu profile will be available at the f ilename specified in the CPUPROFILE environment variable. You can then analyze it using the pprof script (distributed with google-perftools, installed by defau lt on Googler Linux workstations). For example:
52
53 ```
54 $ pprof --gv out/Release/chrome /tmp/cpuprofile
55 ```
56
57 This will generate a visual representation of the cpu profile as a postscript fi le and load it up using `gv`. For more powerful commands, please refer to the p prof help output and the google-perftools documentation.
58
59 Note that due to the current design of google-perftools' profiling tools, it is only possible to profile the browser process. You can also profile and pass the --single-process flag for a rough idea of what the render process looks like, b ut keep in mind that you'll be seeing a mixed browser/renderer codepath that is not used in production.
60
61 For further information, please refer to http://google-perftools.googlecode.com/ svn/trunk/doc/cpuprofile.html.
62
63 ## Heap Profiling
64
65 ### google-perftools
66
67 #### Turning on heap profiles
68 Follow the instructions for enabling profiling as described above in the google- perftools section under Cpu Profiling.
69
70 To turn on the heap profiler on a Chromium build with tcmalloc, use the HEAPPROF ILE environment variable to specify a filename for the heap profile. For exampl e:
71
72 ```
73 $ HEAPPROFILE=/tmp/heapprofile out/Release/chrome
74 ```
75
76 After the program exits successfully, the heap profile will be available at the filename specified in the `HEAPPROFILE` environment variable.
77
78 Some tests fork short-living processes which have a small memory footprint. To c atch those, use the `HEAP_PROFILE_ALLOCATION_INTERVAL` environment variable.
79
80 #### Dumping a profile of a running process
81
82 To programmatically generate a heap profile before exit, use code like:
83 ```
84 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h"
85 ...
86 HeapProfilerDump("foobar"); // "foobar" will be included in the message printed to the console
87 ```
88 For example, you might hook that up to some action in the UI.
89
90 Or you can use gdb to attach at any point:
91
92 1. Attach gdb to the process: `$ gdb -p 12345`
93 1. Cause it to dump a profile: `(gdb) p HeapProfilerDump("foobar")`
94 1. The filename will be printed on the console you started Chrome from; e.g. " `Dumping heap profile to heap.0001.heap (foobar)`"
95
96
97 #### Analyzing dumps
98
99 You can then analyze dumps using the `pprof` script (distributed with google-per ftools, installed by default on Googler Linux workstations; on Ubuntu it is call ed `google-pprof`). For example:
100
101 ```
102 $ pprof --gv out/Release/chrome /tmp/heapprofile
103 ```
104
105 This will generate a visual representation of the heap profile as a postscript f ile and load it up using `gv`. For more powerful commands, please refer to the pprof help output and the google-perftools documentation.
106
107 (pprof is slow. Googlers can try the not-open-source cpprof; Evan wrote an open source alternative [available on github](https://github.com/martine/hp).)
108
109 #### Sandbox
110
111 Sandboxed renderer subprocesses will fail to write out heap profiling dumps. To work around this, turn off the sandbox (via `export CHROME_DEVEL_SANDBOX=`).
112
113 #### Troubleshooting
114
115 * "Hooked allocator frame not found": build with `-Dcomponent=static_library`. tcmalloc gets confused when the allocator routines are in a different `.so` th an the rest of the code.
116
117 #### More reading
118
119 For further information, please refer to http://google-perftools.googlecode.com/ svn/trunk/doc/heapprofile.html.
120
121 ### Massif
122 [Massif](http://valgrind.org/docs/manual/mc-manual.html) is a [Valgrind](http:// www.chromium.org/developers/how-tos/using-valgrind)-based heap profiler.
123 It is much slower than the heap profiler from google-perftools, but it may have some advantages. (In particular, it handles the multi-process executables well).
124
125 First, you will need to build massif from valgrind-variant project yourself, it' s [easy](http://code.google.com/p/valgrind-variant/wiki/HowTo).
126
127 Then, make sure your chromium is built using the [valgrind instructions](http:// www.chromium.org/developers/how-tos/using-valgrind).
128 Now, you can run massif like this:
129
130 ```
131 % path-to-valgrind-variant/valgrind/inst/bin/valgrind --fullpath-after=/chromium /src/ \
132 --trace-children-skip=*npviewer*,/bin/uname,/bin/sh,/usr/bin/which,/bin/ps,/bi n/grep,/usr/bin/linux32 --trace-children=yes --tool=massif \
133 out/Release/chrome --noerrdialogs --disable-hang-monitor --other-chrome-flags
134 ```
135
136 The result will be stored in massif.out.PID files, which you can post-process wi th [ms\_print](http://valgrind.org/docs/manual/mc-manual.html).
137
138 TODO(kcc) sometimes when closing a tab the main process kills the tab process be fore massif completes writing it's log file. Need a flag that tells the main pro cess to wait longer.
139
140 ## Paint profiling
141
142 You can use Xephyr to profile how chrome repaints the screen. Xephyr is a virtua l X server like Xnest with debugging options which draws red rectangles to where applications are drawing before drawing the actual information.
143
144 ```
145 $ export XEPHYR_PAUSE=10000
146 $ Xephyr :1 -ac -screen 800x600 &
147 $ DISPLAY=:1 out/Debug/chrome
148 ```
149
150 When ready to start debugging issue the following command, which will tell Xephy r to start drawing red rectangles:
151
152 ```
153 $ kill -USR1 `pidof Xephyr`
154 ```
155
156 For further information, please refer to http://cgit.freedesktop.org/xorg/xserve r/tree/hw/kdrive/ephyr/README.
OLDNEW
« no previous file with comments | « docs/linux_printing.md ('k') | docs/linux_proxy_config.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698