• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 namespace SysTuning {
26 namespace TraceStreamer {
27 class RawTraceParser : public ParserBase {
28 public:
29     RawTraceParser(TraceDataCache *dataCache, const TraceStreamerFilters *filters);
30     ~RawTraceParser();
31     void ParseTraceDataSegment(std::unique_ptr<uint8_t[]> bufferStr, size_t size, bool isFinish = false) override;
32     void WaitForParserEnd();
ClearRawTraceData()33     void ClearRawTraceData()
34     {
35         rawTraceSplitCpuData_.clear();
36         rawTraceSplitCommData_.clear();
37         curFileOffset_ = 0;
38     }
GetRawtraceCpuData()39     const auto &GetRawtraceCpuData()
40     {
41         return rawTraceSplitCpuData_;
42     }
GetRawtraceCommData()43     const auto &GetRawtraceCommData()
44     {
45         return rawTraceSplitCommData_;
46     }
47 #ifdef IS_WASM
IsWasmReadFile()48     bool IsWasmReadFile()
49     {
50         return isWasmReadFile_;
51     }
SetWasmReadFile(const bool isWasmReadFile)52     void SetWasmReadFile(const bool isWasmReadFile)
53     {
54         isWasmReadFile_ = isWasmReadFile;
55     }
56 #endif
57 
58 private:
59     bool ParseDataRecursively(std::deque<uint8_t>::iterator &packagesCurIter);
60     bool ProcessRawTraceContent(std::string &bufferLine, uint8_t curType);
61     void ParseTraceDataItem(const std::string &buffer) override;
62     bool ParseCpuRawData(uint32_t cpuId, const std::string &buffer, uint32_t curType);
63     bool HmParseCpuRawData(const std::string &buffer, uint32_t curType);
64     bool ParseLastCommData(uint8_t type, const std::string &buffer);
65     bool InitRawTraceFileHeader(std::deque<uint8_t>::iterator &packagesCurIter);
66     bool InitEventFormats(const std::string &buffer);
67     bool UpdateCpuCoreMax(uint32_t cpuId);
68     void UpdateTraceMinRange();
69 
70 private:
71     std::unique_ptr<FtraceCpuDetailMsg> cpuDetail_ = nullptr;
72     std::unique_ptr<CpuDetailParser> cpuDetailParser_ = nullptr;
73     std::unique_ptr<FtraceProcessor> ftraceProcessor_ = nullptr;
74     std::unique_ptr<KernelSymbolsProcessor> ksymsProcessor_ = nullptr;
75     TraceDataCache *traceDataCache_ = nullptr;
76     bool hasGotHeader_ = false;
77 #ifdef IS_WASM
78     bool isWasmReadFile_ = false;
79 #endif
80     uint8_t fileType_ = 0;
81     uint8_t restCommDataCnt_ = 0;
82     uint32_t curCpuCoreNum_ = 0;
83     const std::string eventEndCmd_ = "print fmt:";
84 
85     uint32_t curFileOffset_ = 0;
86     // Store 4k types and data sizes each time
87     struct SpliteDataInfo {
88         uint32_t splitDataOffset_ = 0;
89         uint32_t splitDataSize_ = 0;
90         uint32_t splitType_ = 0;
91         SpliteDataInfo(uint32_t splitDataOffset, uint32_t splitDataSize, uint32_t splitType = 0)
splitDataOffset_SpliteDataInfo92             : splitDataOffset_(splitDataOffset), splitDataSize_(splitDataSize), splitType_(splitType)
93         {
94         }
95     };
96     std::deque<SpliteDataInfo> rawTraceSplitCpuData_ = {};
97     std::deque<SpliteDataInfo> rawTraceSplitCommData_ = {};
98 };
99 } // namespace TraceStreamer
100 } // namespace SysTuning
101 
102 #endif // RAWTRACE_PARSER_H_
103