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

Side by Side Diff: docs/linux_profiling.md

Issue 1324603002: [Docs] Another round of stylistic fixes. (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
1 # Linux Profiling 1 # Linux Profiling
2 2
3 How to profile chromium on Linux. 3 How to profile chromium on Linux.
4 4
5 See [Profiling Chromium and WebKit](https://sites.google.com/a/chromium.org/dev/ developers/profiling-chromium-and-webkit) for alternative discussion. 5 See
6 [Profiling Chromium and WebKit](https://sites.google.com/a/chromium.org/dev/deve lopers/profiling-chromium-and-webkit)
7 for alternative discussion.
6 8
7 ## CPU Profiling 9 ## CPU Profiling
8 10
9 gprof: reported not to work (taking an hour to load on our large binary). 11 gprof: reported not to work (taking an hour to load on our large binary).
10 12
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). 13 oprofile: Dean uses it, says it's good. (As of 9/16/9 oprofile only supports
14 timers on the new Z600 boxes, which doesn't give good granularity for profiling
15 startup).
12 16
13 TODO(willchan): Talk more about oprofile, gprof, etc. 17 TODO(willchan): Talk more about oprofile, gprof, etc.
14 18
15 Also see https://sites.google.com/a/chromium.org/dev/developers/profiling-chromi um-and-webkit 19 Also see
20 https://sites.google.com/a/chromium.org/dev/developers/profiling-chromium-and-we bkit
16 21
17 ### perf 22 ### perf
18 23
19 `perf` is the successor to `oprofile`. It's maintained in the kernel tree, it's available on Ubuntu in the package `linux-tools`. 24 `perf` is the successor to `oprofile`. It's maintained in the kernel tree, it's
25 available on Ubuntu in the package `linux-tools`.
20 26
21 To capture data, you use `perf record`. Some examples: 27 To capture data, you use `perf record`. Some examples:
28
29 ```shell
30 # captures the full execution of the program
31 perf record -f -g out/Release/chrome
32 # captures a particular pid, you can start at the right time, and stop with
33 # ctrl-C
34 perf record -f -g -p 1234
35 perf record -f -g -a # captures the whole system
22 ``` 36 ```
23 $ perf record -f -g out/Release/chrome # captures the full execution of the pro gram 37
24 $ perf record -f -g -p 1234 # captures a particular pid, you can start at the r ight time, and stop with ctrl-C 38 Some versions of the perf command can be confused by process renames. Affected
25 $ perf record -f -g -a # captures the whole system 39 versions will be unable to resolve Chromium's symbols if it was started through
40 perf, as in the first example above. It should work correctly if you attach to
41 an existing Chromium process as shown in the second example. (This is known to
42 be broken as late as 3.2.5 and fixed as early as 3.11.rc3.g36f571. The actual
43 affected range is likely much smaller. You can download and build your own perf
44 from source.)
45
46 The last one is useful on limited systems with few cores and low memory
47 bandwidth, where the CPU cycles are shared between several processes (e.g.
48 chrome browser, renderer, plugin, X, pulseaudio, etc.)
49
50 To look at the data, you use:
51
52 perf report
53
54 This will use the previously captured data (`perf.data`).
55
56 ### google-perftools
57
58 google-perftools code is enabled when the `use_allocator` variable in gyp is set
59 to `tcmalloc` (currently the default). That will build the tcmalloc library,
60 including the cpu profiling and heap profiling code into Chromium. In order to
61 get stacktraces in release builds on 64 bit, you will need to build with some
62 extra flags enabled by setting `profiling=1` in gyp.
63
64 If the stack traces in your profiles are incomplete, this may be due to missing
65 frame pointers in some of the libraries. A workaround is to use the
66 `linux_keep_shadow_stacks=1` gyp option. This will keep a shadow stack using the
67 `-finstrument-functions` option of gcc and consult the stack when unwinding.
68
69 In order to enable cpu profiling, run Chromium with the environment variable
70 `CPUPROFILE` set to a filename. For example:
71
72 CPUPROFILE=/tmp/cpuprofile out/Release/chrome
73
74 After the program exits successfully, the cpu profile will be available at the
75 filename specified in the CPUPROFILE environment variable. You can then analyze
76 it using the pprof script (distributed with google-perftools, installed by
77 default on Googler Linux workstations). For example:
78
79 pprof --gv out/Release/chrome /tmp/cpuprofile
80
81 This will generate a visual representation of the cpu profile as a postscript
82 file and load it up using `gv`. For more powerful commands, please refer to the
83 pprof help output and the google-perftools documentation.
84
85 Note that due to the current design of google-perftools' profiling tools, it is
86 only possible to profile the browser process. You can also profile and pass the
87 `--single-process` flag for a rough idea of what the render process looks like,
88 but keep in mind that you'll be seeing a mixed browser/renderer codepath that is
89 not used in production.
90
91 For further information, please refer to
92 http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html.
93
94 ## Heap Profiling
95
96 ### google-perftools
97
98 #### Turning on heap profiles
99
100 Follow the instructions for enabling profiling as described above in the
101 google-perftools section under CPU Profiling.
102
103 To turn on the heap profiler on a Chromium build with tcmalloc, use the
104 `HEAPPROFILE` environment variable to specify a filename for the heap profile.
105 For example:
106
107 HEAPPROFILE=/tmp/heapprofile out/Release/chrome
108
109 After the program exits successfully, the heap profile will be available at the
110 filename specified in the `HEAPPROFILE` environment variable.
111
112 Some tests fork short-living processes which have a small memory footprint. To
113 catch those, use the `HEAP_PROFILE_ALLOCATION_INTERVAL` environment variable.
114
115 #### Dumping a profile of a running process
116
117 To programmatically generate a heap profile before exit, use code like:
118
119 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h"
120
121 // "foobar" will be included in the message printed to the console
122 HeapProfilerDump("foobar");
123
124 For example, you might hook that up to some action in the UI.
125
126 Or you can use gdb to attach at any point:
127
128 1. Attach gdb to the process: `$ gdb -p 12345`
129 1. Cause it to dump a profile: `(gdb) p HeapProfilerDump("foobar")`
130 1. The filename will be printed on the console you started Chrome from; e.g.
131 "`Dumping heap profile to heap.0001.heap (foobar)`"
132
133 #### Analyzing dumps
134
135 You can then analyze dumps using the `pprof` script (distributed with
136 google-perftools, installed by default on Googler Linux workstations; on Ubuntu
137 it is called `google-pprof`). For example:
138
139 pprof --gv out/Release/chrome /tmp/heapprofile
140
141 This will generate a visual representation of the heap profile as a postscript
142 file and load it up using `gv`. For more powerful commands, please refer to the
143 pprof help output and the google-perftools documentation.
144
145 (pprof is slow. Googlers can try the not-open-source cpprof; Evan wrote an open
146 source alternative [available on github](https://github.com/martine/hp).)
147
148 #### Sandbox
149
150 Sandboxed renderer subprocesses will fail to write out heap profiling dumps. To
151 work around this, turn off the sandbox (via `export CHROME_DEVEL_SANDBOX=`).
152
153 #### Troubleshooting
154
155 * "Hooked allocator frame not found": build with `-Dcomponent=static_library`.
156 `tcmalloc` gets confused when the allocator routines are in a different
157 `.so` than the rest of the code.
158
159 #### More reading
160
161 For further information, please refer to
162 http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html.
163
164 ### Massif
165
166 [Massif](http://valgrind.org/docs/manual/mc-manual.html) is a
167 [Valgrind](http://www.chromium.org/developers/how-tos/using-valgrind)-based heap
168 profiler. It is much slower than the heap profiler from google-perftools, but it
169 may have some advantages. (In particular, it handles the multi-process
170 executables well).
171
172 First, you will need to build massif from valgrind-variant project yourself,
173 it's [easy](http://code.google.com/p/valgrind-variant/wiki/HowTo).
174
175 Then, make sure your chromium is built using the
176 [valgrind instructions](http://www.chromium.org/developers/how-tos/using-valgrin d).
177 Now, you can run massif like this:
178
26 ``` 179 ```
27 180 path-to-valgrind-variant/valgrind/inst/bin/valgrind \
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.) 181 --fullpath-after=/chromium/src/ \
29 182 --trace-children-skip=*npviewer*,/bin/uname,/bin/sh,/usr/bin/which,/bin/ps,/b in/grep,/usr/bin/linux32 \
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.) 183 --trace-children=yes \
31 184 --tool=massif \
32 To look at the data, you use: 185 out/Release/chrome --noerrdialogs --disable-hang-monitor --other-chrome-flags
33 ``` 186 ```
34 $ perf report 187
35 ``` 188 The result will be stored in massif.out.PID files, which you can post-process
36 189 with [ms_print](http://valgrind.org/docs/manual/mc-manual.html).
37 This will use the previously captured data (`perf.data`). 190
38 191 TODO(kcc) sometimes when closing a tab the main process kills the tab process
39 ### google-perftools 192 before massif completes writing it's log file. Need a flag that tells the main
40 193 process to wait longer.
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 194
140 ## Paint profiling 195 ## Paint profiling
141 196
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. 197 You can use Xephyr to profile how chrome repaints the screen. Xephyr is a
143 198 virtual X server like Xnest with debugging options which draws red rectangles to
144 ``` 199 where applications are drawing before drawing the actual information.
145 $ export XEPHYR_PAUSE=10000 200
146 $ Xephyr :1 -ac -screen 800x600 & 201 export XEPHYR_PAUSE=10000
147 $ DISPLAY=:1 out/Debug/chrome 202 Xephyr :1 -ac -screen 800x600 &
148 ``` 203 DISPLAY=:1 out/Debug/chrome
149 204
150 When ready to start debugging issue the following command, which will tell Xephy r to start drawing red rectangles: 205 When ready to start debugging issue the following command, which will tell
151 206 Xephyr to start drawing red rectangles:
152 ``` 207
153 $ kill -USR1 `pidof Xephyr` 208 kill -USR1 `pidof Xephyr`
154 ``` 209
155 210 For further information, please refer to
156 For further information, please refer to http://cgit.freedesktop.org/xorg/xserve r/tree/hw/kdrive/ephyr/README. 211 http://cgit.freedesktop.org/xorg/xserver/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