xref: /aosp_15_r20/external/perfetto/src/trace_processor/storage/trace_storage.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2017 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_STORAGE_TRACE_STORAGE_H_
18 #define SRC_TRACE_PROCESSOR_STORAGE_TRACE_STORAGE_H_
19 
20 #include <algorithm>
21 #include <array>
22 #include <cstddef>
23 #include <cstdint>
24 #include <deque>
25 #include <functional>
26 #include <iterator>
27 #include <limits>
28 #include <map>
29 #include <memory>
30 #include <optional>
31 #include <string>
32 #include <string_view>
33 #include <utility>
34 #include <vector>
35 
36 #include "perfetto/base/logging.h"
37 #include "perfetto/base/status.h"
38 #include "perfetto/base/time.h"
39 #include "perfetto/ext/base/string_view.h"
40 #include "perfetto/trace_processor/basic_types.h"
41 #include "perfetto/trace_processor/trace_blob_view.h"
42 #include "src/trace_processor/containers/null_term_string_view.h"
43 #include "src/trace_processor/containers/string_pool.h"
44 #include "src/trace_processor/db/column/types.h"
45 #include "src/trace_processor/db/typed_column_internal.h"
46 #include "src/trace_processor/storage/stats.h"
47 #include "src/trace_processor/tables/android_tables_py.h"
48 #include "src/trace_processor/tables/counter_tables_py.h"
49 #include "src/trace_processor/tables/etm_tables_py.h"
50 #include "src/trace_processor/tables/flow_tables_py.h"
51 #include "src/trace_processor/tables/jit_tables_py.h"
52 #include "src/trace_processor/tables/memory_tables_py.h"
53 #include "src/trace_processor/tables/metadata_tables_py.h"
54 #include "src/trace_processor/tables/perf_tables_py.h"
55 #include "src/trace_processor/tables/profiler_tables_py.h"
56 #include "src/trace_processor/tables/sched_tables_py.h"
57 #include "src/trace_processor/tables/slice_tables_py.h"
58 #include "src/trace_processor/tables/trace_proto_tables_py.h"
59 #include "src/trace_processor/tables/track_tables_py.h"
60 #include "src/trace_processor/tables/v8_tables_py.h"
61 #include "src/trace_processor/tables/winscope_tables_py.h"
62 #include "src/trace_processor/types/destructible.h"
63 #include "src/trace_processor/types/variadic.h"
64 
65 namespace perfetto::trace_processor {
66 namespace etm {
67 class TargetMemory;
68 }
69 
70 // UniquePid is an offset into |unique_processes_|. This is necessary because
71 // Unix pids are reused and thus not guaranteed to be unique over a long
72 // period of time.
73 using UniquePid = uint32_t;
74 
75 // UniqueTid is an offset into |unique_threads_|. Necessary because tids can
76 // be reused.
77 using UniqueTid = uint32_t;
78 
79 // StringId is an offset into |string_pool_|.
80 using StringId = StringPool::Id;
81 static const StringId kNullStringId = StringId::Null();
82 
83 using ArgSetId = uint32_t;
84 static const ArgSetId kInvalidArgSetId = 0;
85 
86 using TrackId = tables::TrackTable::Id;
87 
88 using CounterId = tables::CounterTable::Id;
89 
90 using SliceId = tables::SliceTable::Id;
91 
92 using SchedId = tables::SchedSliceTable::Id;
93 
94 using MappingId = tables::StackProfileMappingTable::Id;
95 
96 using FrameId = tables::StackProfileFrameTable::Id;
97 
98 using SymbolId = tables::SymbolTable::Id;
99 
100 using CallsiteId = tables::StackProfileCallsiteTable::Id;
101 
102 using MetadataId = tables::MetadataTable::Id;
103 
104 using RawId = tables::RawTable::Id;
105 
106 using FlamegraphId = tables::ExperimentalFlamegraphTable::Id;
107 
108 using VulkanAllocId = tables::VulkanMemoryAllocationsTable::Id;
109 
110 using ProcessMemorySnapshotId = tables::ProcessMemorySnapshotTable::Id;
111 
112 using SnapshotNodeId = tables::MemorySnapshotNodeTable::Id;
113 
114 static const TrackId kInvalidTrackId =
115     TrackId(std::numeric_limits<uint32_t>::max());
116 
117 enum class RefType {
118   kRefNoRef = 0,
119   kRefUtid = 1,
120   kRefCpuId = 2,
121   kRefIrq = 3,
122   kRefSoftIrq = 4,
123   kRefUpid = 5,
124   kRefGpuId = 6,
125   kRefTrack = 7,
126   kRefMax
127 };
128 
129 const std::vector<NullTermStringView>& GetRefTypeStringMap();
130 
131 // Stores a data inside a trace file in a columnar form. This makes it efficient
132 // to read or search across a single field of the trace (e.g. all the thread
133 // names for a given CPU).
134 class TraceStorage {
135  public:
136   explicit TraceStorage(const Config& = Config());
137 
138   virtual ~TraceStorage();
139 
140   class VirtualTrackSlices {
141    public:
AddVirtualTrackSlice(SliceId slice_id,int64_t thread_timestamp_ns,int64_t thread_duration_ns,int64_t thread_instruction_count,int64_t thread_instruction_delta)142     inline uint32_t AddVirtualTrackSlice(SliceId slice_id,
143                                          int64_t thread_timestamp_ns,
144                                          int64_t thread_duration_ns,
145                                          int64_t thread_instruction_count,
146                                          int64_t thread_instruction_delta) {
147       slice_ids_.emplace_back(slice_id);
148       thread_timestamp_ns_.emplace_back(thread_timestamp_ns);
149       thread_duration_ns_.emplace_back(thread_duration_ns);
150       thread_instruction_counts_.emplace_back(thread_instruction_count);
151       thread_instruction_deltas_.emplace_back(thread_instruction_delta);
152       return slice_count() - 1;
153     }
154 
slice_count()155     uint32_t slice_count() const {
156       return static_cast<uint32_t>(slice_ids_.size());
157     }
158 
slice_ids()159     const std::deque<SliceId>& slice_ids() const { return slice_ids_; }
thread_timestamp_ns()160     const std::deque<int64_t>& thread_timestamp_ns() const {
161       return thread_timestamp_ns_;
162     }
thread_duration_ns()163     const std::deque<int64_t>& thread_duration_ns() const {
164       return thread_duration_ns_;
165     }
thread_instruction_counts()166     const std::deque<int64_t>& thread_instruction_counts() const {
167       return thread_instruction_counts_;
168     }
thread_instruction_deltas()169     const std::deque<int64_t>& thread_instruction_deltas() const {
170       return thread_instruction_deltas_;
171     }
172 
FindRowForSliceId(SliceId slice_id)173     std::optional<uint32_t> FindRowForSliceId(SliceId slice_id) const {
174       auto it =
175           std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
176       if (it != slice_ids().end() && *it == slice_id) {
177         return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
178       }
179       return std::nullopt;
180     }
181 
UpdateThreadDeltasForSliceId(SliceId slice_id,int64_t end_thread_timestamp_ns,int64_t end_thread_instruction_count)182     void UpdateThreadDeltasForSliceId(SliceId slice_id,
183                                       int64_t end_thread_timestamp_ns,
184                                       int64_t end_thread_instruction_count) {
185       auto opt_row = FindRowForSliceId(slice_id);
186       if (!opt_row)
187         return;
188       uint32_t row = *opt_row;
189       int64_t begin_ns = thread_timestamp_ns_[row];
190       thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns;
191       int64_t begin_ticount = thread_instruction_counts_[row];
192       thread_instruction_deltas_[row] =
193           end_thread_instruction_count - begin_ticount;
194     }
195 
196    private:
197     std::deque<SliceId> slice_ids_;
198     std::deque<int64_t> thread_timestamp_ns_;
199     std::deque<int64_t> thread_duration_ns_;
200     std::deque<int64_t> thread_instruction_counts_;
201     std::deque<int64_t> thread_instruction_deltas_;
202   };
203 
204   class SqlStats {
205    public:
206     static constexpr size_t kMaxLogEntries = 100;
207     uint32_t RecordQueryBegin(const std::string& query, int64_t time_started);
208     void RecordQueryFirstNext(uint32_t row, int64_t time_first_next);
209     void RecordQueryEnd(uint32_t row, int64_t time_end);
size()210     size_t size() const { return queries_.size(); }
queries()211     const std::deque<std::string>& queries() const { return queries_; }
times_started()212     const std::deque<int64_t>& times_started() const { return times_started_; }
times_first_next()213     const std::deque<int64_t>& times_first_next() const {
214       return times_first_next_;
215     }
times_ended()216     const std::deque<int64_t>& times_ended() const { return times_ended_; }
217 
218    private:
219     uint32_t popped_queries_ = 0;
220 
221     std::deque<std::string> queries_;
222     std::deque<int64_t> times_started_;
223     std::deque<int64_t> times_first_next_;
224     std::deque<int64_t> times_ended_;
225   };
226 
227   struct Stats {
228     using IndexMap = std::map<int, int64_t>;
229     int64_t value = 0;
230     IndexMap indexed_values;
231   };
232   using StatsMap = std::array<Stats, stats::kNumKeys>;
233 
234   // Return an unqiue identifier for the contents of each string.
235   // The string is copied internally and can be destroyed after this called.
236   // Virtual for testing.
InternString(base::StringView str)237   virtual StringId InternString(base::StringView str) {
238     return string_pool_.InternString(str);
239   }
InternString(const char * str)240   virtual StringId InternString(const char* str) {
241     return InternString(base::StringView(str));
242   }
InternString(const std::string & str)243   virtual StringId InternString(const std::string& str) {
244     return InternString(base::StringView(str));
245   }
InternString(std::string_view str)246   virtual StringId InternString(std::string_view str) {
247     return InternString(base::StringView(str.data(), str.size()));
248   }
249 
250   // Example usage: SetStats(stats::android_log_num_failed, 42);
SetStats(size_t key,int64_t value)251   void SetStats(size_t key, int64_t value) {
252     PERFETTO_DCHECK(key < stats::kNumKeys);
253     PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
254     stats_[key].value = value;
255   }
256 
257   // Example usage: IncrementStats(stats::android_log_num_failed, -1);
258   void IncrementStats(size_t key, int64_t increment = 1) {
259     PERFETTO_DCHECK(key < stats::kNumKeys);
260     PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
261     stats_[key].value += increment;
262   }
263 
264   // Example usage: IncrementIndexedStats(stats::cpu_failure, 1);
265   void IncrementIndexedStats(size_t key, int index, int64_t increment = 1) {
266     PERFETTO_DCHECK(key < stats::kNumKeys);
267     PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
268     stats_[key].indexed_values[index] += increment;
269   }
270 
271   // Example usage: SetIndexedStats(stats::cpu_failure, 1, 42);
SetIndexedStats(size_t key,int index,int64_t value)272   void SetIndexedStats(size_t key, int index, int64_t value) {
273     PERFETTO_DCHECK(key < stats::kNumKeys);
274     PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
275     stats_[key].indexed_values[index] = value;
276   }
277 
278   // Example usage: opt_cpu_failure = GetIndexedStats(stats::cpu_failure, 1);
GetIndexedStats(size_t key,int index)279   std::optional<int64_t> GetIndexedStats(size_t key, int index) {
280     PERFETTO_DCHECK(key < stats::kNumKeys);
281     PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
282     auto kv = stats_[key].indexed_values.find(index);
283     if (kv != stats_[key].indexed_values.end()) {
284       return kv->second;
285     }
286     return std::nullopt;
287   }
288 
GetStats(size_t key)289   int64_t GetStats(size_t key) {
290     PERFETTO_DCHECK(key < stats::kNumKeys);
291     PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
292     return stats_[key].value;
293   }
294 
295   class ScopedStatsTracer {
296    public:
ScopedStatsTracer(TraceStorage * storage,size_t key)297     ScopedStatsTracer(TraceStorage* storage, size_t key)
298         : storage_(storage), key_(key), start_ns_(base::GetWallTimeNs()) {}
299 
~ScopedStatsTracer()300     ~ScopedStatsTracer() {
301       if (!storage_)
302         return;
303       auto delta_ns = base::GetWallTimeNs() - start_ns_;
304       storage_->IncrementStats(key_, delta_ns.count());
305     }
306 
ScopedStatsTracer(ScopedStatsTracer && other)307     ScopedStatsTracer(ScopedStatsTracer&& other) noexcept { MoveImpl(&other); }
308 
309     ScopedStatsTracer& operator=(ScopedStatsTracer&& other) {
310       MoveImpl(&other);
311       return *this;
312     }
313 
314    private:
315     ScopedStatsTracer(const ScopedStatsTracer&) = delete;
316     ScopedStatsTracer& operator=(const ScopedStatsTracer&) = delete;
317 
MoveImpl(ScopedStatsTracer * other)318     void MoveImpl(ScopedStatsTracer* other) {
319       storage_ = other->storage_;
320       key_ = other->key_;
321       start_ns_ = other->start_ns_;
322       other->storage_ = nullptr;
323     }
324 
325     TraceStorage* storage_;
326     size_t key_;
327     base::TimeNanos start_ns_;
328   };
329 
TraceExecutionTimeIntoStats(size_t key)330   ScopedStatsTracer TraceExecutionTimeIntoStats(size_t key) {
331     return ScopedStatsTracer(this, key);
332   }
333 
334   // Reading methods.
335   // Virtual for testing.
GetString(StringId id)336   virtual NullTermStringView GetString(StringId id) const {
337     return string_pool_.Get(id);
338   }
339 
340   // Requests the removal of unused capacity.
341   // Matches the semantics of std::vector::shrink_to_fit.
ShrinkToFitTables()342   void ShrinkToFitTables() {
343     // At the moment, we only bother calling ShrinkToFit on a set group
344     // of tables. If we wanted to extend this to every table, we'd need to deal
345     // with tracking all the tables in the storage: this is not worth doing
346     // given most memory is used by these tables.
347     thread_table_.ShrinkToFit();
348     process_table_.ShrinkToFit();
349     track_table_.ShrinkToFit();
350     counter_table_.ShrinkToFit();
351     slice_table_.ShrinkToFit();
352     raw_table_.ShrinkToFit();
353     sched_slice_table_.ShrinkToFit();
354     thread_state_table_.ShrinkToFit();
355     arg_table_.ShrinkToFit();
356     heap_graph_object_table_.ShrinkToFit();
357     heap_graph_reference_table_.ShrinkToFit();
358   }
359 
thread_table()360   const tables::ThreadTable& thread_table() const { return thread_table_; }
mutable_thread_table()361   tables::ThreadTable* mutable_thread_table() { return &thread_table_; }
362 
process_table()363   const tables::ProcessTable& process_table() const { return process_table_; }
mutable_process_table()364   tables::ProcessTable* mutable_process_table() { return &process_table_; }
365 
filedescriptor_table()366   const tables::FiledescriptorTable& filedescriptor_table() const {
367     return filedescriptor_table_;
368   }
mutable_filedescriptor_table()369   tables::FiledescriptorTable* mutable_filedescriptor_table() {
370     return &filedescriptor_table_;
371   }
372 
track_table()373   const tables::TrackTable& track_table() const { return track_table_; }
mutable_track_table()374   tables::TrackTable* mutable_track_table() { return &track_table_; }
375 
gpu_counter_group_table()376   const tables::GpuCounterGroupTable& gpu_counter_group_table() const {
377     return gpu_counter_group_table_;
378   }
mutable_gpu_counter_group_table()379   tables::GpuCounterGroupTable* mutable_gpu_counter_group_table() {
380     return &gpu_counter_group_table_;
381   }
382 
process_track_table()383   const tables::ProcessTrackTable& process_track_table() const {
384     return process_track_table_;
385   }
mutable_process_track_table()386   tables::ProcessTrackTable* mutable_process_track_table() {
387     return &process_track_table_;
388   }
389 
thread_track_table()390   const tables::ThreadTrackTable& thread_track_table() const {
391     return thread_track_table_;
392   }
mutable_thread_track_table()393   tables::ThreadTrackTable* mutable_thread_track_table() {
394     return &thread_track_table_;
395   }
396 
thread_state_table()397   const tables::ThreadStateTable& thread_state_table() const {
398     return thread_state_table_;
399   }
mutable_thread_state_table()400   tables::ThreadStateTable* mutable_thread_state_table() {
401     return &thread_state_table_;
402   }
403 
sched_slice_table()404   const tables::SchedSliceTable& sched_slice_table() const {
405     return sched_slice_table_;
406   }
mutable_sched_slice_table()407   tables::SchedSliceTable* mutable_sched_slice_table() {
408     return &sched_slice_table_;
409   }
410 
slice_table()411   const tables::SliceTable& slice_table() const { return slice_table_; }
mutable_slice_table()412   tables::SliceTable* mutable_slice_table() { return &slice_table_; }
413 
spurious_sched_wakeup_table()414   const tables::SpuriousSchedWakeupTable& spurious_sched_wakeup_table() const {
415     return spurious_sched_wakeup_table_;
416   }
mutable_spurious_sched_wakeup_table()417   tables::SpuriousSchedWakeupTable* mutable_spurious_sched_wakeup_table() {
418     return &spurious_sched_wakeup_table_;
419   }
420 
flow_table()421   const tables::FlowTable& flow_table() const { return flow_table_; }
mutable_flow_table()422   tables::FlowTable* mutable_flow_table() { return &flow_table_; }
423 
virtual_track_slices()424   const VirtualTrackSlices& virtual_track_slices() const {
425     return virtual_track_slices_;
426   }
mutable_virtual_track_slices()427   VirtualTrackSlices* mutable_virtual_track_slices() {
428     return &virtual_track_slices_;
429   }
430 
gpu_slice_table()431   const tables::GpuSliceTable& gpu_slice_table() const {
432     return gpu_slice_table_;
433   }
mutable_gpu_slice_table()434   tables::GpuSliceTable* mutable_gpu_slice_table() { return &gpu_slice_table_; }
435 
counter_table()436   const tables::CounterTable& counter_table() const { return counter_table_; }
mutable_counter_table()437   tables::CounterTable* mutable_counter_table() { return &counter_table_; }
438 
sql_stats()439   const SqlStats& sql_stats() const { return sql_stats_; }
mutable_sql_stats()440   SqlStats* mutable_sql_stats() { return &sql_stats_; }
441 
android_log_table()442   const tables::AndroidLogTable& android_log_table() const {
443     return android_log_table_;
444   }
mutable_android_log_table()445   tables::AndroidLogTable* mutable_android_log_table() {
446     return &android_log_table_;
447   }
448 
android_dumpstate_table()449   const tables::AndroidDumpstateTable& android_dumpstate_table() const {
450     return android_dumpstate_table_;
451   }
452 
mutable_android_dumpstate_table()453   tables::AndroidDumpstateTable* mutable_android_dumpstate_table() {
454     return &android_dumpstate_table_;
455   }
456 
android_key_events_table()457   const tables::AndroidKeyEventsTable& android_key_events_table() const {
458     return android_key_events_table_;
459   }
mutable_android_key_events_table()460   tables::AndroidKeyEventsTable* mutable_android_key_events_table() {
461     return &android_key_events_table_;
462   }
463 
android_motion_events_table()464   const tables::AndroidMotionEventsTable& android_motion_events_table() const {
465     return android_motion_events_table_;
466   }
mutable_android_motion_events_table()467   tables::AndroidMotionEventsTable* mutable_android_motion_events_table() {
468     return &android_motion_events_table_;
469   }
470 
471   const tables::AndroidInputEventDispatchTable&
android_input_event_dispatch_table()472   android_input_event_dispatch_table() const {
473     return android_input_event_dispatch_table_;
474   }
475   tables::AndroidInputEventDispatchTable*
mutable_android_input_event_dispatch_table()476   mutable_android_input_event_dispatch_table() {
477     return &android_input_event_dispatch_table_;
478   }
479 
stats()480   const StatsMap& stats() const { return stats_; }
481 
metadata_table()482   const tables::MetadataTable& metadata_table() const {
483     return metadata_table_;
484   }
mutable_metadata_table()485   tables::MetadataTable* mutable_metadata_table() { return &metadata_table_; }
486 
clock_snapshot_table()487   const tables::ClockSnapshotTable& clock_snapshot_table() const {
488     return clock_snapshot_table_;
489   }
mutable_clock_snapshot_table()490   tables::ClockSnapshotTable* mutable_clock_snapshot_table() {
491     return &clock_snapshot_table_;
492   }
493 
arg_table()494   const tables::ArgTable& arg_table() const { return arg_table_; }
mutable_arg_table()495   tables::ArgTable* mutable_arg_table() { return &arg_table_; }
496 
raw_table()497   const tables::RawTable& raw_table() const { return raw_table_; }
mutable_raw_table()498   tables::RawTable* mutable_raw_table() { return &raw_table_; }
499 
ftrace_event_table()500   const tables::FtraceEventTable& ftrace_event_table() const {
501     return ftrace_event_table_;
502   }
mutable_ftrace_event_table()503   tables::FtraceEventTable* mutable_ftrace_event_table() {
504     return &ftrace_event_table_;
505   }
506 
machine_table()507   const tables::MachineTable& machine_table() const { return machine_table_; }
mutable_machine_table()508   tables::MachineTable* mutable_machine_table() { return &machine_table_; }
509 
cpu_table()510   const tables::CpuTable& cpu_table() const { return cpu_table_; }
mutable_cpu_table()511   tables::CpuTable* mutable_cpu_table() { return &cpu_table_; }
512 
cpu_freq_table()513   const tables::CpuFreqTable& cpu_freq_table() const { return cpu_freq_table_; }
mutable_cpu_freq_table()514   tables::CpuFreqTable* mutable_cpu_freq_table() { return &cpu_freq_table_; }
515 
stack_profile_mapping_table()516   const tables::StackProfileMappingTable& stack_profile_mapping_table() const {
517     return stack_profile_mapping_table_;
518   }
mutable_stack_profile_mapping_table()519   tables::StackProfileMappingTable* mutable_stack_profile_mapping_table() {
520     return &stack_profile_mapping_table_;
521   }
522 
stack_profile_frame_table()523   const tables::StackProfileFrameTable& stack_profile_frame_table() const {
524     return stack_profile_frame_table_;
525   }
mutable_stack_profile_frame_table()526   tables::StackProfileFrameTable* mutable_stack_profile_frame_table() {
527     return &stack_profile_frame_table_;
528   }
529 
stack_profile_callsite_table()530   const tables::StackProfileCallsiteTable& stack_profile_callsite_table()
531       const {
532     return stack_profile_callsite_table_;
533   }
mutable_stack_profile_callsite_table()534   tables::StackProfileCallsiteTable* mutable_stack_profile_callsite_table() {
535     return &stack_profile_callsite_table_;
536   }
537 
heap_profile_allocation_table()538   const tables::HeapProfileAllocationTable& heap_profile_allocation_table()
539       const {
540     return heap_profile_allocation_table_;
541   }
mutable_heap_profile_allocation_table()542   tables::HeapProfileAllocationTable* mutable_heap_profile_allocation_table() {
543     return &heap_profile_allocation_table_;
544   }
545 
package_list_table()546   const tables::PackageListTable& package_list_table() const {
547     return package_list_table_;
548   }
mutable_package_list_table()549   tables::PackageListTable* mutable_package_list_table() {
550     return &package_list_table_;
551   }
552 
553   const tables::AndroidGameInterventionListTable&
android_game_intervention_list_table()554   android_game_intervention_list_table() const {
555     return android_game_intervention_list_table_;
556   }
557   tables::AndroidGameInterventionListTable*
mutable_android_game_intervenion_list_table()558   mutable_android_game_intervenion_list_table() {
559     return &android_game_intervention_list_table_;
560   }
561 
profiler_smaps_table()562   const tables::ProfilerSmapsTable& profiler_smaps_table() const {
563     return profiler_smaps_table_;
564   }
mutable_profiler_smaps_table()565   tables::ProfilerSmapsTable* mutable_profiler_smaps_table() {
566     return &profiler_smaps_table_;
567   }
568 
trace_file_table()569   const tables::TraceFileTable& trace_file_table() const {
570     return trace_file_table_;
571   }
mutable_trace_file_table()572   tables::TraceFileTable* mutable_trace_file_table() {
573     return &trace_file_table_;
574   }
575 
cpu_profile_stack_sample_table()576   const tables::CpuProfileStackSampleTable& cpu_profile_stack_sample_table()
577       const {
578     return cpu_profile_stack_sample_table_;
579   }
mutable_cpu_profile_stack_sample_table()580   tables::CpuProfileStackSampleTable* mutable_cpu_profile_stack_sample_table() {
581     return &cpu_profile_stack_sample_table_;
582   }
583 
perf_session_table()584   const tables::PerfSessionTable& perf_session_table() const {
585     return perf_session_table_;
586   }
mutable_perf_session_table()587   tables::PerfSessionTable* mutable_perf_session_table() {
588     return &perf_session_table_;
589   }
590 
perf_sample_table()591   const tables::PerfSampleTable& perf_sample_table() const {
592     return perf_sample_table_;
593   }
mutable_perf_sample_table()594   tables::PerfSampleTable* mutable_perf_sample_table() {
595     return &perf_sample_table_;
596   }
597 
instruments_sample_table()598   const tables::InstrumentsSampleTable& instruments_sample_table() const {
599     return instruments_sample_table_;
600   }
mutable_instruments_sample_table()601   tables::InstrumentsSampleTable* mutable_instruments_sample_table() {
602     return &instruments_sample_table_;
603   }
604 
symbol_table()605   const tables::SymbolTable& symbol_table() const { return symbol_table_; }
606 
mutable_symbol_table()607   tables::SymbolTable* mutable_symbol_table() { return &symbol_table_; }
608 
heap_graph_object_table()609   const tables::HeapGraphObjectTable& heap_graph_object_table() const {
610     return heap_graph_object_table_;
611   }
612 
mutable_heap_graph_object_table()613   tables::HeapGraphObjectTable* mutable_heap_graph_object_table() {
614     return &heap_graph_object_table_;
615   }
heap_graph_class_table()616   const tables::HeapGraphClassTable& heap_graph_class_table() const {
617     return heap_graph_class_table_;
618   }
619 
mutable_heap_graph_class_table()620   tables::HeapGraphClassTable* mutable_heap_graph_class_table() {
621     return &heap_graph_class_table_;
622   }
623 
heap_graph_reference_table()624   const tables::HeapGraphReferenceTable& heap_graph_reference_table() const {
625     return heap_graph_reference_table_;
626   }
627 
mutable_heap_graph_reference_table()628   tables::HeapGraphReferenceTable* mutable_heap_graph_reference_table() {
629     return &heap_graph_reference_table_;
630   }
631 
cpu_track_table()632   const tables::CpuTrackTable& cpu_track_table() const {
633     return cpu_track_table_;
634   }
mutable_cpu_track_table()635   tables::CpuTrackTable* mutable_cpu_track_table() { return &cpu_track_table_; }
636 
gpu_track_table()637   const tables::GpuTrackTable& gpu_track_table() const {
638     return gpu_track_table_;
639   }
mutable_gpu_track_table()640   tables::GpuTrackTable* mutable_gpu_track_table() { return &gpu_track_table_; }
641 
vulkan_memory_allocations_table()642   const tables::VulkanMemoryAllocationsTable& vulkan_memory_allocations_table()
643       const {
644     return vulkan_memory_allocations_table_;
645   }
646 
647   tables::VulkanMemoryAllocationsTable*
mutable_vulkan_memory_allocations_table()648   mutable_vulkan_memory_allocations_table() {
649     return &vulkan_memory_allocations_table_;
650   }
651 
graphics_frame_slice_table()652   const tables::GraphicsFrameSliceTable& graphics_frame_slice_table() const {
653     return graphics_frame_slice_table_;
654   }
655 
mutable_graphics_frame_slice_table()656   tables::GraphicsFrameSliceTable* mutable_graphics_frame_slice_table() {
657     return &graphics_frame_slice_table_;
658   }
659 
memory_snapshot_table()660   const tables::MemorySnapshotTable& memory_snapshot_table() const {
661     return memory_snapshot_table_;
662   }
mutable_memory_snapshot_table()663   tables::MemorySnapshotTable* mutable_memory_snapshot_table() {
664     return &memory_snapshot_table_;
665   }
666 
process_memory_snapshot_table()667   const tables::ProcessMemorySnapshotTable& process_memory_snapshot_table()
668       const {
669     return process_memory_snapshot_table_;
670   }
mutable_process_memory_snapshot_table()671   tables::ProcessMemorySnapshotTable* mutable_process_memory_snapshot_table() {
672     return &process_memory_snapshot_table_;
673   }
674 
memory_snapshot_node_table()675   const tables::MemorySnapshotNodeTable& memory_snapshot_node_table() const {
676     return memory_snapshot_node_table_;
677   }
mutable_memory_snapshot_node_table()678   tables::MemorySnapshotNodeTable* mutable_memory_snapshot_node_table() {
679     return &memory_snapshot_node_table_;
680   }
681 
memory_snapshot_edge_table()682   const tables::MemorySnapshotEdgeTable& memory_snapshot_edge_table() const {
683     return memory_snapshot_edge_table_;
684   }
mutable_memory_snapshot_edge_table()685   tables::MemorySnapshotEdgeTable* mutable_memory_snapshot_edge_table() {
686     return &memory_snapshot_edge_table_;
687   }
688 
689   const tables::ExpectedFrameTimelineSliceTable&
expected_frame_timeline_slice_table()690   expected_frame_timeline_slice_table() const {
691     return expected_frame_timeline_slice_table_;
692   }
693 
694   tables::ExpectedFrameTimelineSliceTable*
mutable_expected_frame_timeline_slice_table()695   mutable_expected_frame_timeline_slice_table() {
696     return &expected_frame_timeline_slice_table_;
697   }
698 
699   const tables::ActualFrameTimelineSliceTable&
actual_frame_timeline_slice_table()700   actual_frame_timeline_slice_table() const {
701     return actual_frame_timeline_slice_table_;
702   }
703   tables::ActualFrameTimelineSliceTable*
mutable_actual_frame_timeline_slice_table()704   mutable_actual_frame_timeline_slice_table() {
705     return &actual_frame_timeline_slice_table_;
706   }
707 
android_network_packets_table()708   const tables::AndroidNetworkPacketsTable& android_network_packets_table()
709       const {
710     return android_network_packets_table_;
711   }
mutable_android_network_packets_table()712   tables::AndroidNetworkPacketsTable* mutable_android_network_packets_table() {
713     return &android_network_packets_table_;
714   }
715 
v8_isolate_table()716   const tables::V8IsolateTable& v8_isolate_table() const {
717     return v8_isolate_table_;
718   }
mutable_v8_isolate_table()719   tables::V8IsolateTable* mutable_v8_isolate_table() {
720     return &v8_isolate_table_;
721   }
v8_js_script_table()722   const tables::V8JsScriptTable& v8_js_script_table() const {
723     return v8_js_script_table_;
724   }
mutable_v8_js_script_table()725   tables::V8JsScriptTable* mutable_v8_js_script_table() {
726     return &v8_js_script_table_;
727   }
v8_wasm_script_table()728   const tables::V8WasmScriptTable& v8_wasm_script_table() const {
729     return v8_wasm_script_table_;
730   }
mutable_v8_wasm_script_table()731   tables::V8WasmScriptTable* mutable_v8_wasm_script_table() {
732     return &v8_wasm_script_table_;
733   }
v8_js_function_table()734   const tables::V8JsFunctionTable& v8_js_function_table() const {
735     return v8_js_function_table_;
736   }
mutable_v8_js_function_table()737   tables::V8JsFunctionTable* mutable_v8_js_function_table() {
738     return &v8_js_function_table_;
739   }
v8_js_code_table()740   const tables::V8JsCodeTable& v8_js_code_table() const {
741     return v8_js_code_table_;
742   }
mutable_v8_js_code_table()743   tables::V8JsCodeTable* mutable_v8_js_code_table() {
744     return &v8_js_code_table_;
745   }
v8_internal_code_table()746   const tables::V8InternalCodeTable& v8_internal_code_table() const {
747     return v8_internal_code_table_;
748   }
mutable_v8_internal_code_table()749   tables::V8InternalCodeTable* mutable_v8_internal_code_table() {
750     return &v8_internal_code_table_;
751   }
v8_wasm_code_table()752   const tables::V8WasmCodeTable& v8_wasm_code_table() const {
753     return v8_wasm_code_table_;
754   }
mutable_v8_wasm_code_table()755   tables::V8WasmCodeTable* mutable_v8_wasm_code_table() {
756     return &v8_wasm_code_table_;
757   }
v8_regexp_code_table()758   const tables::V8RegexpCodeTable& v8_regexp_code_table() const {
759     return v8_regexp_code_table_;
760   }
mutable_v8_regexp_code_table()761   tables::V8RegexpCodeTable* mutable_v8_regexp_code_table() {
762     return &v8_regexp_code_table_;
763   }
764 
etm_v4_configuration_table()765   const tables::EtmV4ConfigurationTable& etm_v4_configuration_table() const {
766     return etm_v4_configuration_table_;
767   }
mutable_etm_v4_configuration_table()768   tables::EtmV4ConfigurationTable* mutable_etm_v4_configuration_table() {
769     return &etm_v4_configuration_table_;
770   }
etm_v4_configuration_data()771   const std::vector<std::unique_ptr<Destructible>>& etm_v4_configuration_data()
772       const {
773     return etm_v4_configuration_data_;
774   }
775   std::vector<std::unique_ptr<Destructible>>*
mutable_etm_v4_configuration_data()776   mutable_etm_v4_configuration_data() {
777     return &etm_v4_configuration_data_;
778   }
etm_v4_session_table()779   const tables::EtmV4SessionTable& etm_v4_session_table() const {
780     return etm_v4_session_table_;
781   }
mutable_etm_v4_session_table()782   tables::EtmV4SessionTable* mutable_etm_v4_session_table() {
783     return &etm_v4_session_table_;
784   }
etm_v4_trace_table()785   const tables::EtmV4TraceTable& etm_v4_trace_table() const {
786     return etm_v4_trace_table_;
787   }
mutable_etm_v4_trace_table()788   tables::EtmV4TraceTable* mutable_etm_v4_trace_table() {
789     return &etm_v4_trace_table_;
790   }
etm_v4_trace_data()791   const std::vector<TraceBlobView>& etm_v4_trace_data() const {
792     return etm_v4_trace_data_;
793   }
mutable_etm_v4_trace_data()794   std::vector<TraceBlobView>* mutable_etm_v4_trace_data() {
795     return &etm_v4_trace_data_;
796   }
797 
jit_code_table()798   const tables::JitCodeTable& jit_code_table() const { return jit_code_table_; }
mutable_jit_code_table()799   tables::JitCodeTable* mutable_jit_code_table() { return &jit_code_table_; }
800 
jit_frame_table()801   const tables::JitFrameTable& jit_frame_table() const {
802     return jit_frame_table_;
803   }
mutable_jit_frame_table()804   tables::JitFrameTable* mutable_jit_frame_table() { return &jit_frame_table_; }
805 
mutable_mmap_record_table()806   tables::MmapRecordTable* mutable_mmap_record_table() {
807     return &mmap_record_table_;
808   }
mmap_record_table()809   const tables::MmapRecordTable& mmap_record_table() const {
810     return mmap_record_table_;
811   }
spe_record_table()812   const tables::SpeRecordTable& spe_record_table() const {
813     return spe_record_table_;
814   }
mutable_spe_record_table()815   tables::SpeRecordTable* mutable_spe_record_table() {
816     return &spe_record_table_;
817   }
818 
inputmethod_clients_table()819   const tables::InputMethodClientsTable& inputmethod_clients_table() const {
820     return inputmethod_clients_table_;
821   }
mutable_inputmethod_clients_table()822   tables::InputMethodClientsTable* mutable_inputmethod_clients_table() {
823     return &inputmethod_clients_table_;
824   }
825 
826   const tables::InputMethodManagerServiceTable&
inputmethod_manager_service_table()827   inputmethod_manager_service_table() const {
828     return inputmethod_manager_service_table_;
829   }
830   tables::InputMethodManagerServiceTable*
mutable_inputmethod_manager_service_table()831   mutable_inputmethod_manager_service_table() {
832     return &inputmethod_manager_service_table_;
833   }
834 
inputmethod_service_table()835   const tables::InputMethodServiceTable& inputmethod_service_table() const {
836     return inputmethod_service_table_;
837   }
mutable_inputmethod_service_table()838   tables::InputMethodServiceTable* mutable_inputmethod_service_table() {
839     return &inputmethod_service_table_;
840   }
841 
842   const tables::SurfaceFlingerLayersSnapshotTable&
surfaceflinger_layers_snapshot_table()843   surfaceflinger_layers_snapshot_table() const {
844     return surfaceflinger_layers_snapshot_table_;
845   }
846   tables::SurfaceFlingerLayersSnapshotTable*
mutable_surfaceflinger_layers_snapshot_table()847   mutable_surfaceflinger_layers_snapshot_table() {
848     return &surfaceflinger_layers_snapshot_table_;
849   }
850 
surfaceflinger_layer_table()851   const tables::SurfaceFlingerLayerTable& surfaceflinger_layer_table() const {
852     return surfaceflinger_layer_table_;
853   }
mutable_surfaceflinger_layer_table()854   tables::SurfaceFlingerLayerTable* mutable_surfaceflinger_layer_table() {
855     return &surfaceflinger_layer_table_;
856   }
857 
858   const tables::SurfaceFlingerTransactionsTable&
surfaceflinger_transactions_table()859   surfaceflinger_transactions_table() const {
860     return surfaceflinger_transactions_table_;
861   }
862   tables::SurfaceFlingerTransactionsTable*
mutable_surfaceflinger_transactions_table()863   mutable_surfaceflinger_transactions_table() {
864     return &surfaceflinger_transactions_table_;
865   }
866 
viewcapture_table()867   const tables::ViewCaptureTable& viewcapture_table() const {
868     return viewcapture_table_;
869   }
mutable_viewcapture_table()870   tables::ViewCaptureTable* mutable_viewcapture_table() {
871     return &viewcapture_table_;
872   }
873 
windowmanager_table()874   const tables::WindowManagerTable& windowmanager_table() const {
875     return windowmanager_table_;
876   }
mutable_windowmanager_table()877   tables::WindowManagerTable* mutable_windowmanager_table() {
878     return &windowmanager_table_;
879   }
880 
881   const tables::WindowManagerShellTransitionsTable&
window_manager_shell_transitions_table()882   window_manager_shell_transitions_table() const {
883     return window_manager_shell_transitions_table_;
884   }
885   tables::WindowManagerShellTransitionsTable*
mutable_window_manager_shell_transitions_table()886   mutable_window_manager_shell_transitions_table() {
887     return &window_manager_shell_transitions_table_;
888   }
889 
890   const tables::WindowManagerShellTransitionHandlersTable&
window_manager_shell_transition_handlers_table()891   window_manager_shell_transition_handlers_table() const {
892     return window_manager_shell_transition_handlers_table_;
893   }
894   tables::WindowManagerShellTransitionHandlersTable*
mutable_window_manager_shell_transition_handlers_table()895   mutable_window_manager_shell_transition_handlers_table() {
896     return &window_manager_shell_transition_handlers_table_;
897   }
898 
protolog_table()899   const tables::ProtoLogTable& protolog_table() const {
900     return protolog_table_;
901   }
mutable_protolog_table()902   tables::ProtoLogTable* mutable_protolog_table() { return &protolog_table_; }
903 
experimental_proto_path_table()904   const tables::ExperimentalProtoPathTable& experimental_proto_path_table()
905       const {
906     return experimental_proto_path_table_;
907   }
mutable_experimental_proto_path_table()908   tables::ExperimentalProtoPathTable* mutable_experimental_proto_path_table() {
909     return &experimental_proto_path_table_;
910   }
911 
912   const tables::ExperimentalProtoContentTable&
experimental_proto_content_table()913   experimental_proto_content_table() const {
914     return experimental_proto_content_table_;
915   }
916   tables::ExperimentalProtoContentTable*
mutable_experimental_proto_content_table()917   mutable_experimental_proto_content_table() {
918     return &experimental_proto_content_table_;
919   }
920 
921   const tables::ExpMissingChromeProcTable&
experimental_missing_chrome_processes_table()922   experimental_missing_chrome_processes_table() const {
923     return experimental_missing_chrome_processes_table_;
924   }
925   tables::ExpMissingChromeProcTable*
mutable_experimental_missing_chrome_processes_table()926   mutable_experimental_missing_chrome_processes_table() {
927     return &experimental_missing_chrome_processes_table_;
928   }
929 
string_pool()930   const StringPool& string_pool() const { return string_pool_; }
mutable_string_pool()931   StringPool* mutable_string_pool() { return &string_pool_; }
932 
933   // Number of interned strings in the pool. Includes the empty string w/ ID=0.
string_count()934   size_t string_count() const { return string_pool_.size(); }
935 
ExtractArg(uint32_t arg_set_id,const char * key,std::optional<Variadic> * result)936   base::Status ExtractArg(uint32_t arg_set_id,
937                           const char* key,
938                           std::optional<Variadic>* result) const {
939     const auto& args = arg_table();
940     Query q;
941     q.constraints = {args.arg_set_id().eq(arg_set_id), args.key().eq(key)};
942     auto it = args.FilterToIterator(q);
943     if (!it) {
944       *result = std::nullopt;
945       return base::OkStatus();
946     }
947     *result = GetArgValue(it.row_number().row_number());
948     if (++it) {
949       return base::ErrStatus(
950           "EXTRACT_ARG: received multiple args matching arg set id and key");
951     }
952     return base::OkStatus();
953   }
954 
GetArgValue(uint32_t row)955   Variadic GetArgValue(uint32_t row) const {
956     auto rr = arg_table_[row];
957 
958     Variadic v = Variadic::Null();
959     v.type = *GetVariadicTypeForId(rr.value_type());
960     switch (v.type) {
961       case Variadic::Type::kBool:
962         v.bool_value = static_cast<bool>(*rr.int_value());
963         break;
964       case Variadic::Type::kInt:
965         v.int_value = *rr.int_value();
966         break;
967       case Variadic::Type::kUint:
968         v.uint_value = static_cast<uint64_t>(*rr.int_value());
969         break;
970       case Variadic::Type::kString: {
971         auto opt_value = rr.string_value();
972         v.string_value = opt_value ? *opt_value : kNullStringId;
973         break;
974       }
975       case Variadic::Type::kPointer:
976         v.pointer_value = static_cast<uint64_t>(*rr.int_value());
977         break;
978       case Variadic::Type::kReal:
979         v.real_value = *rr.real_value();
980         break;
981       case Variadic::Type::kJson: {
982         auto opt_value = rr.string_value();
983         v.json_value = opt_value ? *opt_value : kNullStringId;
984         break;
985       }
986       case Variadic::Type::kNull:
987         break;
988     }
989     return v;
990   }
991 
GetIdForVariadicType(Variadic::Type type)992   StringId GetIdForVariadicType(Variadic::Type type) const {
993     return variadic_type_ids_[type];
994   }
995 
GetVariadicTypeForId(StringId id)996   std::optional<Variadic::Type> GetVariadicTypeForId(StringId id) const {
997     auto it =
998         std::find(variadic_type_ids_.begin(), variadic_type_ids_.end(), id);
999     if (it == variadic_type_ids_.end())
1000       return std::nullopt;
1001 
1002     int64_t idx = std::distance(variadic_type_ids_.begin(), it);
1003     return static_cast<Variadic::Type>(idx);
1004   }
1005 
1006  private:
1007   using StringHash = uint64_t;
1008 
1009   TraceStorage(const TraceStorage&) = delete;
1010   TraceStorage& operator=(const TraceStorage&) = delete;
1011 
1012   TraceStorage(TraceStorage&&) = delete;
1013   TraceStorage& operator=(TraceStorage&&) = delete;
1014 
1015   friend etm::TargetMemory;
etm_target_memory()1016   Destructible* etm_target_memory() { return etm_target_memory_.get(); }
set_etm_target_memory(std::unique_ptr<Destructible> target_memory)1017   void set_etm_target_memory(std::unique_ptr<Destructible> target_memory) {
1018     etm_target_memory_ = std::move(target_memory);
1019   }
1020 
1021   // One entry for each unique string in the trace.
1022   StringPool string_pool_;
1023 
1024   // Stats about parsing the trace.
1025   StatsMap stats_{};
1026 
1027   // Extra data extracted from the trace. Includes:
1028   // * metadata from chrome and benchmarking infrastructure
1029   // * descriptions of android packages
1030   tables::MetadataTable metadata_table_{&string_pool_};
1031 
1032   // Contains data from all the clock snapshots in the trace.
1033   tables::ClockSnapshotTable clock_snapshot_table_{&string_pool_};
1034 
1035   // Metadata for tracks.
1036   tables::TrackTable track_table_{&string_pool_};
1037   tables::ThreadStateTable thread_state_table_{&string_pool_};
1038   tables::CpuTrackTable cpu_track_table_{&string_pool_, &track_table_};
1039   tables::GpuTrackTable gpu_track_table_{&string_pool_, &track_table_};
1040   tables::ProcessTrackTable process_track_table_{&string_pool_, &track_table_};
1041   tables::ThreadTrackTable thread_track_table_{&string_pool_, &track_table_};
1042 
1043   // Track tables for counter events.
1044   tables::GpuCounterGroupTable gpu_counter_group_table_{&string_pool_};
1045 
1046   // Args for all other tables.
1047   tables::ArgTable arg_table_{&string_pool_};
1048 
1049   // Information about all the threads and processes in the trace.
1050   tables::ThreadTable thread_table_{&string_pool_};
1051   tables::ProcessTable process_table_{&string_pool_};
1052   tables::FiledescriptorTable filedescriptor_table_{&string_pool_};
1053 
1054   // Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros).
1055   tables::SliceTable slice_table_{&string_pool_};
1056 
1057   // Flow events from userspace events (e.g. Chromium TRACE_EVENT macros).
1058   tables::FlowTable flow_table_{&string_pool_};
1059 
1060   // Slices from CPU scheduling data.
1061   tables::SchedSliceTable sched_slice_table_{&string_pool_};
1062 
1063   tables::SpuriousSchedWakeupTable spurious_sched_wakeup_table_{&string_pool_};
1064 
1065   // Additional attributes for virtual track slices (sub-type of
1066   // NestableSlices).
1067   VirtualTrackSlices virtual_track_slices_;
1068 
1069   // Additional attributes for gpu track slices (sub-type of
1070   // NestableSlices).
1071   tables::GpuSliceTable gpu_slice_table_{&string_pool_, &slice_table_};
1072 
1073   // The values from the Counter events from the trace. This includes CPU
1074   // frequency events as well systrace trace_marker counter events.
1075   tables::CounterTable counter_table_{&string_pool_};
1076 
1077   SqlStats sql_stats_;
1078 
1079   tables::RawTable raw_table_{&string_pool_};
1080   tables::FtraceEventTable ftrace_event_table_{&string_pool_, &raw_table_};
1081 
1082   tables::MachineTable machine_table_{&string_pool_};
1083 
1084   tables::CpuTable cpu_table_{&string_pool_};
1085 
1086   tables::CpuFreqTable cpu_freq_table_{&string_pool_};
1087 
1088   tables::AndroidLogTable android_log_table_{&string_pool_};
1089 
1090   tables::AndroidDumpstateTable android_dumpstate_table_{&string_pool_};
1091 
1092   tables::AndroidKeyEventsTable android_key_events_table_{&string_pool_};
1093   tables::AndroidMotionEventsTable android_motion_events_table_{&string_pool_};
1094   tables::AndroidInputEventDispatchTable android_input_event_dispatch_table_{
1095       &string_pool_};
1096 
1097   tables::StackProfileMappingTable stack_profile_mapping_table_{&string_pool_};
1098   tables::StackProfileFrameTable stack_profile_frame_table_{&string_pool_};
1099   tables::StackProfileCallsiteTable stack_profile_callsite_table_{
1100       &string_pool_};
1101   tables::HeapProfileAllocationTable heap_profile_allocation_table_{
1102       &string_pool_};
1103   tables::CpuProfileStackSampleTable cpu_profile_stack_sample_table_{
1104       &string_pool_};
1105   tables::PerfSessionTable perf_session_table_{&string_pool_};
1106   tables::PerfSampleTable perf_sample_table_{&string_pool_};
1107   tables::InstrumentsSampleTable instruments_sample_table_{&string_pool_};
1108   tables::PackageListTable package_list_table_{&string_pool_};
1109   tables::AndroidGameInterventionListTable
1110       android_game_intervention_list_table_{&string_pool_};
1111   tables::ProfilerSmapsTable profiler_smaps_table_{&string_pool_};
1112 
1113   tables::TraceFileTable trace_file_table_{&string_pool_};
1114 
1115   // Symbol tables (mappings from frames to symbol names)
1116   tables::SymbolTable symbol_table_{&string_pool_};
1117   tables::HeapGraphObjectTable heap_graph_object_table_{&string_pool_};
1118   tables::HeapGraphClassTable heap_graph_class_table_{&string_pool_};
1119   tables::HeapGraphReferenceTable heap_graph_reference_table_{&string_pool_};
1120 
1121   tables::VulkanMemoryAllocationsTable vulkan_memory_allocations_table_{
1122       &string_pool_};
1123 
1124   tables::GraphicsFrameSliceTable graphics_frame_slice_table_{&string_pool_,
1125                                                               &slice_table_};
1126 
1127   // Metadata for memory snapshot.
1128   tables::MemorySnapshotTable memory_snapshot_table_{&string_pool_};
1129   tables::ProcessMemorySnapshotTable process_memory_snapshot_table_{
1130       &string_pool_};
1131   tables::MemorySnapshotNodeTable memory_snapshot_node_table_{&string_pool_};
1132   tables::MemorySnapshotEdgeTable memory_snapshot_edge_table_{&string_pool_};
1133 
1134   // FrameTimeline tables
1135   tables::ExpectedFrameTimelineSliceTable expected_frame_timeline_slice_table_{
1136       &string_pool_, &slice_table_};
1137   tables::ActualFrameTimelineSliceTable actual_frame_timeline_slice_table_{
1138       &string_pool_, &slice_table_};
1139 
1140   // AndroidNetworkPackets tables
1141   tables::AndroidNetworkPacketsTable android_network_packets_table_{
1142       &string_pool_, &slice_table_};
1143 
1144   // V8 tables
1145   tables::V8IsolateTable v8_isolate_table_{&string_pool_};
1146   tables::V8JsScriptTable v8_js_script_table_{&string_pool_};
1147   tables::V8WasmScriptTable v8_wasm_script_table_{&string_pool_};
1148   tables::V8JsFunctionTable v8_js_function_table_{&string_pool_};
1149   tables::V8JsCodeTable v8_js_code_table_{&string_pool_};
1150   tables::V8InternalCodeTable v8_internal_code_table_{&string_pool_};
1151   tables::V8WasmCodeTable v8_wasm_code_table_{&string_pool_};
1152   tables::V8RegexpCodeTable v8_regexp_code_table_{&string_pool_};
1153 
1154   // Jit tables
1155   tables::JitCodeTable jit_code_table_{&string_pool_};
1156   tables::JitFrameTable jit_frame_table_{&string_pool_};
1157 
1158   // ETM tables
1159   tables::EtmV4ConfigurationTable etm_v4_configuration_table_{&string_pool_};
1160   // Indexed by tables::EtmV4ConfigurationTable::Id
1161   std::vector<std::unique_ptr<Destructible>> etm_v4_configuration_data_;
1162   tables::EtmV4SessionTable etm_v4_session_table_{&string_pool_};
1163   tables::EtmV4TraceTable etm_v4_trace_table_{&string_pool_};
1164   // Indexed by tables::EtmV4TraceTable::Id
1165   std::vector<TraceBlobView> etm_v4_trace_data_;
1166   std::unique_ptr<Destructible> etm_target_memory_;
1167 
1168   // Perf tables
1169   tables::MmapRecordTable mmap_record_table_{&string_pool_};
1170   tables::SpeRecordTable spe_record_table_{&string_pool_};
1171 
1172   // Winscope tables
1173   tables::InputMethodClientsTable inputmethod_clients_table_{&string_pool_};
1174   tables::InputMethodManagerServiceTable inputmethod_manager_service_table_{
1175       &string_pool_};
1176   tables::InputMethodServiceTable inputmethod_service_table_{&string_pool_};
1177   tables::SurfaceFlingerLayersSnapshotTable
1178       surfaceflinger_layers_snapshot_table_{&string_pool_};
1179   tables::SurfaceFlingerLayerTable surfaceflinger_layer_table_{&string_pool_};
1180   tables::SurfaceFlingerTransactionsTable surfaceflinger_transactions_table_{
1181       &string_pool_};
1182   tables::ViewCaptureTable viewcapture_table_{&string_pool_};
1183   tables::WindowManagerTable windowmanager_table_{&string_pool_};
1184   tables::WindowManagerShellTransitionsTable
1185       window_manager_shell_transitions_table_{&string_pool_};
1186   tables::WindowManagerShellTransitionHandlersTable
1187       window_manager_shell_transition_handlers_table_{&string_pool_};
1188   tables::ProtoLogTable protolog_table_{&string_pool_};
1189 
1190   tables::ExperimentalProtoPathTable experimental_proto_path_table_{
1191       &string_pool_};
1192   tables::ExperimentalProtoContentTable experimental_proto_content_table_{
1193       &string_pool_};
1194 
1195   tables::ExpMissingChromeProcTable
1196       experimental_missing_chrome_processes_table_{&string_pool_};
1197 
1198   // The below array allow us to map between enums and their string
1199   // representations.
1200   std::array<StringId, Variadic::kMaxType + 1> variadic_type_ids_;
1201 };
1202 
1203 }  // namespace perfetto::trace_processor
1204 
1205 template <>
1206 struct std::hash<::perfetto::trace_processor::BaseId> {
1207   using argument_type = ::perfetto::trace_processor::BaseId;
1208   using result_type = size_t;
1209 
1210   result_type operator()(const argument_type& r) const {
1211     return std::hash<uint32_t>{}(r.value);
1212   }
1213 };
1214 
1215 template <>
1216 struct std::hash<::perfetto::trace_processor::TrackId>
1217     : std::hash<::perfetto::trace_processor::BaseId> {};
1218 template <>
1219 struct std::hash<::perfetto::trace_processor::MappingId>
1220     : std::hash<::perfetto::trace_processor::BaseId> {};
1221 template <>
1222 struct std::hash<::perfetto::trace_processor::CallsiteId>
1223     : std::hash<::perfetto::trace_processor::BaseId> {};
1224 template <>
1225 struct std::hash<::perfetto::trace_processor::FrameId>
1226     : std::hash<::perfetto::trace_processor::BaseId> {};
1227 template <>
1228 struct std::hash<::perfetto::trace_processor::tables::HeapGraphObjectTable::Id>
1229     : std::hash<::perfetto::trace_processor::BaseId> {};
1230 template <>
1231 struct std::hash<::perfetto::trace_processor::tables::V8IsolateTable::Id>
1232     : std::hash<::perfetto::trace_processor::BaseId> {};
1233 template <>
1234 struct std::hash<::perfetto::trace_processor::tables::JitCodeTable::Id>
1235     : std::hash<::perfetto::trace_processor::BaseId> {};
1236 
1237 template <>
1238 struct std::hash<
1239     ::perfetto::trace_processor::tables::StackProfileFrameTable::Row> {
1240   using argument_type =
1241       ::perfetto::trace_processor::tables::StackProfileFrameTable::Row;
1242   using result_type = size_t;
1243 
1244   result_type operator()(const argument_type& r) const {
1245     return std::hash<::perfetto::trace_processor::StringId>{}(r.name) ^
1246            std::hash<std::optional<::perfetto::trace_processor::MappingId>>{}(
1247                r.mapping) ^
1248            std::hash<int64_t>{}(r.rel_pc);
1249   }
1250 };
1251 
1252 template <>
1253 struct std::hash<
1254     ::perfetto::trace_processor::tables::StackProfileCallsiteTable::Row> {
1255   using argument_type =
1256       ::perfetto::trace_processor::tables::StackProfileCallsiteTable::Row;
1257   using result_type = size_t;
1258 
1259   result_type operator()(const argument_type& r) const {
1260     return std::hash<int64_t>{}(r.depth) ^
1261            std::hash<std::optional<::perfetto::trace_processor::CallsiteId>>{}(
1262                r.parent_id) ^
1263            std::hash<::perfetto::trace_processor::FrameId>{}(r.frame_id);
1264   }
1265 };
1266 
1267 template <>
1268 struct std::hash<
1269     ::perfetto::trace_processor::tables::StackProfileMappingTable::Row> {
1270   using argument_type =
1271       ::perfetto::trace_processor::tables::StackProfileMappingTable::Row;
1272   using result_type = size_t;
1273 
1274   result_type operator()(const argument_type& r) const {
1275     return std::hash<::perfetto::trace_processor::StringId>{}(r.build_id) ^
1276            std::hash<int64_t>{}(r.exact_offset) ^
1277            std::hash<int64_t>{}(r.start_offset) ^
1278            std::hash<int64_t>{}(r.start) ^ std::hash<int64_t>{}(r.end) ^
1279            std::hash<int64_t>{}(r.load_bias) ^
1280            std::hash<::perfetto::trace_processor::StringId>{}(r.name);
1281   }
1282 };
1283 
1284 #endif  // SRC_TRACE_PROCESSOR_STORAGE_TRACE_STORAGE_H_
1285