1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RAWTRACE_PARSER_H 17 #define RAWTRACE_PARSER_H 18 #include "common_types.h" 19 #include "cpu_detail_parser.h" 20 #include "parser_base.h" 21 #include "ftrace_processor.h" 22 #include "kernel_symbols_processor.h" 23 #include "trace_data_cache.h" 24 #include "config_filter.h" 25 26 namespace SysTuning { 27 namespace TraceStreamer { 28 class RawTraceParser : public ParserBase { 29 public: 30 RawTraceParser(TraceDataCache *dataCache, const TraceStreamerFilters *filters); 31 ~RawTraceParser(); 32 void ParseTraceDataSegment(std::unique_ptr<uint8_t[]> bufferStr, size_t size, bool isFinish = false) override; 33 void WaitForParserEnd(); ClearRawTraceData()34 void ClearRawTraceData() 35 { 36 rawTraceSplitCpuData_.clear(); 37 rawTraceSplitCommData_.clear(); 38 curFileOffset_ = 0; 39 } GetRawtraceCpuData()40 const auto &GetRawtraceCpuData() 41 { 42 return rawTraceSplitCpuData_; 43 } GetRawtraceCommData()44 const auto &GetRawtraceCommData() 45 { 46 return rawTraceSplitCommData_; 47 } 48 #ifdef IS_WASM IsWasmReadFile()49 bool IsWasmReadFile() 50 { 51 return isWasmReadFile_; 52 } SetWasmReadFile(const bool isWasmReadFile)53 void SetWasmReadFile(const bool isWasmReadFile) 54 { 55 isWasmReadFile_ = isWasmReadFile; 56 } 57 #endif 58 59 private: 60 bool ParseDataRecursively(std::deque<uint8_t>::iterator &packagesCurIter); 61 bool ProcessRawTraceContent(std::string &bufferLine, uint8_t curType); 62 void ParseTraceDataItem(const std::string &buffer) override; 63 bool ParseCpuRawData(uint32_t cpuId, const std::string &buffer, uint32_t curType); 64 bool HmParseCpuRawData(const std::string &buffer, uint32_t curType); 65 bool ParseLastCommData(uint8_t type, const std::string &buffer); 66 bool InitRawTraceFileHeader(std::deque<uint8_t>::iterator &packagesCurIter); 67 bool InitEventFormats(const std::string &buffer); 68 bool UpdateCpuCoreMax(uint32_t cpuId); 69 void UpdateTraceMinRange(); 70 71 private: 72 std::unique_ptr<FtraceCpuDetailMsg> cpuDetail_ = nullptr; 73 std::unique_ptr<CpuDetailParser> cpuDetailParser_ = nullptr; 74 std::unique_ptr<FtraceProcessor> ftraceProcessor_ = nullptr; 75 std::unique_ptr<KernelSymbolsProcessor> ksymsProcessor_ = nullptr; 76 TraceDataCache *traceDataCache_ = nullptr; 77 bool hasGotHeader_ = false; 78 #ifdef IS_WASM 79 bool isWasmReadFile_ = false; 80 #endif 81 uint8_t fileType_ = 0; 82 uint8_t restCommDataCnt_ = 0; 83 uint32_t curCpuCoreNum_ = 0; 84 const std::string eventEndCmd_ = "print fmt:"; 85 86 uint32_t curFileOffset_ = 0; 87 // Store 4k types and data sizes each time 88 struct SpliteDataInfo { 89 uint32_t splitDataOffset_ = 0; 90 uint32_t splitDataSize_ = 0; 91 uint32_t splitType_ = 0; 92 SpliteDataInfo(uint32_t splitDataOffset, uint32_t splitDataSize, uint32_t splitType = 0) splitDataOffset_SpliteDataInfo93 : splitDataOffset_(splitDataOffset), splitDataSize_(splitDataSize), splitType_(splitType) 94 { 95 } 96 }; 97 std::deque<SpliteDataInfo> rawTraceSplitCpuData_ = {}; 98 std::deque<SpliteDataInfo> rawTraceSplitCommData_ = {}; 99 }; 100 } // namespace TraceStreamer 101 } // namespace SysTuning 102 103 #endif // RAWTRACE_PARSER_H_ 104