1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci#ifndef SRC_PRINT_EVENT_PARSER_H 16fb726d48Sopenharmony_ci#define SRC_PRINT_EVENT_PARSER_H 17fb726d48Sopenharmony_ci#include <regex> 18fb726d48Sopenharmony_ci#include <set> 19fb726d48Sopenharmony_ci#include <string_view> 20fb726d48Sopenharmony_ci#include "common_types.h" 21fb726d48Sopenharmony_ci#include "event_parser_base.h" 22fb726d48Sopenharmony_ci#include "measure_filter.h" 23fb726d48Sopenharmony_ci#include "process_filter.h" 24fb726d48Sopenharmony_ci#include "slice_filter.h" 25fb726d48Sopenharmony_ci#include "task_pool_filter.h" 26fb726d48Sopenharmony_ci#include "string_to_numerical.h" 27fb726d48Sopenharmony_ci#include "trace_streamer_config.h" 28fb726d48Sopenharmony_cinamespace SysTuning { 29fb726d48Sopenharmony_cinamespace TraceStreamer { 30fb726d48Sopenharmony_ciclass PrintEventParser : private EventParserBase { 31fb726d48Sopenharmony_cipublic: 32fb726d48Sopenharmony_ci PrintEventParser(TraceDataCache *dataCache, const TraceStreamerFilters *filter); 33fb726d48Sopenharmony_ci bool ParsePrintEvent(const std::string &comm, 34fb726d48Sopenharmony_ci uint64_t ts, 35fb726d48Sopenharmony_ci uint32_t pid, 36fb726d48Sopenharmony_ci std::string_view event, 37fb726d48Sopenharmony_ci const BytraceLine &line); 38fb726d48Sopenharmony_ci void ParseBeginEvent(const std::string &comm, 39fb726d48Sopenharmony_ci uint64_t ts, 40fb726d48Sopenharmony_ci uint32_t pid, 41fb726d48Sopenharmony_ci TracePoint &point, 42fb726d48Sopenharmony_ci const BytraceLine &line); 43fb726d48Sopenharmony_ci void ParseEndEvent(uint64_t ts, uint32_t pid, const TracePoint &point); 44fb726d48Sopenharmony_ci void ParseStartEvent(const std::string &comm, 45fb726d48Sopenharmony_ci uint64_t ts, 46fb726d48Sopenharmony_ci uint32_t pid, 47fb726d48Sopenharmony_ci const TracePoint &point, 48fb726d48Sopenharmony_ci const BytraceLine &line); 49fb726d48Sopenharmony_ci void ParseFinishEvent(uint64_t ts, uint32_t pid, const TracePoint &point, const BytraceLine &line); 50fb726d48Sopenharmony_ci void ParseCreateEvent(uint64_t ts, const TracePoint &point); 51fb726d48Sopenharmony_ci void ParseGEvent(uint64_t ts, uint32_t pid, TracePoint &point); 52fb726d48Sopenharmony_ci void ParseHEvent(uint64_t ts, const TracePoint &point); 53fb726d48Sopenharmony_ci void Finish(); 54fb726d48Sopenharmony_ci void SetTraceType(TraceFileType traceType); 55fb726d48Sopenharmony_ci void SetTraceClockId(BuiltinClocks clock); 56fb726d48Sopenharmony_ci 57fb726d48Sopenharmony_ciprivate: 58fb726d48Sopenharmony_ci using FrameFuncCall = std::function<bool(const size_t callStackRow, std::string &args, const BytraceLine &line)>; 59fb726d48Sopenharmony_ci ParseResult GetTracePoint(std::string_view pointStr, TracePoint &outPoint) const; 60fb726d48Sopenharmony_ci ParseResult CheckTracePoint(std::string_view pointStr) const; 61fb726d48Sopenharmony_ci uint32_t GetThreadGroupId(std::string_view pointStr, size_t &length) const; 62fb726d48Sopenharmony_ci std::string_view GetPointNameForBegin(std::string_view pointStr, size_t tGidlength) const; 63fb726d48Sopenharmony_ci ParseResult HandlerB(std::string_view pointStr, TracePoint &outPoint, size_t tGidlength) const; 64fb726d48Sopenharmony_ci bool HandleFrameSliceBeginEvent(DataIndex eventName, 65fb726d48Sopenharmony_ci size_t callStackRow, 66fb726d48Sopenharmony_ci std::string &args, 67fb726d48Sopenharmony_ci const BytraceLine &line); 68fb726d48Sopenharmony_ci void HandleFrameSliceEndEvent(uint64_t ts, uint64_t pid, uint64_t tid, size_t callStackRow); 69fb726d48Sopenharmony_ci void HandleFrameQueueEndEvent(uint64_t ts, uint64_t pid, uint64_t tid, size_t callStackRow); 70fb726d48Sopenharmony_ci bool HandleAnimationBeginEvent(const TracePoint &point, size_t callStackRow, const BytraceLine &line); 71fb726d48Sopenharmony_ci static ParseResult HandlerE(void); 72fb726d48Sopenharmony_ci ParseResult HandlerCSF(std::string_view pointStr, TracePoint &outPoint, size_t tGidlength) const; 73fb726d48Sopenharmony_ci static size_t GetNameLength(std::string_view pointStr, size_t nameIndex); 74fb726d48Sopenharmony_ci static size_t GetGHNameLength(std::string_view pointStr, size_t nameIndex); 75fb726d48Sopenharmony_ci ParseResult HandlerGH(std::string_view pointStr, TracePoint &outPoint, size_t tGidlength) const; 76fb726d48Sopenharmony_ci size_t GetValueLength(std::string_view pointStr, size_t valueIndex) const; 77fb726d48Sopenharmony_ci bool ReciveVsync(size_t callStackRow, std::string &args, const BytraceLine &line); 78fb726d48Sopenharmony_ci bool RSReciveOnDoComposition(size_t callStackRow, std::string &args, const BytraceLine &line); 79fb726d48Sopenharmony_ci bool OnRwTransaction(size_t callStackRow, std::string &args, const BytraceLine &line); 80fb726d48Sopenharmony_ci bool OnMainThreadProcessCmd(size_t callStackRow, std::string &args, const BytraceLine &line); 81fb726d48Sopenharmony_ci bool OnFrameQueueStart(uint64_t ts, size_t callStackRow, uint64_t pid); 82fb726d48Sopenharmony_ci bool OnVsyncEvent(size_t callStackRow, std::string &args, const BytraceLine &line); 83fb726d48Sopenharmony_ci 84fb726d48Sopenharmony_ciprivate: 85fb726d48Sopenharmony_ci std::map<DataIndex, FrameFuncCall> eventToFrameFunctionMap_ = {}; 86fb726d48Sopenharmony_ci TraceStreamerConfig config_{}; 87fb726d48Sopenharmony_ci const DataIndex recvievVsync_ = traceDataCache_->GetDataIndex("H:ReceiveVsync"); 88fb726d48Sopenharmony_ci const DataIndex onVsyncEvent_ = traceDataCache_->GetDataIndex("H:OnVsyncEvent"); 89fb726d48Sopenharmony_ci const std::string rsOnDoCompositionStr_ = "H:RSMainThread::DoComposition"; 90fb726d48Sopenharmony_ci DataIndex rsOnDoCompositionEvent_ = INVALID_DATAINDEX; 91fb726d48Sopenharmony_ci const std::string onFrameQueeuStartEvent_ = "H:M: Frame queued"; 92fb726d48Sopenharmony_ci const std::string onAnimationProcEvent_ = "render_service"; // 并行化前动效过程异步trace打点线程 93fb726d48Sopenharmony_ci const std::string newOnAnimationProcEvent_ = "RSUniRenderThre"; // 并行化后动效过程异步trace打点线程 94fb726d48Sopenharmony_ci const DataIndex marshRwTransactionData_ = traceDataCache_->GetDataIndex("H:MarshRSTransactionData"); 95fb726d48Sopenharmony_ci const DataIndex rsMainThreadProcessCmd_ = traceDataCache_->GetDataIndex("H:RSMainThread::ProcessCommandUni"); 96fb726d48Sopenharmony_ci const std::regex recvVsyncPattern_ = std::regex(R"((\w+):\s*(\w+))"); 97fb726d48Sopenharmony_ci const std::regex transFlagPattern_ = std::regex("transactionFlag:\\[(\\d+),(\\d+)\\]"); 98fb726d48Sopenharmony_ci const std::regex mainProcessCmdPattern_ = std::regex("\\[(\\d+),(\\d+)\\]"); 99fb726d48Sopenharmony_ci const std::regex distributeMatcher_ = std::regex(R"(H:\[([a-z0-9]+),([a-z0-9]+),([a-z0-9]+)\]#([CS]?)##(.*))"); 100fb726d48Sopenharmony_ci std::vector<uint64_t> frameCallIds_ = {}; 101fb726d48Sopenharmony_ci std::unordered_map<uint64_t, std::vector<uint64_t>> vsyncSliceMap_ = {}; 102fb726d48Sopenharmony_ci TraceFileType traceType_ = TRACE_FILETYPE_H_TRACE; 103fb726d48Sopenharmony_ci BuiltinClocks clock_ = TS_CLOCK_BOOTTIME; 104fb726d48Sopenharmony_ci const uint32_t maxVsyncEventSize_ = 2; 105fb726d48Sopenharmony_ci // if convert vsync's now and expectEnd 106fb726d48Sopenharmony_ci bool convertVsyncTs_ = true; 107fb726d48Sopenharmony_ci}; 108fb726d48Sopenharmony_ci} // namespace TraceStreamer 109fb726d48Sopenharmony_ci} // namespace SysTuning 110fb726d48Sopenharmony_ci 111fb726d48Sopenharmony_ci#endif // SRC_PRINT_EVENT_PARSER_H 112