xref: /aosp_15_r20/external/perfetto/protos/perfetto/trace/profiling/heap_graph.proto (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1/*
2 * Copyright (C) 2019 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
19// TODO(fmayer): Remove this import once clients are migrated to the new
20// location.
21import public "protos/perfetto/trace/profiling/deobfuscation.proto";
22import "protos/perfetto/trace/profiling/profile_common.proto";
23
24// These messages encode a graph of objects that retain one another. Currently
25// this is used for Android Runtime (i.e. Java and Kotlin) heap graphs.
26
27package perfetto.protos;
28
29message HeapGraphRoot {
30  enum Type {
31    ROOT_UNKNOWN = 0;
32    ROOT_JNI_GLOBAL = 1;
33    ROOT_JNI_LOCAL = 2;
34    ROOT_JAVA_FRAME = 3;
35    ROOT_NATIVE_STACK = 4;
36    ROOT_STICKY_CLASS = 5;
37    ROOT_THREAD_BLOCK = 6;
38    ROOT_MONITOR_USED = 7;
39    ROOT_THREAD_OBJECT = 8;
40    ROOT_INTERNED_STRING = 9;
41    ROOT_FINALIZING = 10;
42    ROOT_DEBUGGER = 11;
43    ROOT_REFERENCE_CLEANUP = 12;
44    ROOT_VM_INTERNAL = 13;
45    ROOT_JNI_MONITOR = 14;
46  };
47  // Objects retained by this root.
48  repeated uint64 object_ids = 1 [packed = true];
49
50  optional Type root_type = 2;
51}
52
53message HeapGraphType {
54  enum Kind {
55    KIND_UNKNOWN = 0;
56    KIND_NORMAL = 1;
57    KIND_NOREFERENCES = 2;
58    KIND_STRING = 3;
59    KIND_ARRAY = 4;
60    KIND_CLASS = 5;
61    KIND_CLASSLOADER = 6;
62    KIND_DEXCACHE = 7;
63    KIND_SOFT_REFERENCE = 8;
64    KIND_WEAK_REFERENCE = 9;
65    KIND_FINALIZER_REFERENCE = 10;
66    KIND_PHANTOM_REFERENCE = 11;
67  };
68  // TODO(fmayer): Consider removing this and using the index in the repeaed
69  // field to save space.
70  optional uint64 id = 1;
71  optional uint64 location_id = 2;
72  optional string class_name = 3;
73  // Size of objects of this type.
74  optional uint64 object_size = 4;
75  optional uint64 superclass_id = 5;
76  // Indices for InternedData.field_names for the names of the fields of
77  // instances of this class. This does NOT include the fields from
78  // superclasses. The consumer of this data needs to walk all super
79  // classes to get a full lists of fields. Objects always write the
80  // fields in order of most specific class to the furthest up superclass.
81  repeated uint64 reference_field_id = 6 [packed = true];
82  optional Kind kind = 7;
83  optional uint64 classloader_id = 8;
84}
85
86message HeapGraphObject {
87  oneof identifier {
88    uint64 id = 1;
89    uint64 id_delta = 7;
90  }
91
92  // Index for InternedData.types for the name of the type of this object.
93  optional uint64 type_id = 2;
94
95  // Bytes occupied by this objects.
96  optional uint64 self_size = 3;
97
98  // Add this to all non-zero values in reference_object_id. This is used to
99  // get more compact varint encoding.
100  //
101  // The name is confusing, but this has always been used as a base for
102  // reference_object_id. The field should be named reference_object_id_base.
103  optional uint64 reference_field_id_base = 6;
104
105  // Indices for InternedData.field_names for the name of the field referring
106  // to the object. For Android S+ and for instances of normal classes (e.g.
107  // not instances of java.lang.Class or arrays), this is instead set in the
108  // corresponding HeapGraphType, and this is left empty.
109  repeated uint64 reference_field_id = 4 [packed = true];
110
111  // Ids of the Object that is referred to.
112  repeated uint64 reference_object_id = 5 [packed = true];
113
114  // If this object is an instance of `libcore.util.NativeAllocationRegistry`,
115  // the value of the `size` field.
116  //
117  // N.B. This is not the native size of this object.
118  optional int64 native_allocation_registry_size_field = 8;
119
120  enum HeapType {
121    HEAP_TYPE_UNKNOWN = 0;
122    HEAP_TYPE_APP = 1;
123    HEAP_TYPE_ZYGOTE = 2;
124    HEAP_TYPE_BOOT_IMAGE = 3;
125  }
126  // To reduce the space required we only emit the heap type if it has changed
127  // from the previous object we recorded.
128  optional HeapType heap_type_delta = 9;
129}
130
131message HeapGraph {
132  optional int32 pid = 1;
133
134  // This contains all objects at the time this dump was taken. Some of these
135  // will be live, some of those unreachable (garbage). To find the live
136  // objects, the client needs to build the transitive closure of objects
137  // reachable from |roots|.
138  // All objects not contained within that transitive closure are garbage that
139  // has not yet been collected.
140  repeated HeapGraphObject objects = 2;
141
142  // Roots at the time this dump was taken.
143  // All live objects are reachable from the roots. All other objects are
144  // garbage.
145  repeated HeapGraphRoot roots = 7;
146
147  // Types used in HeapGraphObjects.
148  repeated HeapGraphType types = 9;
149
150  reserved 3;
151
152  // Field names for references in managed heap graph.
153  repeated InternedString field_names = 4;
154
155  // Paths of files used in managed heap graph.
156  repeated InternedString location_names = 8;
157
158  optional bool continued = 5;
159  optional uint64 index = 6;
160}
161