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