• 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 
48 private:
49     bool ParseDataRecursively(std::deque<uint8_t>::iterator &packagesCurIter);
50     bool ProcessRawTraceContent(std::string &bufferLine, uint8_t curType);
51     void ParseTraceDataItem(const std::string &buffer) override;
52     bool ParseCpuRawData(uint32_t cpuId, const std::string &buffer, uint32_t curType);
53     bool HmParseCpuRawData(const std::string &buffer, uint32_t curType);
54     bool ParseLastCommData(uint8_t type, const std::string &buffer);
55     bool InitRawTraceFileHeader(std::deque<uint8_t>::iterator &packagesCurIter);
56     bool InitEventFormats(const std::string &buffer);
57     bool UpdateCpuCoreMax(uint32_t cpuId);
58     void UpdateTraceMinRange();
59 
60 private:
61     std::unique_ptr<FtraceCpuDetailMsg> cpuDetail_ = nullptr;
62     std::unique_ptr<CpuDetailParser> cpuDetailParser_ = nullptr;
63     std::unique_ptr<FtraceProcessor> ftraceProcessor_ = nullptr;
64     std::unique_ptr<KernelSymbolsProcessor> ksymsProcessor_ = nullptr;
65     TraceDataCache *traceDataCache_ = nullptr;
66     bool hasGotHeader_ = false;
67     uint8_t fileType_ = 0;
68     uint8_t restCommDataCnt_ = 0;
69     uint32_t curCpuCoreNum_ = 0;
70     const std::string eventEndCmd_ = "print fmt:";
71 
72     uint32_t curFileOffset_ = 0;
73     // Store 4k types and data sizes each time
74     struct SpliteDataInfo {
75         uint32_t splitDataOffset_ = 0;
76         uint32_t splitDataSize_ = 0;
77         uint32_t splitType_ = 0;
78         SpliteDataInfo(uint32_t splitDataOffset, uint32_t splitDataSize, uint32_t splitType = 0)
splitDataOffset_SpliteDataInfo79             : splitDataOffset_(splitDataOffset), splitDataSize_(splitDataSize), splitType_(splitType)
80         {
81         }
82     };
83     std::deque<SpliteDataInfo> rawTraceSplitCpuData_ = {};
84     std::deque<SpliteDataInfo> rawTraceSplitCommData_ = {};
85 };
86 } // namespace TraceStreamer
87 } // namespace SysTuning
88 
89 #endif // RAWTRACE_PARSER_H_
90