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_COMMON_TRACE_FILE_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_TRACE_FILE_TRACKER_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "src/trace_processor/storage/trace_storage.h" 24 #include "src/trace_processor/tables/metadata_tables_py.h" 25 #include "src/trace_processor/util/trace_type.h" 26 27 namespace perfetto::trace_processor { 28 29 class TraceProcessorContext; 30 31 // This class keeps track of the file currently being parsed and metadata about 32 // it. Files can be nested into other files (zip or gzip files) and this class 33 // also keeps track of those relations. 34 class TraceFileTracker { 35 public: TraceFileTracker(TraceProcessorContext * context)36 explicit TraceFileTracker(TraceProcessorContext* context) 37 : context_(context) {} 38 39 tables::TraceFileTable::Id AddFile(const std::string& name); AddFile()40 tables::TraceFileTable::Id AddFile() { return AddFileImpl(kNullStringId); } 41 void SetSize(tables::TraceFileTable::Id id, uint64_t size); 42 void StartParsing(tables::TraceFileTable::Id id, TraceType trace_type); 43 void DoneParsing(tables::TraceFileTable::Id id, size_t size); 44 45 private: 46 tables::TraceFileTable::Id AddFileImpl(StringId name); 47 48 TraceProcessorContext* const context_; 49 size_t processing_order_ = 0; 50 std::vector<tables::TraceFileTable::Id> parsing_stack_; 51 }; 52 53 } // namespace perfetto::trace_processor 54 55 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_TRACE_FILE_TRACKER_H_ 56