• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 #ifndef SRC_PRINT_EVENT_PARSER_H
16 #define SRC_PRINT_EVENT_PARSER_H
17 #include <regex>
18 #include <string_view>
19 #include "common_types.h"
20 #include "event_parser_base.h"
21 #include "filter/measure_filter.h"
22 #include "filter/process_filter.h"
23 #include "filter/slice_filter.h"
24 #include "filter/task_pool_filter.h"
25 #include "string_to_numerical.h"
26 #include "trace_streamer_config.h"
27 namespace SysTuning {
28 namespace TraceStreamer {
29 class PrintEventParser : private EventParserBase {
30 public:
31     PrintEventParser(TraceDataCache* dataCache, const TraceStreamerFilters* filter);
32     bool ParsePrintEvent(const std::string& comm,
33                          uint64_t ts,
34                          uint32_t pid,
35                          std::string_view event,
36                          const BytraceLine& line);
37     void Finish();
38     void SetTraceType(TraceFileType traceType);
39     void SetTraceClockId(BuiltinClocks clock);
40 
41 private:
42     using FrameFuncCall = std::function<bool(const size_t callStackRow, std::string& args, const BytraceLine& line)>;
43     ParseResult GetTracePoint(std::string_view pointStr, TracePoint& outPoint) const;
44     ParseResult CheckTracePoint(std::string_view pointStr) const;
45     uint32_t GetThreadGroupId(std::string_view pointStr, size_t& length) const;
46     std::string_view GetPointNameForBegin(std::string_view pointStr, size_t tGidlength) const;
47     ParseResult HandlerB(std::string_view pointStr, TracePoint& outPoint, size_t tGidlength) const;
48     void HandleFrameSliceBeginEvent(DataIndex eventName,
49                                     size_t callStackRow,
50                                     std::string& args,
51                                     const BytraceLine& line);
52     void HandleFrameSliceEndEvent(uint64_t ts, uint64_t pid, uint64_t tid, size_t callStackRow);
53     void HandleFrameQueueEndEvent(uint64_t ts, uint64_t pid, uint64_t tid, size_t callStackRow);
54     static ParseResult HandlerE(void);
55     ParseResult HandlerCSF(std::string_view pointStr, TracePoint& outPoint, size_t tGidlength) const;
56     static size_t GetNameLength(std::string_view pointStr, size_t nameIndex);
57     size_t GetValueLength(std::string_view pointStr, size_t valueIndex) const;
58     bool ReciveVsync(size_t callStackRow, std::string& args, const BytraceLine& line);
59     bool RSReciveOnVsync(size_t callStackRow, std::string& args, const BytraceLine& line);
60     bool OnRwTransaction(size_t callStackRow, std::string& args, const BytraceLine& line);
61     bool OnMainThreadProcessCmd(size_t callStackRow, std::string& args, const BytraceLine& line);
62     bool OnFrameQueueStart(uint64_t ts, size_t callStackRow, uint64_t pid);
63 
64 private:
65     std::map<DataIndex, FrameFuncCall> eventToFrameFunctionMap_ = {};
66     const uint32_t pointLength_;
67     const uint32_t maxPointLength_;
68     TraceStreamerConfig config_{};
69     const DataIndex recvievVsync_ = traceDataCache_->GetDataIndex("H:ReceiveVsync");
70     const DataIndex rsOnVsyncEvent_ = traceDataCache_->GetDataIndex("H:RSMainThread::OnVsync");
71     const std::string onFrameQueeuStartEvent_ = "H:M: Frame queued";
72     const DataIndex marshRwTransactionData_ = traceDataCache_->GetDataIndex("H:MarshRSTransactionData");
73     const DataIndex rsMainThreadProcessCmd_ = traceDataCache_->GetDataIndex("H:RSMainThread::ProcessCommandUni");
74     const std::regex recvVsyncPattern_ = std::regex("(\\w+):(\\w+)");
75     const std::regex transFlagPattern_ = std::regex("transactionFlag:\\[(\\d+),(\\d+)\\]");
76     const std::regex mainProcessCmdPattern = std::regex("\\[(\\d+),(\\d+)\\]");
77     std::vector<uint64_t> frameCallIds_ = {};
78     std::vector<uint64_t> vsyncSliceIds_ = {};
79     TraceFileType traceType_ = TRACE_FILETYPE_H_TRACE;
80     BuiltinClocks clock_ = TS_CLOCK_BOOTTIME;
81     // if convert vsync's now and expectEnd
82     bool convertVsyncTs_ = true;
83 };
84 } // namespace TraceStreamer
85 } // namespace SysTuning
86 
87 #endif // SRC_PRINT_EVENT_PARSER_H
88