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