OLD | NEW |
1 # Adding MemoryInfra Tracing to a Component | 1 # Adding MemoryInfra Tracing to a Component |
2 | 2 |
3 If you have a component that manages memory allocations, you should be | 3 If you have a component that manages memory allocations, you should be |
4 registering and tracking those allocations with Chrome's MemoryInfra system. | 4 registering and tracking those allocations with Chrome's MemoryInfra system. |
5 This lets you: | 5 This lets you: |
6 | 6 |
7 * See an overview of your allocations, giving insight into total size and | 7 * See an overview of your allocations, giving insight into total size and |
8 breakdown. | 8 breakdown. |
9 * Understand how your allocations change over time and how they are impacted by | 9 * Understand how your allocations change over time and how they are impacted by |
10 other parts of Chrome. | 10 other parts of Chrome. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 base::trace_event::MemoryAllocatorDumpGUID guid(alloc_->GetGUIDString()); | 141 base::trace_event::MemoryAllocatorDumpGUID guid(alloc_->GetGUIDString()); |
142 | 142 |
143 // From this global ID we can generate the parent allocator dump. | 143 // From this global ID we can generate the parent allocator dump. |
144 base::trace_event::MemoryAllocatorDump* target_mad = | 144 base::trace_event::MemoryAllocatorDump* target_mad = |
145 process_memory_dump->CreateSharedGlobalAllocatorDump(guid); | 145 process_memory_dump->CreateSharedGlobalAllocatorDump(guid); |
146 | 146 |
147 // We now create an ownership edge from the source dump to the target dump. | 147 // We now create an ownership edge from the source dump to the target dump. |
148 // When creating an edge, you can assign an importance to this edge. If all | 148 // When creating an edge, you can assign an importance to this edge. If all |
149 // edges have the same importance, the size of the allocation will be split | 149 // edges have the same importance, the size of the allocation will be split |
150 // between all sources which create a dump for the allocation. If one | 150 // between all sources which create a dump for the allocation. If one |
151 // edge has higher importance than the others, its soruce will be assigned the | 151 // edge has higher importance than the others, its source will be assigned the |
152 // full size of the allocation. | 152 // full size of the allocation. |
153 const int kImportance = 1; | 153 const int kImportance = 1; |
154 process_memory_dump->AddOwnershipEdge( | 154 process_memory_dump->AddOwnershipEdge( |
155 source_mad->guid(), target_mad->guid(), kImportance); | 155 source_mad->guid(), target_mad->guid(), kImportance); |
156 ``` | 156 ``` |
157 | 157 |
158 If an allocation is being shared across process boundaries, it may be useful to | 158 If an allocation is being shared across process boundaries, it may be useful to |
159 generate a global ID which incorporates the ID of the local process, preventing | 159 generate a global ID which incorporates the ID of the local process, preventing |
160 two processes from generating colliding IDs. As it is not recommended to pass a | 160 two processes from generating colliding IDs. As it is not recommended to pass a |
161 process ID between processes for security reasons, a function | 161 process ID between processes for security reasons, a function |
162 `MemoryDumpManager::GetTracingProcessId` is provided which generates a unique ID | 162 `MemoryDumpManager::GetTracingProcessId` is provided which generates a unique ID |
163 per process that can be passed with the resource without security concerns. | 163 per process that can be passed with the resource without security concerns. |
164 Frequently this ID is used to generate a global ID that is based on the | 164 Frequently this ID is used to generate a global ID that is based on the |
165 allocated resource's ID combined with the allocating process' tracing ID. | 165 allocated resource's ID combined with the allocating process' tracing ID. |
166 | 166 |
167 ## Suballocations | 167 ## Suballocations |
168 | 168 |
169 Another advanced use case involves tracking sub-allocations of a larger | 169 Another advanced use case involves tracking sub-allocations of a larger |
170 allocation. For instance, this is used in | 170 allocation. For instance, this is used in |
171 [`gpu::gles2::TextureManager`][texture-manager] to dump both the suballocations | 171 [`gpu::gles2::TextureManager`][texture-manager] to dump both the suballocations |
172 which make up a texture. To create a suballocation, instead of calling | 172 which make up a texture. To create a suballocation, instead of calling |
173 [`ProcessMemoryDump::CreateAllocatorDump`][pmd] to create a | 173 [`ProcessMemoryDump::CreateAllocatorDump`][pmd] to create a |
174 [`MemoryAllocatorDump`][mem-alloc-dump], you call | 174 [`MemoryAllocatorDump`][mem-alloc-dump], you call |
175 [`ProcessMemoryDump::AddSubAllocation`][pmd], providing the ID of the parent | 175 [`ProcessMemoryDump::AddSubAllocation`][pmd], providing the ID of the parent |
176 allocation as the first parameter. | 176 allocation as the first parameter. |
177 | 177 |
178 [texture-manager]: https://chromium.googlesource.com/chromium/src/+/master/gpu/c
ommand_buffer/service/texture_manager.cc | 178 [texture-manager]: https://chromium.googlesource.com/chromium/src/+/master/gpu/c
ommand_buffer/service/texture_manager.cc |
OLD | NEW |