• 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 // @param file_name
37 // @param file_name_iid
38 // @param path_iid
39 // @param start_address
40 // @param module_timestamp
41 // @param module_debugid
42 // @param module_debug_path
43 // @param protection_flags
44 // @param private_clean_resident_kb
45 // @param shared_dirty_resident_kb
46 // @param shared_clean_resident_kb
47 // @param locked_kb
48 // @param proportional_resident_kb
49 // @tablegroup Callstack profilers
50 #define PERFETTO_TP_PROFILER_SMAPS_DEF(NAME, PARENT, C) \
51   NAME(ProfilerSmapsTable, "profiler_smaps")            \
52   PERFETTO_TP_ROOT_TABLE(PARENT, C)                     \
53   C(uint32_t, upid)                                     \
54   C(int64_t, ts)                                        \
55   C(StringPool::Id, path)                               \
56   C(int64_t, size_kb)                                   \
57   C(int64_t, private_dirty_kb)                          \
58   C(int64_t, swap_kb)                                   \
59   C(StringPool::Id, file_name)                          \
60   C(int64_t, start_address)                             \
61   C(int64_t, module_timestamp)                          \
62   C(StringPool::Id, module_debugid)                     \
63   C(StringPool::Id, module_debug_path)                  \
64   C(int64_t, protection_flags)                          \
65   C(int64_t, private_clean_resident_kb)                 \
66   C(int64_t, shared_dirty_resident_kb)                  \
67   C(int64_t, shared_clean_resident_kb)                  \
68   C(int64_t, locked_kb)                                 \
69   C(int64_t, proportional_resident_kb)
70 
71 PERFETTO_TP_TABLE(PERFETTO_TP_PROFILER_SMAPS_DEF);
72 
73 // Metadata about packages installed on the system.
74 // This is generated by the packages_list data-source.
75 // @param package_name name of the package, e.g. com.google.android.gm.
76 // @param uid UID processes of this package run as.
77 // @param debuggable bool whether this app is debuggable.
78 // @param profileable_from_shell bool whether this app is profileable.
79 // @param version_code versionCode from the APK.
80 #define PERFETTO_TP_PACKAGES_LIST_DEF(NAME, PARENT, C) \
81   NAME(PackageListTable, "package_list")               \
82   PERFETTO_TP_ROOT_TABLE(PARENT, C)                    \
83   C(StringPool::Id, package_name)                      \
84   C(int64_t, uid)                                      \
85   C(int32_t, debuggable)                               \
86   C(int32_t, profileable_from_shell)                   \
87   C(int64_t, version_code)
88 
89 PERFETTO_TP_TABLE(PERFETTO_TP_PACKAGES_LIST_DEF);
90 
91 // A mapping (binary / library) in a process.
92 // This is generated by the stack profilers: heapprofd and traced_perf.
93 // @param build_id hex-encoded Build ID of the binary / library.
94 // @param start start of the mapping in the process' address space.
95 // @param end end of the mapping in the process' address space.
96 // @param name filename of the binary / library {@joinable profiler_smaps.path}.
97 // @tablegroup Callstack profilers
98 #define PERFETTO_TP_STACK_PROFILE_MAPPING_DEF(NAME, PARENT, C) \
99   NAME(StackProfileMappingTable, "stack_profile_mapping")      \
100   PERFETTO_TP_ROOT_TABLE(PARENT, C)                            \
101   C(StringPool::Id, build_id)                                  \
102   C(int64_t, exact_offset)                                     \
103   C(int64_t, start_offset)                                     \
104   C(int64_t, start)                                            \
105   C(int64_t, end)                                              \
106   C(int64_t, load_bias)                                        \
107   C(StringPool::Id, name)
108 
109 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_PROFILE_MAPPING_DEF);
110 
111 // A frame on the callstack. This is a location in a program.
112 // This is generated by the stack profilers: heapprofd and traced_perf.
113 // @param name name of the function this location is in.
114 // @param mapping the mapping (library / binary) this location is in.
115 // @param rel_pc the program counter relative to the start of the mapping.
116 // @param symbol_set_id if the profile was offline symbolized, the offline
117 //        symbol information of this frame.
118 //        {@joinable stack_profile_symbol.symbol_set_id}
119 // @tablegroup Callstack profilers
120 #define PERFETTO_TP_STACK_PROFILE_FRAME_DEF(NAME, PARENT, C) \
121   NAME(StackProfileFrameTable, "stack_profile_frame")        \
122   PERFETTO_TP_ROOT_TABLE(PARENT, C)                          \
123   C(StringPool::Id, name)                                    \
124   C(StackProfileMappingTable::Id, mapping)                   \
125   C(int64_t, rel_pc)                                         \
126   C(base::Optional<uint32_t>, symbol_set_id)                 \
127   C(base::Optional<StringPool::Id>, deobfuscated_name)
128 
129 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_PROFILE_FRAME_DEF);
130 
131 // A callsite. This is a list of frames that were on the stack.
132 // This is generated by the stack profilers: heapprofd and traced_perf.
133 // @param depth distance from the bottom-most frame of the callstack.
134 // @param parent_id parent frame on the callstack. NULL for the bottom-most.
135 // @param frame_id frame at this position in the callstack.
136 // @tablegroup Callstack profilers
137 #define PERFETTO_TP_STACK_PROFILE_CALLSITE_DEF(NAME, PARENT, C) \
138   NAME(StackProfileCallsiteTable, "stack_profile_callsite")     \
139   PERFETTO_TP_ROOT_TABLE(PARENT, C)                             \
140   C(uint32_t, depth)                                            \
141   C(base::Optional<StackProfileCallsiteTable::Id>, parent_id)   \
142   C(StackProfileFrameTable::Id, frame_id)
143 
144 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_PROFILE_CALLSITE_DEF);
145 
146 // TODO(rsavitski): rethink what to do with the root table now that only chrome
147 // callstacks use it.
148 
149 // Root table for timestamped stack samples.
150 // @param ts timestamp of the sample.
151 // @param callsite_id unwound callstack.
152 // @tablegroup Callstack profilers
153 #define PERFETTO_TP_STACK_SAMPLE_DEF(NAME, PARENT, C) \
154   NAME(StackSampleTable, "stack_sample")              \
155   PERFETTO_TP_ROOT_TABLE(PARENT, C)                   \
156   C(int64_t, ts, Column::Flag::kSorted)               \
157   C(StackProfileCallsiteTable::Id, callsite_id)
158 
159 PERFETTO_TP_TABLE(PERFETTO_TP_STACK_SAMPLE_DEF);
160 
161 // Samples from the Chromium stack sampler.
162 // @param ts timestamp this sample was taken at.
163 // @param utid thread that was active when the sample was taken.
164 // @param callsite_id callstack in active thread at time of sample.
165 // @tablegroup Callstack profilers
166 #define PERFETTO_TP_CPU_PROFILE_STACK_SAMPLE_DEF(NAME, PARENT, C) \
167   NAME(CpuProfileStackSampleTable, "cpu_profile_stack_sample")    \
168   PARENT(PERFETTO_TP_STACK_SAMPLE_DEF, C)                         \
169   C(uint32_t, utid)                                               \
170   C(int32_t, process_priority)
171 
172 PERFETTO_TP_TABLE(PERFETTO_TP_CPU_PROFILE_STACK_SAMPLE_DEF);
173 
174 // Samples from the traced_perf perf sampler.
175 //
176 // The table currently provides no means of discriminating between multiple data
177 // sources producing samples within a single trace.
178 // @param ts timestamp of the sample.
179 // @param utid sampled thread. {@joinable thread.utid}.
180 // @param cpu the core the sampled thread was running on.
181 // @param cpu_mode execution state (userspace/kernelspace) of the sampled
182 //        thread.
183 // @param callsite_id if set, unwound callstack of the sampled thread.
184 // @param unwind_error if set, indicates that the unwinding for this sample
185 //        encountered an error. Such samples still reference the best-effort
186 //        result via the callsite_id (with a synthetic error frame at the point
187 //        where unwinding stopped).
188 // @param perf_session_id distinguishes samples from different profiling
189 //        streams (i.e. multiple data sources).
190 //        {@joinable perf_counter_track.perf_session_id}
191 // @tablegroup Callstack profilers
192 #define PERFETTO_TP_PERF_SAMPLE_DEF(NAME, PARENT, C)            \
193   NAME(PerfSampleTable, "perf_sample")                          \
194   PERFETTO_TP_ROOT_TABLE(PARENT, C)                             \
195   C(int64_t, ts, Column::Flag::kSorted)                         \
196   C(uint32_t, utid)                                             \
197   C(uint32_t, cpu)                                              \
198   C(StringPool::Id, cpu_mode)                                   \
199   C(base::Optional<StackProfileCallsiteTable::Id>, callsite_id) \
200   C(base::Optional<StringPool::Id>, unwind_error)               \
201   C(uint32_t, perf_session_id)
202 
203 PERFETTO_TP_TABLE(PERFETTO_TP_PERF_SAMPLE_DEF);
204 
205 // Symbolization data for a frame. Rows with the same symbol_set_id describe
206 // one callframe, with the most-inlined symbol having id == symbol_set_id.
207 //
208 // For instance, if the function foo has an inlined call to the function bar,
209 // which has an inlined call to baz, the stack_profile_symbol table would look
210 // like this.
211 //
212 // ```
213 // |id|symbol_set_id|name         |source_file|line_number|
214 // |--|-------------|-------------|-----------|-----------|
215 // |1 |      1      |baz          |foo.cc     | 36        |
216 // |2 |      1      |bar          |foo.cc     | 30        |
217 // |3 |      1      |foo          |foo.cc     | 60        |
218 // ```
219 // @param name name of the function.
220 // @param source_file name of the source file containing the function.
221 // @param line_number line number of the frame in the source file. This is the
222 // exact line for the corresponding program counter, not the beginning of the
223 // function.
224 // @tablegroup Callstack profilers
225 #define PERFETTO_TP_SYMBOL_DEF(NAME, PARENT, C) \
226   NAME(SymbolTable, "stack_profile_symbol")     \
227   PERFETTO_TP_ROOT_TABLE(PARENT, C)             \
228   C(uint32_t, symbol_set_id)                    \
229   C(StringPool::Id, name)                       \
230   C(StringPool::Id, source_file)                \
231   C(uint32_t, line_number)
232 
233 PERFETTO_TP_TABLE(PERFETTO_TP_SYMBOL_DEF);
234 
235 // Allocations that happened at a callsite.
236 //
237 //
238 // NOTE: this table is not sorted by timestamp intentionanlly - see b/193757386
239 // for details.
240 // TODO(b/193757386): readd the sorted flag once this bug is fixed.
241 //
242 // This is generated by heapprofd.
243 // @param ts the timestamp the allocations happened at. heapprofd batches
244 // allocations and frees, and all data from a dump will have the same
245 // timestamp.
246 // @param upid the UniquePID of the allocating process.
247 //        {@joinable process.upid}
248 // @param callsite_id the callsite the allocation happened at.
249 // @param count if positive: number of allocations that happened at this
250 // callsite. if negative: number of allocations that happened at this callsite
251 // that were freed.
252 // @param size if positive: size of allocations that happened at this
253 // callsite. if negative: size of allocations that happened at this callsite
254 // that were freed.
255 // @tablegroup Callstack profilers
256 #define PERFETTO_TP_HEAP_PROFILE_ALLOCATION_DEF(NAME, PARENT, C) \
257   NAME(HeapProfileAllocationTable, "heap_profile_allocation")    \
258   PERFETTO_TP_ROOT_TABLE(PARENT, C)                              \
259   C(int64_t, ts)                                                 \
260   C(uint32_t, upid)                                              \
261   C(StringPool::Id, heap_name)                                   \
262   C(StackProfileCallsiteTable::Id, callsite_id)                  \
263   C(int64_t, count)                                              \
264   C(int64_t, size)
265 
266 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_PROFILE_ALLOCATION_DEF);
267 
268 // Table used to render flamegraphs. This gives cumulative sizes of nodes in
269 // the flamegraph.
270 //
271 // WARNING: This is experimental and the API is subject to change.
272 // @tablegroup Callstack profilers
273 #define PERFETTO_TP_EXPERIMENTAL_FLAMEGRAPH_NODES(NAME, PARENT, C)        \
274   NAME(ExperimentalFlamegraphNodesTable, "experimental_flamegraph_nodes") \
275   PERFETTO_TP_ROOT_TABLE(PARENT, C)                                       \
276   C(int64_t, ts, Column::Flag::kSorted | Column::Flag::kHidden)           \
277   C(uint32_t, upid, Column::Flag::kHidden)                                \
278   C(StringPool::Id, profile_type, Column::Flag::kHidden)                  \
279   C(StringPool::Id, focus_str, Column::Flag::kHidden)                     \
280   C(uint32_t, depth)                                                      \
281   C(StringPool::Id, name)                                                 \
282   C(StringPool::Id, map_name)                                             \
283   C(int64_t, count)                                                       \
284   C(int64_t, cumulative_count)                                            \
285   C(int64_t, size)                                                        \
286   C(int64_t, cumulative_size)                                             \
287   C(int64_t, alloc_count)                                                 \
288   C(int64_t, cumulative_alloc_count)                                      \
289   C(int64_t, alloc_size)                                                  \
290   C(int64_t, cumulative_alloc_size)                                       \
291   C(base::Optional<ExperimentalFlamegraphNodesTable::Id>, parent_id)      \
292   C(base::Optional<StringPool::Id>, source_file)                          \
293   C(base::Optional<uint32_t>, line_number)                                \
294   C(base::Optional<StringPool::Id>, upid_group)
295 
296 PERFETTO_TP_TABLE(PERFETTO_TP_EXPERIMENTAL_FLAMEGRAPH_NODES);
297 
298 // @param name (potentially obfuscated) name of the class.
299 // @param deobfuscated_name if class name was obfuscated and deobfuscation map
300 // for it provided, the deobfuscated name.
301 // @param location the APK / Dex / JAR file the class is contained in.
302 // @tablegroup ART Heap Graphs
303 //
304 // classloader_id should really be HeapGraphObject::id, but that would
305 // create a loop, which is currently not possible.
306 // TODO(lalitm): resolve this
307 #define PERFETTO_TP_HEAP_GRAPH_CLASS_DEF(NAME, PARENT, C)   \
308   NAME(HeapGraphClassTable, "heap_graph_class")             \
309   PERFETTO_TP_ROOT_TABLE(PARENT, C)                         \
310   C(StringPool::Id, name)                                   \
311   C(base::Optional<StringPool::Id>, deobfuscated_name)      \
312   C(base::Optional<StringPool::Id>, location)               \
313   C(base::Optional<HeapGraphClassTable::Id>, superclass_id) \
314   C(base::Optional<uint32_t>, classloader_id)               \
315   C(StringPool::Id, kind)
316 
317 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_GRAPH_CLASS_DEF);
318 
319 // The objects on the Dalvik heap.
320 //
321 // All rows with the same (upid, graph_sample_ts) are one dump.
322 // @param upid UniquePid of the target {@joinable process.upid}.
323 // @param graph_sample_ts timestamp this dump was taken at.
324 // @param self_size size this object uses on the Java Heap.
325 // @param native_size approximate amount of native memory used by this object,
326 //        as reported by libcore.util.NativeAllocationRegistry.size.
327 // @param reference_set_id join key with heap_graph_reference containing all
328 //        objects referred in this object's fields.
329 //        {@joinable heap_graph_reference.reference_set_id}
330 // @param reachable bool whether this object is reachable from a GC root. If
331 // false, this object is uncollected garbage.
332 // @param type_id class this object is an instance of.
333 // @param root_type if not NULL, this object is a GC root.
334 // @tablegroup ART Heap Graphs
335 #define PERFETTO_TP_HEAP_GRAPH_OBJECT_DEF(NAME, PARENT, C)            \
336   NAME(HeapGraphObjectTable, "heap_graph_object")                     \
337   PERFETTO_TP_ROOT_TABLE(PARENT, C)                                   \
338   C(uint32_t, upid)                                                   \
339   C(int64_t, graph_sample_ts)                                         \
340   C(int64_t, self_size)                                               \
341   C(int64_t, native_size)                                             \
342   C(base::Optional<uint32_t>, reference_set_id, Column::Flag::kDense) \
343   C(int32_t, reachable)                                               \
344   C(HeapGraphClassTable::Id, type_id)                                 \
345   C(base::Optional<StringPool::Id>, root_type)                        \
346   C(int32_t, root_distance, Column::Flag::kHidden)
347 
348 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_GRAPH_OBJECT_DEF);
349 
350 // Many-to-many mapping between heap_graph_object.
351 //
352 // This associates the object with given reference_set_id with the objects
353 // that are referred to by its fields.
354 // @param reference_set_id join key to heap_graph_object.
355 // @param owner_id id of object that has this reference_set_id.
356 // @param owned_id id of object that is referred to.
357 // @param field_name the field that refers to the object. E.g. Foo.name.
358 // @param field_type_name the static type of the field. E.g. java.lang.String.
359 // @param deobfuscated_field_name if field_name was obfuscated and a
360 // deobfuscation mapping was provided for it, the deobfuscated name.
361 // @tablegroup ART Heap Graphs
362 #define PERFETTO_TP_HEAP_GRAPH_REFERENCE_DEF(NAME, PARENT, C) \
363   NAME(HeapGraphReferenceTable, "heap_graph_reference")       \
364   PERFETTO_TP_ROOT_TABLE(PARENT, C)                           \
365   C(uint32_t, reference_set_id, Column::Flag::kSorted)        \
366   C(HeapGraphObjectTable::Id, owner_id)                       \
367   C(base::Optional<HeapGraphObjectTable::Id>, owned_id)       \
368   C(StringPool::Id, field_name)                               \
369   C(StringPool::Id, field_type_name)                          \
370   C(base::Optional<StringPool::Id>, deobfuscated_field_name)
371 
372 PERFETTO_TP_TABLE(PERFETTO_TP_HEAP_GRAPH_REFERENCE_DEF);
373 
374 // @param arg_set_id {@joinable args.arg_set_id}
375 #define PERFETTO_TP_VULKAN_MEMORY_ALLOCATIONS_DEF(NAME, PARENT, C) \
376   NAME(VulkanMemoryAllocationsTable, "vulkan_memory_allocations")  \
377   PERFETTO_TP_ROOT_TABLE(PARENT, C)                                \
378   C(StringPool::Id, source)                                        \
379   C(StringPool::Id, operation)                                     \
380   C(int64_t, timestamp)                                            \
381   C(base::Optional<uint32_t>, upid)                                \
382   C(base::Optional<int64_t>, device)                               \
383   C(base::Optional<int64_t>, device_memory)                        \
384   C(base::Optional<uint32_t>, memory_type)                         \
385   C(base::Optional<uint32_t>, heap)                                \
386   C(base::Optional<StringPool::Id>, function_name)                 \
387   C(base::Optional<int64_t>, object_handle)                        \
388   C(base::Optional<int64_t>, memory_address)                       \
389   C(base::Optional<int64_t>, memory_size)                          \
390   C(StringPool::Id, scope)                                         \
391   C(base::Optional<uint32_t>, arg_set_id)
392 
393 PERFETTO_TP_TABLE(PERFETTO_TP_VULKAN_MEMORY_ALLOCATIONS_DEF);
394 
395 #define PERFETTO_TP_GPU_COUNTER_GROUP_DEF(NAME, PARENT, C) \
396   NAME(GpuCounterGroupTable, "gpu_counter_group")          \
397   PERFETTO_TP_ROOT_TABLE(PARENT, C)                        \
398   C(int32_t, group_id)                                     \
399   C(TrackTable::Id, track_id)
400 
401 PERFETTO_TP_TABLE(PERFETTO_TP_GPU_COUNTER_GROUP_DEF);
402 
403 }  // namespace tables
404 }  // namespace trace_processor
405 }  // namespace perfetto
406 
407 #endif  // SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_H_
408