• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_H_
18 #define SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_H_
19 
20 #include "src/trace_processor/tables/macros.h"
21 #include "src/trace_processor/tables/track_tables.h"
22 
23 namespace perfetto {
24 namespace trace_processor {
25 namespace tables {
26 
27 // The profiler smaps contains the memory stats for virtual memory ranges
28 // captured by the [heap profiler](/docs/data-sources/native-heap-profiler.md).
29 // @param upid The UniquePID of the process {@joinable process.upid}.
30 // @param ts   Timestamp of the snapshot. Multiple rows will have the same
31 //             timestamp.
32 // @param path The mmaped file, as per /proc/pid/smaps.
33 // @param size_kb Total size of the mapping.
34 // @param private_dirty_kb KB of this mapping that are private dirty  RSS.
35 // @param swap_kb KB of this mapping that are in swap.
36 // @tablegroup Callstack profilers
37 #define PERFETTO_TP_PROFILER_SMAPS_DEF(NAME, PARENT, C) \
38   NAME(ProfilerSmapsTable, "profiler_smaps")            \
39   PERFETTO_TP_ROOT_TABLE(PARENT, C)                     \
40   C(uint32_t, upid)                                     \
41   C(int64_t, ts)                                        \
42   C(StringPool::Id, path)                               \
43   C(int64_t, size_kb)                                   \
44   C(int64_t, private_dirty_kb)                          \
45   C(int64_t, swap_kb)
46 
47 PERFETTO_TP_TABLE(PERFETTO_TP_PROFILER_SMAPS_DEF);
48 
49 // Metadata about packages installed on the system.
50 // This is generated by the packages_list data-source.
51 // @param package_name name of the package, e.g. com.google.android.gm.
52 // @param uid UID processes of this package run as.
53 // @param debuggable bool whether this app is debuggable.
54 // @param profileable_from_shell bool whether this app is profileable.
55 // @param version_code versionCode from the APK.
56 #define PERFETTO_TP_PACKAGES_LIST_DEF(NAME, PARENT, C) \
57   NAME(PackageListTable, "package_list")               \
58   PERFETTO_TP_ROOT_TABLE(PARENT, C)                    \
59   C(StringPool::Id, package_name)                      \
60   C(int64_t, uid)                                      \
61   C(int32_t, debuggable)                               \
62   C(int32_t, profileable_from_shell)                   \
63   C(int64_t, version_code)
64 
65 PERFETTO_TP_TABLE(PERFETTO_TP_PACKAGES_LIST_DEF);
66 
67 // A mapping (binary / library) in a process.
68 // This is generated by the stack profilers: heapprofd and traced_perf.
69 // @param build_id hex-encoded Build ID of the binary / library.
70 // @param start start of the mapping in the process' address space.
71 // @param end end of the mapping in the process' address space.
72 // @param name filename of the binary / library {@joinable profiler_smaps.path}.
73 // @tablegroup Callstack profilers
74 #define PERFETTO_TP_STACK_PROFILE_MAPPING_DEF(NAME, PARENT, C) \
75   NAME(StackProfileMappingTable, "stack_profile_mapping")      \
76   PERFETTO_TP_ROOT_TABLE(PARENT, C)                            \
77   C(StringPool::Id, build_id)                                  \
78   C(int64_t, exact_offset)                                     \
79   C(int64_t, start_offset)                                     \
80   C(int64_t, start)                                            \
81   C(int64_t, end)                                              \
82   C(int64_t, load_bias)                                        \
83   C(StringPool::Id, name)
84 
85 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_PROFILE_MAPPING_DEF);
86 
87 // A frame on the callstack. This is a location in a program.
88 // This is generated by the stack profilers: heapprofd and traced_perf.
89 // @param name name of the function this location is in.
90 // @param mapping the mapping (library / binary) this location is in.
91 // @param rel_pc the program counter relative to the start of the mapping.
92 // @param symbol_set_id if the profile was offline symbolized, the offline
93 //        symbol information of this frame.
94 //        {@joinable stack_profile_symbol.symbol_set_id}
95 // @tablegroup Callstack profilers
96 #define PERFETTO_TP_STACK_PROFILE_FRAME_DEF(NAME, PARENT, C) \
97   NAME(StackProfileFrameTable, "stack_profile_frame")        \
98   PERFETTO_TP_ROOT_TABLE(PARENT, C)                          \
99   C(StringPool::Id, name)                                    \
100   C(StackProfileMappingTable::Id, mapping)                   \
101   C(int64_t, rel_pc)                                         \
102   C(base::Optional<uint32_t>, symbol_set_id)
103 
104 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_PROFILE_FRAME_DEF);
105 
106 // A callsite. This is a list of frames that were on the stack.
107 // This is generated by the stack profilers: heapprofd and traced_perf.
108 // @param depth distance from the bottom-most frame of the callstack.
109 // @param parent_id parent frame on the callstack. NULL for the bottom-most.
110 // @param frame_id frame at this position in the callstack.
111 // @tablegroup Callstack profilers
112 #define PERFETTO_TP_STACK_PROFILE_CALLSITE_DEF(NAME, PARENT, C) \
113   NAME(StackProfileCallsiteTable, "stack_profile_callsite")     \
114   PERFETTO_TP_ROOT_TABLE(PARENT, C)                             \
115   C(uint32_t, depth)                                            \
116   C(base::Optional<StackProfileCallsiteTable::Id>, parent_id)   \
117   C(StackProfileFrameTable::Id, frame_id)
118 
119 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_PROFILE_CALLSITE_DEF);
120 
121 // This is generated by traced_perf.
122 // @param ts timestamp this sample was taken at.
123 // @param utid thread that was active when the sample was taken.
124 // @param callsite_id callstack in active thread at time of sample.
125 // @tablegroup Callstack profilers
126 #define PERFETTO_TP_CPU_PROFILE_STACK_SAMPLE_DEF(NAME, PARENT, C) \
127   NAME(CpuProfileStackSampleTable, "cpu_profile_stack_sample")    \
128   PERFETTO_TP_ROOT_TABLE(PARENT, C)                               \
129   C(int64_t, ts, Column::Flag::kSorted)                           \
130   C(StackProfileCallsiteTable::Id, callsite_id)                   \
131   C(uint32_t, utid)                                               \
132   C(int32_t, process_priority)
133 
134 PERFETTO_TP_TABLE(PERFETTO_TP_CPU_PROFILE_STACK_SAMPLE_DEF);
135 
136 // Symbolization data for a frame. Rows with them same symbol_set_id describe
137 // one frame, with the bottom-most inlined frame having id == symbol_set_id.
138 //
139 // For instance, if the function foo has an inlined call to the function bar,
140 // which has an inlined call to baz, the stack_profile_symbol table would look
141 // like this.
142 //
143 // ```
144 // |id|symbol_set_id|name         |source_file|line_number|
145 // |--|-------------|-------------|-----------|-----------|
146 // |1 |      1      |foo          |foo.cc     | 60        |
147 // |2 |      1      |bar          |foo.cc     | 30        |
148 // |3 |      1      |baz          |foo.cc     | 36        |
149 // ```
150 // @param name name of the function.
151 // @param source_file name of the source file containing the function.
152 // @param line_number line number of the frame in the source file. This is the
153 // exact line for the corresponding program counter, not the beginning of the
154 // function.
155 // @tablegroup Callstack profilers
156 #define PERFETTO_TP_SYMBOL_DEF(NAME, PARENT, C) \
157   NAME(SymbolTable, "stack_profile_symbol")     \
158   PERFETTO_TP_ROOT_TABLE(PARENT, C)             \
159   C(uint32_t, symbol_set_id)                    \
160   C(StringPool::Id, name)                       \
161   C(StringPool::Id, source_file)                \
162   C(uint32_t, line_number)
163 
164 PERFETTO_TP_TABLE(PERFETTO_TP_SYMBOL_DEF);
165 
166 // Allocations that happened at a callsite.
167 // This is generated by heapprofd.
168 // @param ts the timestamp the allocations happened at. heapprofd batches
169 // allocations and frees, and all data from a dump will have the same
170 // timestamp.
171 // @param upid the UniquePID of the allocating process.
172 //        {@joinable process.upid}
173 // @param callsite_id the callsite the allocation happened at.
174 // @param count if positive: number of allocations that happened at this
175 // callsite. if negative: number of allocations that happened at this callsite
176 // that were freed.
177 // @param size if positive: size of allocations that happened at this
178 // callsite. if negative: size of allocations that happened at this callsite
179 // that were freed.
180 // @tablegroup Callstack profilers
181 #define PERFETTO_TP_HEAP_PROFILE_ALLOCATION_DEF(NAME, PARENT, C) \
182   NAME(HeapProfileAllocationTable, "heap_profile_allocation")    \
183   PERFETTO_TP_ROOT_TABLE(PARENT, C)                              \
184   C(int64_t, ts, Column::Flag::kSorted)                          \
185   C(uint32_t, upid)                                              \
186   C(StackProfileCallsiteTable::Id, callsite_id)                  \
187   C(int64_t, count)                                              \
188   C(int64_t, size)
189 
190 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_PROFILE_ALLOCATION_DEF);
191 
192 // Table used to render flamegraphs. This gives cumulative sizes of nodes in
193 // the flamegraph.
194 //
195 // WARNING: This is experimental and the API is subject to change.
196 // @tablegroup Callstack profilers
197 #define PERFETTO_TP_EXPERIMENTAL_FLAMEGRAPH_NODES(NAME, PARENT, C)        \
198   NAME(ExperimentalFlamegraphNodesTable, "experimental_flamegraph_nodes") \
199   PERFETTO_TP_ROOT_TABLE(PARENT, C)                                       \
200   C(int64_t, ts, Column::Flag::kSorted | Column::Flag::kHidden)           \
201   C(uint32_t, upid, Column::Flag::kHidden)                                \
202   C(StringPool::Id, profile_type, Column::Flag::kHidden)                  \
203   C(StringPool::Id, focus_str, Column::Flag::kHidden)                     \
204   C(uint32_t, depth)                                                      \
205   C(StringPool::Id, name)                                                 \
206   C(StringPool::Id, map_name)                                             \
207   C(int64_t, count)                                                       \
208   C(int64_t, cumulative_count)                                            \
209   C(int64_t, size)                                                        \
210   C(int64_t, cumulative_size)                                             \
211   C(int64_t, alloc_count)                                                 \
212   C(int64_t, cumulative_alloc_count)                                      \
213   C(int64_t, alloc_size)                                                  \
214   C(int64_t, cumulative_alloc_size)                                       \
215   C(base::Optional<ExperimentalFlamegraphNodesTable::Id>, parent_id)
216 
217 PERFETTO_TP_TABLE(PERFETTO_TP_EXPERIMENTAL_FLAMEGRAPH_NODES);
218 
219 // @param name (potentially obfuscated) name of the class.
220 // @param deobfuscated_name if class name was obfuscated and deobfuscation map
221 // for it provided, the deobfuscated name.
222 // @param location the APK / Dex / JAR file the class is contained in.
223 // @tablegroup ART Heap Profiler
224 #define PERFETTO_TP_HEAP_GRAPH_CLASS_DEF(NAME, PARENT, C) \
225   NAME(HeapGraphClassTable, "heap_graph_class")           \
226   PERFETTO_TP_ROOT_TABLE(PARENT, C)                       \
227   C(StringPool::Id, name)                                 \
228   C(base::Optional<StringPool::Id>, deobfuscated_name)    \
229   C(base::Optional<StringPool::Id>, location)
230 
231 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_GRAPH_CLASS_DEF);
232 
233 // The objects on the Dalvik heap.
234 //
235 // All rows with the same (upid, graph_sample_ts) are one dump.
236 // @param upid UniquePid of the target {@joinable process.upid}.
237 // @param graph_sample_ts timestamp this dump was taken at.
238 // @param self_size size this object uses on the Java Heap.
239 // @param reference_set_id join key with heap_graph_reference containing all
240 //        objects referred in this object's fields.
241 //        {@joinable heap_graph_reference.reference_set_id}
242 // @param reachable bool whether this object is reachable from a GC root. If
243 // false, this object is uncollected garbage.
244 // @param type_id class this object is an instance of.
245 // @param root_type if not NULL, this object is a GC root.
246 // @tablegroup ART Heap Profiler
247 #define PERFETTO_TP_HEAP_GRAPH_OBJECT_DEF(NAME, PARENT, C)            \
248   NAME(HeapGraphObjectTable, "heap_graph_object")                     \
249   PERFETTO_TP_ROOT_TABLE(PARENT, C)                                   \
250   C(uint32_t, upid)                                                   \
251   C(int64_t, graph_sample_ts)                                         \
252   C(int64_t, self_size)                                               \
253   C(base::Optional<uint32_t>, reference_set_id, Column::Flag::kDense) \
254   C(int32_t, reachable)                                               \
255   C(HeapGraphClassTable::Id, type_id)                                 \
256   C(base::Optional<StringPool::Id>, root_type)                        \
257   C(int32_t, root_distance, Column::Flag::kHidden)
258 
259 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_GRAPH_OBJECT_DEF);
260 
261 // Many-to-many mapping between heap_graph_object.
262 //
263 // This associates the object with given reference_set_id with the objects
264 // that are referred to by its fields.
265 // @param reference_set_id join key to heap_graph_object.
266 // @param owner_id id of object that has this reference_set_id.
267 // @param owned_id id of object that is referred to.
268 // @param field_name the field that refers to the object. E.g. Foo.name.
269 // @param field_type_name the static type of the field. E.g. java.lang.String.
270 // @param deobfuscated_field_name if field_name was obfuscated and a
271 // deobfuscation mapping was provided for it, the deobfuscated name.
272 // @tablegroup ART Heap Profiler
273 #define PERFETTO_TP_HEAP_GRAPH_REFERENCE_DEF(NAME, PARENT, C) \
274   NAME(HeapGraphReferenceTable, "heap_graph_reference")       \
275   PERFETTO_TP_ROOT_TABLE(PARENT, C)                           \
276   C(uint32_t, reference_set_id, Column::Flag::kSorted)        \
277   C(HeapGraphObjectTable::Id, owner_id)                       \
278   C(HeapGraphObjectTable::Id, owned_id)                       \
279   C(StringPool::Id, field_name)                               \
280   C(StringPool::Id, field_type_name)                          \
281   C(base::Optional<StringPool::Id>, deobfuscated_field_name)
282 
283 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_GRAPH_REFERENCE_DEF);
284 
285 // @param arg_set_id {@joinable args.arg_set_id}
286 #define PERFETTO_TP_VULKAN_MEMORY_ALLOCATIONS_DEF(NAME, PARENT, C) \
287   NAME(VulkanMemoryAllocationsTable, "vulkan_memory_allocations")  \
288   PERFETTO_TP_ROOT_TABLE(PARENT, C)                                \
289   C(StringPool::Id, source)                                        \
290   C(StringPool::Id, operation)                                     \
291   C(int64_t, timestamp)                                            \
292   C(base::Optional<uint32_t>, upid)                                \
293   C(base::Optional<int64_t>, device)                               \
294   C(base::Optional<int64_t>, device_memory)                        \
295   C(base::Optional<uint32_t>, memory_type)                         \
296   C(base::Optional<uint32_t>, heap)                                \
297   C(base::Optional<StringPool::Id>, function_name)                 \
298   C(base::Optional<int64_t>, object_handle)                        \
299   C(base::Optional<int64_t>, memory_address)                       \
300   C(base::Optional<int64_t>, memory_size)                          \
301   C(StringPool::Id, scope)                                         \
302   C(base::Optional<uint32_t>, arg_set_id)
303 
304 PERFETTO_TP_TABLE(PERFETTO_TP_VULKAN_MEMORY_ALLOCATIONS_DEF);
305 
306 #define PERFETTO_TP_GPU_COUNTER_GROUP_DEF(NAME, PARENT, C) \
307   NAME(GpuCounterGroupTable, "gpu_counter_group")          \
308   PERFETTO_TP_ROOT_TABLE(PARENT, C)                        \
309   C(int32_t, group_id)                                     \
310   C(TrackTable::Id, track_id)
311 
312 PERFETTO_TP_TABLE(PERFETTO_TP_GPU_COUNTER_GROUP_DEF);
313 
314 }  // namespace tables
315 }  // namespace trace_processor
316 }  // namespace perfetto
317 
318 #endif  // SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_H_
319