xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/instruments/row_data_tracker.cc (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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 #include "src/trace_processor/importers/instruments/row_data_tracker.h"
18 
19 #include "perfetto/base/status.h"
20 
21 #if !PERFETTO_BUILDFLAG(PERFETTO_TP_INSTRUMENTS)
22 #error \
23     "This file should not be built when enable_perfetto_trace_processor_mac_instruments=false"
24 #endif
25 
26 namespace perfetto::trace_processor::instruments_importer {
27 
RowDataTracker()28 RowDataTracker::RowDataTracker() {}
29 RowDataTracker::~RowDataTracker() = default;
30 
NewThread()31 IdPtr<Thread> RowDataTracker::NewThread() {
32   ThreadId id = static_cast<ThreadId>(threads_.size());
33   Thread* ptr = &threads_.emplace_back();
34   // Always add 1 to ids, so that they're non-zero.
35   return {id + 1, ptr};
36 }
GetThread(ThreadId id)37 Thread* RowDataTracker::GetThread(ThreadId id) {
38   PERFETTO_DCHECK(id != kNullId);
39   return &threads_[id - 1];
40 }
41 
NewProcess()42 IdPtr<Process> RowDataTracker::NewProcess() {
43   ProcessId id = static_cast<ProcessId>(processes_.size());
44   Process* ptr = &processes_.emplace_back();
45   // Always add 1 to ids, so that they're non-zero.
46   return {id + 1, ptr};
47 }
GetProcess(ProcessId id)48 Process* RowDataTracker::GetProcess(ProcessId id) {
49   PERFETTO_DCHECK(id != kNullId);
50   return &processes_[id - 1];
51 }
52 
NewFrame()53 IdPtr<Frame> RowDataTracker::NewFrame() {
54   BacktraceFrameId id = static_cast<BacktraceFrameId>(frames_.size());
55   Frame* ptr = &frames_.emplace_back();
56   // Always add 1 to ids, so that they're non-zero.
57   return {id + 1, ptr};
58 }
GetFrame(BacktraceFrameId id)59 Frame* RowDataTracker::GetFrame(BacktraceFrameId id) {
60   PERFETTO_DCHECK(id != kNullId);
61   return &frames_[id - 1];
62 }
63 
NewBacktrace()64 IdPtr<Backtrace> RowDataTracker::NewBacktrace() {
65   BacktraceId id = static_cast<BacktraceId>(backtraces_.size());
66   Backtrace* ptr = &backtraces_.emplace_back();
67   // Always add 1 to ids, so that they're non-zero.
68   return {id + 1, ptr};
69 }
GetBacktrace(BacktraceId id)70 Backtrace* RowDataTracker::GetBacktrace(BacktraceId id) {
71   PERFETTO_DCHECK(id != kNullId);
72   return &backtraces_[id - 1];
73 }
74 
NewBinary()75 IdPtr<Binary> RowDataTracker::NewBinary() {
76   BinaryId id = static_cast<BinaryId>(binaries_.size());
77   Binary* ptr = &binaries_.emplace_back();
78   // Always add 1 to ids, so that they're non-zero.
79   return {id + 1, ptr};
80 }
GetBinary(BinaryId id)81 Binary* RowDataTracker::GetBinary(BinaryId id) {
82   // Frames are allowed to have null binaries.
83   if (id == kNullId)
84     return nullptr;
85   return &binaries_[id - 1];
86 }
87 
88 }  // namespace perfetto::trace_processor::instruments_importer
89