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