1/* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17syntax = "proto2"; 18 19package perfetto.protos; 20 21// Message definitions for app-reported memory breakdowns. At the moment, this 22// is a Chrome-only tracing feature, historically known as 'memory-infra'. See 23// https://chromium.googlesource.com/chromium/src/+/master/docs/memory-infra/ . 24// This is unrelated to the native or java heap profilers (those protos live 25// in //protos/perfetto/trace/profiling/). 26 27message MemoryTrackerSnapshot { 28 // Memory snapshot of a process. The snapshot contains memory data that is 29 // from 2 different sources, namely system stats and instrumentation stats. 30 // The system memory usage stats come from the OS based on standard API 31 // available in the platform to query memory usage. The instrumentation stats 32 // are added by instrumenting specific piece of code which tracks memory 33 // allocations and deallocations made by a small sub-system within the 34 // application. 35 // The system stats of the global memory snapshot are recorded as part of 36 // ProcessStats and SmapsPacket fields in trace packet with the same 37 // timestamp. 38 message ProcessSnapshot { 39 // Process ID of the process 40 optional int32 pid = 1; 41 42 // Memory dumps are represented as a graph of memory nodes which contain 43 // statistics. To avoid double counting the same memory across different 44 // nodes, edges are used to mark nodes that account for the same memory. See 45 // this doc for examples of the usage: 46 // https://docs.google.com/document/d/1WGQRJ1sjJrfVkNcgPVY6frm64UqPc94tsxUOXImZUZI 47 48 // A single node in the memory graph. 49 message MemoryNode { 50 // Unique ID of the node across all processes involved in the global 51 // memory dump. The ID is only unique within this particular global dump 52 // identified by GlobalMemoryDumpPacket.global_dump_id. 53 optional uint64 id = 1; 54 55 // Absolute name is a unique name for the memory node within the process 56 // with ProcessMemoryDump.pid. The name can contain multiple parts 57 // separated by '/', which traces the edges of the node from the root 58 // node. 59 // Eg: "partition_allocator/array_buffers/buffer1" refers to the child 60 // node "buffer1" in a graph structure of: 61 // root -> partition_allocator -> array_buffers -> buffer1. 62 optional string absolute_name = 2; 63 64 // A weak node means that the instrumentation that added the current node 65 // is unsure about the existence of the actual memory. Unless a "strong" 66 // (non-weak is default) node that has an edge to the current node exists 67 // in the current global dump, the current node will be discarded. 68 optional bool weak = 3; 69 70 // Size of the node in bytes, used to compute the effective size of the 71 // nodes without double counting. 72 optional uint64 size_bytes = 4; 73 74 // Entries in the memory node that contain statistics and additional 75 // debuggable information about the memory. The size of the node is 76 // tracked separately in the |size_bytes| field. 77 message MemoryNodeEntry { 78 optional string name = 1; 79 80 enum Units { 81 UNSPECIFIED = 0; 82 BYTES = 1; 83 COUNT = 2; 84 } 85 optional Units units = 2; 86 87 // Contains either one of uint64 or string value. 88 optional uint64 value_uint64 = 3; 89 optional string value_string = 4; 90 } 91 repeated MemoryNodeEntry entries = 5; 92 } 93 repeated MemoryNode allocator_dumps = 2; 94 95 // A directed edge that connects any 2 nodes in the graph above. These are 96 // in addition to the inherent edges added due to the tree structure of the 97 // node's absolute names. 98 // Node with id |source_id| owns the node with id |target_id|, and has the 99 // effect of attributing the memory usage of target to source. |importance| 100 // is optional and relevant only for the cases of co-ownership, where it 101 // acts as a z-index: the owner with the highest importance will be 102 // attributed target's memory. 103 message MemoryEdge { 104 optional uint64 source_id = 1; 105 optional uint64 target_id = 2; 106 optional uint32 importance = 3; 107 optional bool overridable = 4; 108 } 109 repeated MemoryEdge memory_edges = 3; 110 } 111 112 // Unique ID that represents the global memory dump. 113 optional uint64 global_dump_id = 1; 114 115 enum LevelOfDetail { 116 DETAIL_FULL = 0; 117 DETAIL_LIGHT = 1; 118 DETAIL_BACKGROUND = 2; 119 } 120 optional LevelOfDetail level_of_detail = 2; 121 122 repeated ProcessSnapshot process_memory_dumps = 3; 123} 124