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_ETM_ETM_V4_DECODER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ETM_V4_DECODER_H_ 19 20 #include <stdint.h> 21 #include <cstdint> 22 #include <memory> 23 24 #include "perfetto/base/status.h" 25 #include "perfetto/ext/base/status_or.h" 26 #include "src/trace_processor/importers/etm/error_logger.h" 27 #include "src/trace_processor/importers/etm/opencsd.h" 28 29 namespace perfetto::trace_processor::etm { 30 31 class MappingVersion; 32 class TargetMemoryReader; 33 34 // Wrapper around the open_csd packet processor. This class will take ETM traces 35 // as input and output a stream of ETM elements. 36 class EtmV4Decoder : private ITrcGenElemIn { 37 public: 38 class Delegate { 39 public: 40 virtual ~Delegate(); 41 virtual ocsd_datapath_resp_t TraceElemIn(const ocsd_trc_index_t index_sop, 42 const uint8_t trc_chan_id, 43 const OcsdTraceElement& elem, 44 const MappingVersion* mapping) = 0; 45 }; 46 47 static base::StatusOr<std::unique_ptr<EtmV4Decoder>> Create( 48 Delegate* delegate, 49 TargetMemoryReader* reader, 50 const EtmV4Config& config); 51 52 base::StatusOr<bool> Reset(ocsd_trc_index_t index); 53 base::StatusOr<bool> Data(const ocsd_trc_index_t, 54 const size_t size, 55 const uint8_t* data, 56 uint32_t* num_bytes_processed); 57 base::StatusOr<bool> Flush(ocsd_trc_index_t index); 58 base::StatusOr<bool> Eot(ocsd_trc_index_t index); 59 60 private: 61 EtmV4Decoder(Delegate* delegate, TargetMemoryReader* reader); 62 base::Status Init(const EtmV4Config& config); 63 ocsd_datapath_resp_t TraceElemIn(const ocsd_trc_index_t, 64 const uint8_t, 65 const OcsdTraceElement& elem) override; 66 67 Delegate* const delegate_; 68 TargetMemoryReader* memory_reader_; 69 70 ErrorLogger error_logger_; 71 TrcIDecode instruction_decoder_; 72 TrcPktDecodeEtmV4I packet_decoder_; 73 TrcPktProcEtmV4I packet_processor_; 74 }; 75 76 } // namespace perfetto::trace_processor::etm 77 78 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ETM_V4_DECODER_H_ 79