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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_INSTRUMENTS_ROW_DATA_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_INSTRUMENTS_ROW_DATA_TRACKER_H_ 19 20 #include "src/trace_processor/importers/instruments/row.h" 21 #include "src/trace_processor/types/destructible.h" 22 #include "src/trace_processor/types/trace_processor_context.h" 23 24 namespace perfetto::trace_processor::instruments_importer { 25 26 template <typename T> 27 struct IdPtr { 28 uint32_t id; 29 T* ptr; 30 }; 31 32 // Keeps track of row data. 33 class RowDataTracker : public Destructible { 34 public: GetOrCreate(TraceProcessorContext * context)35 static RowDataTracker& GetOrCreate(TraceProcessorContext* context) { 36 if (!context->instruments_row_data_tracker) { 37 context->instruments_row_data_tracker.reset(new RowDataTracker()); 38 } 39 return static_cast<RowDataTracker&>(*context->instruments_row_data_tracker); 40 } 41 ~RowDataTracker() override; 42 43 IdPtr<Thread> NewThread(); 44 Thread* GetThread(ThreadId id); 45 46 IdPtr<Process> NewProcess(); 47 Process* GetProcess(ProcessId id); 48 49 IdPtr<Frame> NewFrame(); 50 Frame* GetFrame(BacktraceFrameId id); 51 52 IdPtr<Backtrace> NewBacktrace(); 53 Backtrace* GetBacktrace(BacktraceId id); 54 55 IdPtr<Binary> NewBinary(); 56 Binary* GetBinary(BinaryId id); 57 58 private: 59 explicit RowDataTracker(); 60 61 std::vector<Thread> threads_; 62 std::vector<Process> processes_; 63 std::vector<Frame> frames_; 64 std::vector<Backtrace> backtraces_; 65 std::vector<Binary> binaries_; 66 }; 67 68 } // namespace perfetto::trace_processor::instruments_importer 69 70 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_INSTRUMENTS_ROW_DATA_TRACKER_H_ 71