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