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_PERF_AUX_DATA_TOKENIZER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_AUX_DATA_TOKENIZER_H_ 19 20 #include <cstdint> 21 #include <functional> 22 #include <memory> 23 24 #include "perfetto/base/status.h" 25 #include "perfetto/ext/base/status_or.h" 26 #include "perfetto/trace_processor/trace_blob_view.h" 27 #include "src/trace_processor/importers/common/clock_tracker.h" 28 #include "src/trace_processor/importers/perf/perf_session.h" 29 30 namespace perfetto { 31 namespace trace_processor { 32 33 class TraceProcessorContext; 34 namespace perf_importer { 35 36 struct AuxRecord; 37 class AuxStream; 38 struct ItraceStartRecord; 39 40 class AuxDataStream { 41 public: 42 virtual ~AuxDataStream(); 43 virtual void OnDataLoss(uint64_t) = 0; 44 virtual base::Status Parse(AuxRecord record, TraceBlobView data) = 0; 45 virtual base::Status NotifyEndOfStream() = 0; 46 virtual base::Status OnItraceStartRecord(ItraceStartRecord start) = 0; 47 }; 48 49 // Base class for aux data tokenizers. 50 // A factory is created upon encountering an AUXTRACE_INFO record. the payload 51 // for such messages usually contains trace specific information to setup trace 52 // specific parsing. Subclasses are responsible for parsing the payload and 53 // storing any data needed to create `AuxDataStream` instances as new data 54 // streams are encountered in the trace. 55 class AuxDataTokenizer { 56 public: 57 virtual ~AuxDataTokenizer(); 58 virtual base::StatusOr<AuxDataStream*> InitializeAuxDataStream( 59 AuxStream* stream) = 0; 60 }; 61 62 // Dummy tokenizer that just discard data. 63 // Used to skip streams that we do not know how to parse. 64 class DummyAuxDataStream : public AuxDataStream { 65 public: 66 explicit DummyAuxDataStream(TraceProcessorContext* context); 67 void OnDataLoss(uint64_t size) override; 68 base::Status Parse(AuxRecord, TraceBlobView data) override; 69 base::Status NotifyEndOfStream() override; 70 base::Status OnItraceStartRecord(ItraceStartRecord start) override; 71 72 private: 73 TraceProcessorContext* const context_; 74 }; 75 76 // Dummy tokenizer that just discard data. 77 // Used to skip streams that we do not know how to parse. 78 class DummyAuxDataTokenizer : public AuxDataTokenizer { 79 public: 80 explicit DummyAuxDataTokenizer(TraceProcessorContext* context); 81 ~DummyAuxDataTokenizer() override; 82 virtual base::StatusOr<AuxDataStream*> InitializeAuxDataStream( 83 AuxStream* stream) override; 84 85 private: 86 DummyAuxDataStream stream_; 87 }; 88 89 } // namespace perf_importer 90 } // namespace trace_processor 91 } // namespace perfetto 92 93 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_AUX_DATA_TOKENIZER_H_ 94