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