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_field_id. This is used to
99  // get more compact varint encoding.
100  optional uint64 reference_field_id_base = 6;
101
102  // Indices for InternedData.field_names for the name of the field referring
103  // to the object. For Android S+ and for instances of normal classes (e.g.
104  // not instances of java.lang.Class or arrays), this is instead set in the
105  // corresponding HeapGraphType, and this is left empty.
106  repeated uint64 reference_field_id = 4 [packed = true];
107
108  // Ids of the Object that is referred to.
109  repeated uint64 reference_object_id = 5 [packed = true];
110}
111
112message HeapGraph {
113  optional int32 pid = 1;
114
115  // This contains all objects at the time this dump was taken. Some of these
116  // will be live, some of those unreachable (garbage). To find the live
117  // objects, the client needs to build the transitive closure of objects
118  // reachable from |roots|.
119  // All objects not contained within that transitive closure are garbage that
120  // has not yet been collected.
121  repeated HeapGraphObject objects = 2;
122
123  // Roots at the time this dump was taken.
124  // All live objects are reachable from the roots. All other objects are
125  // garbage.
126  repeated HeapGraphRoot roots = 7;
127
128  // Types used in HeapGraphObjects.
129  repeated HeapGraphType types = 9;
130
131  reserved 3;
132
133  // Field names for references in managed heap graph.
134  repeated InternedString field_names = 4;
135
136  // Paths of files used in managed heap graph.
137  repeated InternedString location_names = 8;
138
139  optional bool continued = 5;
140  optional uint64 index = 6;
141}
142