OLD | NEW |
---|---|
(Empty) | |
1 # Heap Profiling with MemoryInfra | |
2 | |
3 As of Chrome 48, MemoryInfra supports heap profiling. The core principle is | |
4 a solution that JustWorks™ on all platforms without patching or rebuilding, | |
5 intergrated with the chrome://tracing ecosystem. | |
6 | |
7 [TOC] | |
8 | |
9 ## How to Use | |
10 | |
11 * Start Chrome with the `--enable-heap-profiling` switch. This will make Chrome | |
petrcermak
2016/01/19 10:13:55
Shouldn't this be an enumeration (1, 2, 3, ...)?
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
| |
12 keep track of all allocations. | |
13 | |
14 * Grab a [MemoryInfra][memory-infra] trace. For best results, start tracing | |
15 first, and _then_ open a new tab that you want to trace. Furthermore, | |
16 enabling more categories (besides memory-infra) will yield more detailed | |
17 information in the heap profiler. | |
petrcermak
2016/01/19 10:13:55
maybe say "... in the heap profiler pseudo stack t
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
| |
18 | |
19 * When the trace has been collected, select a heavy memory dump indicated by | |
20 a purple ![M][m-purple] dot. Heap dumps are only included in heavy memory | |
21 dumps. | |
22 | |
23 * In the analysis view, cells marked with a triple bar icon (☰) contain heap | |
24 dumps. Select such a cell. | |
25 | |
26 ![Cells containing a heap dump][cells-heap-dump] | |
27 | |
28 Note that at the moment only PartitionAlloc is supported. Heap dumps for | |
29 malloc is currently in the prototype stage. | |
petrcermak
2016/01/19 10:13:54
s/is/are/ (or s/dumps/dumping/ on the previous lin
Ruud van Asseldonk
2016/01/19 10:44:48
Fixed.
| |
30 | |
31 * Scroll down all the way to _Heap Details_. | |
32 | |
33 * Pinpoint the memory bug and live happily ever after. | |
34 | |
35 [memory-infra]: memory_infra.md | |
36 [m-purple]: https://drive.google.com/uc?id=0Bx14iZPZRgb5RFFGc0xZZEJWVFk | |
37 [cells-heap-dump]: https://drive.google.com/uc?id=0Bx14iZPZRgb5NGlJSFRONTFoWEU | |
38 | |
39 ## Heap Details | |
40 | |
41 The heap details view contains a tree that represents the heap. The size of the | |
42 root node corresponds to the selected allocator cell. | |
43 | |
44 *** aside | |
45 The size value in the heap details view will not match the value in the selected | |
46 analysis view cell exactly. There are three reasons for this. First, the heap | |
47 profiler reports the memory that _the program requested_, whereas the allocator | |
48 reports the memory that it _actually allocated_ plus its own bookkeeping | |
49 overhead. Second, allocations that happen early --- before Chrome knows that | |
50 heap profiling is enabled --- are not captured by the heap profiler, but they | |
51 are reported by the allocator. Third, tracing overhead is not discounted by the | |
52 heap profiler. | |
53 *** | |
54 | |
55 The heap can be broken down in two ways: by _backtrace_ (marked with an ƒ), and | |
56 by _type_ (marked with a Ⓣ). When tracing is enabled, Chrome records trace | |
57 events, shown in the flame chart in timeline view. At every point in time these | |
petrcermak
2016/01/19 10:13:55
nit: This makes it sounds like Chrome *only* recor
Ruud van Asseldonk
2016/01/19 10:44:48
Replaced “shown” with “most of which appear”.
| |
58 trace events form a pseudo stack, and a vertical slice through the flame chart | |
59 is like a backtrace. This corresponds to the ƒ nodes in the heap details view. | |
60 Hence enabling more tracing categories will give a more detailed breakdown of | |
61 the heap. | |
62 | |
63 The other way to break down the heap is by object type. At the moment this is | |
64 only supported for PartitionAlloc. | |
petrcermak
2016/01/19 10:13:55
The second sentence seems irrelevant at the moment
Ruud van Asseldonk
2016/01/19 10:44:48
I know, but the screenshots show the icon for mall
petrcermak
2016/01/19 11:11:30
Do you mean the heap dump icon? As far as I unders
| |
65 | |
66 *** aside | |
67 In official builds, only the most common type names are included due to binary | |
68 size concerns. A development build has full type information. | |
petrcermak
2016/01/19 10:13:54
nit: I don't like the indefinite article in front
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
| |
69 *** | |
70 | |
71 To keep the trace log small, uninteresting information is omitted from heap | |
72 dumps. The long tail of small nodes is not dumped, but grouped in an `<other>` | |
73 node instead. Note that altough these small nodes are insignificant on their | |
74 own, together they can be responsible for a significant portion of the heap. The | |
75 `<other>` node is large in that case. | |
76 | |
77 ## Example | |
78 | |
79 In the trace below, `ParseAuthorStyleSheet` is called at some point. | |
80 | |
81 ![ParseAuthorStyleSheet pseudo stack][pseudo-stack] | |
82 | |
83 The pseudo stack of trace events translates in the tree of ƒ nodes below. Of the | |
petrcermak
2016/01/19 10:13:54
nit: s/translates in/is translated into/
Ruud van Asseldonk
2016/01/19 10:44:48
Changed to “corresponds to”.
| |
84 23.5 MiB of memory allocated with PartitionAlloc, 1.9 MiB was allocated inside | |
85 `ParseAuthorStyleSheet`, either directly, or at a deeper level | |
86 (like `CSSParserImpl::parseStyleSheet`). | |
87 | |
88 ![Memory Allocated in ParseAuthorStyleSheet][break-down-by-backtrace] | |
89 | |
90 By expanding `ParseAuthorStyleSheet`, we can see which types were allocated | |
91 there. Of the 1.9 MiB, 371 KiB is spent on `ImmutableStylePropertySet`s, and | |
petrcermak
2016/01/19 10:13:55
nit: s/is/was/ (consistency with "were allocated"
Ruud van Asseldonk
2016/01/19 10:44:48
Done. You are sharp today :)
| |
92 238 KiB is spent on `StringImpl`s. | |
petrcermak
2016/01/19 10:13:54
ditto
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
| |
93 | |
94 ![ParseAuthorStyleSheet broken down by type][break-down-by-type] | |
95 | |
96 It is also possible to break down by type first, and then by backtrace. Below | |
97 we see that of the 23.5 MiB allocated with PartitionAlloc, 1 MiB is spent on | |
98 `Node`s, and about half of the memory spent on nodes was allocated in | |
99 `HTMLDocumentParser`. | |
100 | |
101 ![The PartitionAlloc heap broken down by type first and then by backtrace][type- then-backtrace] | |
102 | |
103 Heap dump diffs are fully supported by trace viewer. Select a heavy memory dump, | |
104 then with the control key select a heavy memory dump earlier in time. Below is a | |
petrcermak
2016/01/19 10:13:54
people tend to forget things, so it might be worth
petrcermak
2016/01/19 10:13:55
nit: Since you can also select a dump in the futur
Ruud van Asseldonk
2016/01/19 10:44:48
Hah, actually I stressed that you have to select t
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
petrcermak
2016/01/19 11:11:30
Oh, really? Then it's a bug in the memory UI. It s
| |
105 diff of theverge.com before and in the middle of loading ads. We can see that 4 | |
106 MiB was allocated when parsing the documents in all those iframes, almost a | |
petrcermak
2016/01/19 10:13:54
probably s/was/were/
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
| |
107 megabyte of which was due to JavaScript. (Note that this is memory on the | |
petrcermak
2016/01/19 10:13:54
nit: s/memory on the/memory allocated by/
Ruud van Asseldonk
2016/01/19 10:44:48
Done.
| |
108 PartitionAlloc alone, the total renderer memory increase was around 72 MiB.) | |
109 | |
110 ![Diff of The Verge before and after loading ads][diff] | |
111 | |
112 [pseudo-stack]: https://drive.google.com/uc?id=0Bx14iZPZRgb5M194Y2RqQ jhoZkk | |
113 [break-down-by-backtrace]: https://drive.google.com/uc?id=0Bx14iZPZRgb5ZDRQdGNnN DNIazA | |
114 [break-down-by-type]: https://drive.google.com/uc?id=0Bx14iZPZRgb5THJMYlpyT EN2Q2s | |
115 [type-then-backtrace]: https://drive.google.com/uc?id=0Bx14iZPZRgb5UGZFX1pDU VpOLUU | |
116 [diff]: https://drive.google.com/uc?id=0Bx14iZPZRgb5UzNvMmVOa 0RnQWs | |
OLD | NEW |