hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 1 | # MemoryInfra |
| 2 | |
| 3 | MemoryInfra is a timeline-based profiling system integrated in chrome://tracing. |
| 4 | It aims at creating Chrome-scale memory measurement tooling so that on any |
| 5 | Chrome in the world --- desktop, mobile, Chrome OS or any other --- with the |
| 6 | click of a button you can understand where memory is being used in your system. |
| 7 | |
| 8 | [TOC] |
| 9 | |
| 10 | ## Getting Started |
| 11 | |
| 12 | 1. Get a bleeding-edge or tip-of-tree build of Chrome. |
| 13 | |
| 14 | 2. [Record a trace as usual][record-trace]: open [chrome://tracing][tracing] |
| 15 | on Desktop Chrome or [chrome://inspect?tracing][inspect-tracing] to trace |
| 16 | Chrome for Android. |
| 17 | |
| 18 | 3. Make sure to enable the **memory-infra** category on the right. |
| 19 | |
| 20 | ![Tick the memory-infra checkbox when recording a trace.][memory-infra-box] |
| 21 | |
| 22 | 4. For now, some subsystems only work if Chrome is started with the |
| 23 | `--no-sandbox` flag. |
| 24 | <!-- TODO(primiano) TODO(ssid): https://crbug.com/461788 --> |
| 25 | |
| 26 | [record-trace]: https://sites.google.com/a/chromium.org/dev/developers/how-tos/trace-event-profiling-tool/recording-tracing-runs |
| 27 | [tracing]: chrome://tracing |
| 28 | [inspect-tracing]: chrome://inspect?tracing |
| 29 | [memory-infra-box]: https://storage.googleapis.com/chromium-docs.appspot.com/1c6d1886584e7cc6ffed0d377f32023f8da53e02 |
| 30 | |
| 31 | ![Timeline View and Analysis View][tracing-views] |
| 32 | |
| 33 | After recording a trace, you will see the **timeline view**. Timeline view |
| 34 | shows: |
| 35 | |
| 36 | * Total resident memory grouped by process (at the top). |
| 37 | * Total resident memory grouped by subsystem (at the top). |
| 38 | * Allocated memory per subsystem for every process. |
| 39 | |
| 40 | Click one of the ![M][m-blue] dots to bring up the **analysis view**. Click |
| 41 | on a cell in analysis view to reveal more information about its subsystem. |
| 42 | PartitionAlloc for instance, has more details about its partitions. |
| 43 | |
| 44 | ![Component details for PartitionAlloc][partalloc-details] |
| 45 | |
| 46 | The purple ![M][m-purple] dots represent heavy dumps. In these dumps, components |
| 47 | can provide more details than in the regular dumps. The full details of the |
| 48 | MemoryInfra UI are explained in its [design doc][mi-ui-doc]. |
| 49 | |
| 50 | [tracing-views]: https://storage.googleapis.com/chromium-docs.appspot.com/db12015bd262385f0f8bd69133330978a99da1ca |
| 51 | [m-blue]: https://storage.googleapis.com/chromium-docs.appspot.com/b60f342e38ff3a3767bbe4c8640d96a2d8bc864b |
| 52 | [partalloc-details]: https://storage.googleapis.com/chromium-docs.appspot.com/02eade61d57c83f8ef8227965513456555fc3324 |
| 53 | [m-purple]: https://storage.googleapis.com/chromium-docs.appspot.com/d7bdf4d16204c293688be2e5a0bcb2bf463dbbc3 |
| 54 | [mi-ui-doc]: https://docs.google.com/document/d/1b5BSBEd1oB-3zj_CBAQWiQZ0cmI0HmjmXG-5iNveLqw/edit |
| 55 | |
| 56 | ## Columns |
| 57 | |
| 58 | **Columns in blue** reflect the amount of actual physical memory used by the |
| 59 | process. This is what exerts memory pressure on the system. |
| 60 | |
ssid | 5183d87 | 2016-11-29 00:10:56 | [diff] [blame] | 61 | * **Total Resident**: The current working set size of the process, excluding |
| 62 | the memory overhead of tracing. On Linux, this returns the resident set size. |
| 63 | * **Peak Total Resident**: The overall peak working set size of the process on |
| 64 | supported platforms. On Linux kernel versions >= 4.0 the peak usage between |
| 65 | two memory dumps is shown. |
| 66 | * **PSS**: POSIX only. The process's proportional share of total resident size. |
| 67 | * **Private Dirty**: The total size of dirty pages which are not used by any |
| 68 | other process. |
| 69 | * **Swapped**: The total size of anonymous memory used by process, which is |
| 70 | swapped out of RAM. |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 71 | |
qyearsley | c0dc6f4 | 2016-12-02 22:13:39 | [diff] [blame^] | 72 | **Columns in black** reflect a best estimation of the amount of physical |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 73 | memory used by various subsystems of Chrome. |
| 74 | |
| 75 | * **Blink GC**: Memory used by [Oilpan][oilpan]. |
| 76 | * **CC**: Memory used by the compositor. |
| 77 | See [cc/memory][cc-memory] for the full details. |
ssid | 5183d87 | 2016-11-29 00:10:56 | [diff] [blame] | 78 | * **Discardable**: Total [discardable][discardable] memory used by the process |
| 79 | from various components like Skia caches and Web caches. |
| 80 | * **Font Caches**: Size of cache that stores Font shapes and platform Fonts. |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 81 | * **GPU** and **GPU Memory Buffer**: GPU memory and RAM used for GPU purposes. |
| 82 | See [GPU Memory Tracing][gpu-memory]. |
ssid | 5183d87 | 2016-11-29 00:10:56 | [diff] [blame] | 83 | * **LevelDB**: Memory used for LeveldbValueStore(s), IndexedDB databases and |
| 84 | ProtoDatabase(s). |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 85 | * **Malloc**: Memory allocated by calls to `malloc`, or `new` for most |
| 86 | non-Blink objects. |
| 87 | * **PartitionAlloc**: Memory allocated via [PartitionAlloc][partalloc]. |
| 88 | Blink objects that are not managed by Oilpan are allocated with |
| 89 | PartitionAlloc. |
ssid | 5183d87 | 2016-11-29 00:10:56 | [diff] [blame] | 90 | * **Skia**: Memory used by all resources used by the Skia rendering system. |
| 91 | * **SQLite**: Memory used for all sqlite databases. |
| 92 | * **Sync**: Memory used by Chrome Sync when signed in. |
| 93 | * **UI**: Android only. Memory used by Android java bitmaps for the UI. |
| 94 | * **V8**: Memory used by V8 Javascript engine. |
| 95 | * **Web Cache**: Memory used by resources downloaded from the Web, like images |
| 96 | and scipts. |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 97 | |
| 98 | The **tracing column in gray** reports memory that is used to collect all of the |
| 99 | above information. This memory would not be used if tracing were not enabled, |
| 100 | and it is discounted from malloc and the blue columns. |
| 101 | |
| 102 | <!-- TODO(primiano): Improve this. https://crbug.com/??? --> |
| 103 | |
| 104 | [oilpan]: /third_party/WebKit/Source/platform/heap/BlinkGCDesign.md |
ssid | 5183d87 | 2016-11-29 00:10:56 | [diff] [blame] | 105 | [discardable]:base/memory/discardable_memory.h |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 106 | [cc-memory]: probe-cc.md |
| 107 | [gpu-memory]: probe-gpu.md |
| 108 | [partalloc]: /third_party/WebKit/Source/wtf/allocator/PartitionAlloc.md |
| 109 | |
| 110 | ## Related Pages |
| 111 | |
| 112 | * [Adding MemoryInfra Tracing to a Component](adding_memory_infra_tracing.md) |
| 113 | * [GPU Memory Tracing](probe-gpu.md) |
| 114 | * [Heap Profiler Internals](heap_profiler_internals.md) |
| 115 | * [Heap Profiling with MemoryInfra](heap_profiler.md) |
| 116 | * [Startup Tracing with MemoryInfra](memory_infra_startup_tracing.md) |
| 117 | |
| 118 | ## Rationale |
| 119 | |
| 120 | Another memory profiler? What is wrong with tool X? |
| 121 | Most of the existing tools: |
| 122 | |
| 123 | * Are hard to get working with Chrome. (Massive symbols, require OS-specific |
| 124 | tricks.) |
| 125 | * Lack Chrome-related context. |
| 126 | * Don't deal with multi-process scenarios. |
| 127 | |
| 128 | MemoryInfra leverages the existing tracing infrastructure in Chrome and provides |
| 129 | contextual data: |
| 130 | |
| 131 | * **It speaks Chrome slang.** |
| 132 | The Chromium codebase is instrumented. Its memory subsystems (allocators, |
| 133 | caches, etc.) uniformly report their stats into the trace in a way that can |
| 134 | be understood by Chrome developers. No more |
| 135 | `__gnu_cxx::new_allocator< std::_Rb_tree_node< std::pair< std::string const, base::Value*>>> ::allocate`. |
| 136 | * **Timeline data that can be correlated with other events.** |
| 137 | Did memory suddenly increase during a specific Blink / V8 / HTML parsing |
| 138 | event? Which subsystem increased? Did memory not go down as expected after |
| 139 | closing a tab? Which other threads were active during a bloat? |
| 140 | * **Works out of the box on desktop and mobile.** |
| 141 | No recompilations with unmaintained `GYP_DEFINES`, no time-consuming |
| 142 | symbolizations stages. All the logic is already into Chrome, ready to dump at |
| 143 | any time. |
| 144 | * **The same technology is used for telemetry and the ChromePerf dashboard.** |
| 145 | See [the slides][chromeperf-slides] and take a look at |
| 146 | [some ChromePerf dashboards][chromeperf] and |
| 147 | [telemetry documentation][telemetry]. |
| 148 | |
| 149 | [chromeperf-slides]: https://docs.google.com/presentation/d/1OyxyT1sfg50lA36A7ibZ7-bBRXI1kVlvCW0W9qAmM_0/present?slide=id.gde150139b_0_137 |
| 150 | [chromeperf]: https://chromeperf.appspot.com/report?sid=3b54e60c9951656574e19252fadeca846813afe04453c98a49136af4c8820b8d |
| 151 | [telemetry]: https://catapult.gsrc.io/telemetry |
| 152 | |
| 153 | ## Development |
| 154 | |
| 155 | MemoryInfra is based on a simple and extensible architecture. See |
| 156 | [the slides][dp-slides] on how to get your subsystem reported in MemoryInfra, |
| 157 | or take a look at one of the existing examples such as |
| 158 | [malloc_dump_provider.cc][malloc-dp]. The crbug label is |
| 159 | [Hotlist-MemoryInfra][hotlist]. Don't hesitate to contact |
| 160 | [[email protected]][mailtracing] for questions and support. |
| 161 | |
| 162 | [dp-slides]: https://docs.google.com/presentation/d/1GI3HY3Mm5-Mvp6eZyVB0JiaJ-u3L1MMJeKHJg4lxjEI/present?slide=id.g995514d5c_1_45 |
| 163 | [malloc-dp]: https://chromium.googlesource.com/chromium/src.git/+/master/base/trace_event/malloc_dump_provider.cc |
| 164 | [hotlist]: https://code.google.com/p/chromium/issues/list?q=label:Hotlist-MemoryInfra |
| 165 | [mailtracing]: mailto:[email protected] |
| 166 | |
| 167 | ## Design documents |
| 168 | |
| 169 | Architectural: |
| 170 | |
| 171 | <iframe width="100%" height="300px" src="https://docs.google.com/a/google.com/embeddedfolderview?id=0B3KuDeqD-lVJfmp0cW1VcE5XVWNxZndxelV5T19kT2NFSndYZlNFbkFpc3pSa2VDN0hlMm8"> |
| 172 | </iframe> |
| 173 | |
| 174 | Chrome-side design docs: |
| 175 | |
| 176 | <iframe width="100%" height="300px" src="https://docs.google.com/a/google.com/embeddedfolderview?id=0B3KuDeqD-lVJfndSa2dleUQtMnZDeWpPZk1JV0QtbVM5STkwWms4YThzQ0pGTmU1QU9kNVk"> |
| 177 | </iframe> |
| 178 | |
| 179 | Catapult-side design docs: |
| 180 | |
| 181 | <iframe width="100%" height="300px" src="https://docs.google.com/a/google.com/embeddedfolderview?id=0B3KuDeqD-lVJfm10bXd5YmRNWUpKOElOWS0xdU1tMmV1S3F4aHo0ZDJLTmtGRy1qVnQtVWM"> |
| 182 | </iframe> |