From d9c083f22ef26ea0f25d915e038b32f9f2bbbaeb Mon Sep 17 00:00:00 2001 From: JustinYT Date: Tue, 13 May 2025 16:06:20 +0800 Subject: [PATCH 1/2] Add config.json for switch config.Add syscalls switch. Signed-off-by: JustinYT --- trace_streamer/build_operator.sh | 8 + trace_streamer/config/config.json | 136 ++++++++++++ trace_streamer/src/filter/BUILD.gn | 1 + .../src/filter/animation_filter.cpp | 34 ++- trace_streamer/src/filter/animation_filter.h | 13 +- .../src/filter/app_start_filter.cpp | 12 +- trace_streamer/src/filter/app_start_filter.h | 14 +- trace_streamer/src/filter/config_filter.cpp | 208 ++++++++++++++++++ trace_streamer/src/filter/config_filter.h | 159 +++++++++++++ trace_streamer/src/filter/cpu_filter.cpp | 5 +- trace_streamer/src/filter/cpu_filter.h | 1 + trace_streamer/src/filter/slice_filter.cpp | 13 +- trace_streamer/src/filter/syscall_filter.cpp | 31 +-- trace_streamer/src/filter/syscall_filter.h | 2 +- .../parser/hiperf_parser/perf_data_parser.cpp | 2 +- .../htrace_parser/htrace_event_parser.cpp | 32 ++- .../src/parser/print_event_parser.cpp | 14 +- .../bytrace_parser/bytrace_event_parser.cpp | 22 +- .../rawtrace_parser/cpu_detail_parser.cpp | 2 +- .../rawtrace_parser/rawtrace_parser.cpp | 2 +- .../parser/rawtrace_parser/rawtrace_parser.h | 1 + trace_streamer/src/rpc/rpc_server.cpp | 9 +- .../trace_stdtype/ftrace/syscall_stdtype.cpp | 2 +- .../trace_stdtype/ftrace/syscall_stdtype.h | 2 +- .../trace_streamer/trace_streamer_filters.cpp | 1 + .../trace_streamer/trace_streamer_filters.h | 2 + .../trace_streamer_selector.cpp | 27 ++- .../trace_streamer/trace_streamer_selector.h | 3 + trace_streamer/src/version.cpp | 4 +- 29 files changed, 656 insertions(+), 106 deletions(-) create mode 100644 trace_streamer/config/config.json create mode 100644 trace_streamer/src/filter/config_filter.cpp create mode 100644 trace_streamer/src/filter/config_filter.h diff --git a/trace_streamer/build_operator.sh b/trace_streamer/build_operator.sh index f4b86177..656c8ee4 100755 --- a/trace_streamer/build_operator.sh +++ b/trace_streamer/build_operator.sh @@ -62,6 +62,14 @@ else echo "begin to build ..." prebuilts/"$gn_path"/"$ninja" -C "$out_dir" fi +if [ "$target" != "wasm" ]; then + if [ -f "config/config.json" ]; then + cp -r "config" "$out_dir" + echo "Successfully found the configuration!" + else + echo "Failed to find the configuration!" + fi +fi if [ "$out_dir" == "out/macx" ];then ./mac_depend.sh fi \ No newline at end of file diff --git a/trace_streamer/config/config.json b/trace_streamer/config/config.json new file mode 100644 index 00000000..6b4ff707 --- /dev/null +++ b/trace_streamer/config/config.json @@ -0,0 +1,136 @@ +{ + "_comment": "这是动效的相关打点", + "Animation": { + "_comment": "动效过程打点线程,render_service为并行化前的打点线程,RSUniRenderThre为并行化后的打点线程", + "animationProcEvents_": [ + "render_service", + "RSUniRenderThre" + ], + "_comment": "动效相关打点,H:LAUNCHER_APP_LAUNCH_FROM_ICON为桌面图标点击启动,H:LAUNCHER_APP_LAUNCH_FROM_NOTIFICATIONBAR为通知栏通知消息点击启动,H:LAUNCHER_APP_LAUNCH_FROM_NOTIFICATIONBAR_IN_LOCKSCREEN为锁屏通知消息点击启动,H:LAUNCHER_APP_LAUNCH_FROM_RECENT为多任务点击应用,H:LAUNCHER_APP_SWIPE_TO_HOME为HOME键返回桌面,H:LAUNCHER_APP_BACK_TO_HOME为Back键返回桌面,H:APP_TRANSITION_TO_OTHER_APP为应用切换到另一个应用,H:APP_TRANSITION_FROM_OTHER_APP为从另一个应用跳回,H:APP_LIST_FLING为应用中列表滑动", + "onAnimationStartEvents_": [ + "H:LAUNCHER_APP_LAUNCH_FROM_ICON", + "H:LAUNCHER_APP_LAUNCH_FROM_NOTIFICATIONBAR", + "H:LAUNCHER_APP_LAUNCH_FROM_NOTIFICATIONBAR_IN_LOCKSCREEN", + "H:LAUNCHER_APP_LAUNCH_FROM_RECENT", + "H:LAUNCHER_APP_SWIPE_TO_HOME", + "H:LAUNCHER_APP_BACK_TO_HOME", + "H:APP_TRANSITION_TO_OTHER_APP", + "H:APP_TRANSITION_FROM_OTHER_APP", + "H:APP_LIST_FLING" + ], + "_comment": "H:GenerateVsyncCount,用于计算设备的平均帧率,累计6次后输出平均帧率", + "frameRateCmd_": [ + "H:GenerateVsyncCount" + ], + "_comment": "H:RSJankStats::RecordAnimationDynamicFrameRate,用于更新动效的帧率,若存在此打点,则以这个打点为准,否则以H:Repaint为准", + "realFrameRateCmd_": [ + "H:RSJankStats::RecordAnimationDynamicFrameRate" + ], + "_comment": "H:Repaint(硬件合成器合成绘制),用于计算动效帧率", + "frameCountCmd_": [ + "H:Repaint" + ], + "_comment": "H:RSUniRender::Process:[WindowScene_和H:RSSurfaceRenderNodeDrawable::OnDraw:[WindowScene_用来获取动效帧数据的打点,其中H:RSUniRender::Process:[WindowScene_为并行化前打点", + "frameBeginCmd_": [ + "H:RSUniRender::Process:[WindowScene_", + "H:RSSurfaceRenderNodeDrawable::OnDraw:[WindowScene_" + ], + "_comment": "H:RSUniRender::Process:[SCBDesktop和H:RSSurfaceRenderNodeDrawable::OnDraw:[SCBDesktop用来获取设备的宽高,其中H:RSUniRender::Process:[SCBDesktop为并行化前打点", + "screenSizeCmd_": [ + "H:RSUniRender::Process:[SCBDesktop", + "H:RSSurfaceRenderNodeDrawable::OnDraw:[SCBDesktop" + ], + "_comment": "H:RSMainThread::DoComposition和H:RenderFrame用来获取动效帧的结束时间,其中H:RSMainThread::DoComposition为并行化前的打点", + "frameEndTimeCmd_": [ + "H:RenderFrame" + ], + "_comment": "H:PostAndWait, parallel type并行化的标志", + "parallelTypeCmd_": [ + "H:PostAndWait, parallel type" + ] + }, + "_comment": "这是启动场景的相关打点", + "AppStartup": { + "_comment": "启动第一阶段,手指点击", + "phase1": { + "pName": "ProcessTouchEvent", + "start": [ + "H:client dispatch touchId:" + ], + "end": [ + "H:OHOS::ErrCode OHOS::AAFwk::AbilityManagerClient::StartUIAbilityBySCB" + ] + }, + "_comment": "启动第二阶段,处理创建进程信息,创建窗口", + "phase2": { + "pName": "StartUIAbilityBySCB", + "start": [ + "H:OHOS::ErrCode OHOS::AAFwk::AbilityManagerClient::StartUIAbilityBySCB" + ], + "end": [ + "H:virtual void OHOS::AppExecFwk::AppMgrServiceInner::LoadAbility" + ] + }, + "_comment": "启动第三阶段,拉起应用进程", + "phase3": { + "pName": "LoadAbility", + "start": [ + "H:virtual void OHOS::AppExecFwk::AppMgrServiceInner::LoadAbility" + ], + "end": [ + "H:virtual void OHOS::AppExecFwk::AppMgrServiceInner::AttachApplication(const pid_t, const sptr &)##" + ] + }, + "_comment": "启动第四阶段,加载应用", + "phase4": { + "pName": "Application Launching", + "start": [ + "H:virtual void OHOS::AppExecFwk::AppMgrServiceInner::AttachApplication(const pid_t, const sptr &)##" + ], + "end": [ + "H:void OHOS::AppExecFwk::MainThread::HandleLaunchAbility(const std::shared_ptr &)##" + ] + }, + "_comment": "启动第五阶段,加载 UI Ability", + "phase5": { + "pName": "UI Ability Launching", + "start": [ + "H:void OHOS::AppExecFwk::MainThread::HandleLaunchAbility(const std::shared_ptr &)##" + ], + "end": [ + "H:void OHOS::AbilityRuntime::FAAbilityThread::HandleAbilityTransaction(const OHOS::AbilityRuntime::Want &, const OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##", + "H:void OHOS::AbilityRuntime::UIAbilityThread::HandleAbilityTransaction" + ] + }, + "_comment": "启动第六阶段,应用进入前台", + "phase6": { + "pName": "UI Ability OnForeground", + "start": [ + "H:void OHOS::AbilityRuntime::FAAbilityThread::HandleAbilityTransaction(const OHOS::AbilityRuntime::Want &, const OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##", + "H:void OHOS::AbilityRuntime::UIAbilityThread::HandleAbilityTransaction" + ], + "end": [ + "H:ReceiveVsync dataCount" + ] + } + }, + "_comment": "Flag 开关", + "config": { + "TaskPool": 0, + "AnimationAnalysis": 0, + "AppStartup": 0, + "SchedulingAnalysis": 0, + "BinderRunnable": 0, + "FfrtConvert": 0, + "HMKernel": 1, + "VSync": 0, + "Hangs Detection": 0, + "LTPO": 0, + "Start&Finish Trace Category": 0, + "UserPluginsRow": 0, + "CPU by Irq": 0, + "RawTraceCutStartTs": 1, + "AI": 0, + "System Calls": "" + } +} \ No newline at end of file diff --git a/trace_streamer/src/filter/BUILD.gn b/trace_streamer/src/filter/BUILD.gn index 5939c40b..33a4036c 100644 --- a/trace_streamer/src/filter/BUILD.gn +++ b/trace_streamer/src/filter/BUILD.gn @@ -82,6 +82,7 @@ ohos_source_set("filter") { "args_filter.cpp", "binder_filter.cpp", "clock_filter_ex.cpp", + "config_filter.cpp", "cpu_filter.cpp", "filter_base.cpp", "filter_filter.cpp", diff --git a/trace_streamer/src/filter/animation_filter.cpp b/trace_streamer/src/filter/animation_filter.cpp index 4dbe7d94..478cf77d 100644 --- a/trace_streamer/src/filter/animation_filter.cpp +++ b/trace_streamer/src/filter/animation_filter.cpp @@ -34,18 +34,15 @@ AnimationFilter::AnimationFilter(TraceDataCache *dataCache, const TraceStreamerF if (dynamicFrame_ == nullptr || callStackSlice_ == nullptr) { TS_LOGE("dynamicFrame_ or callStackSlice_ is nullptr."); } - onAnimationStartEvents_ = { - traceDataCache_->GetDataIndex("H:LAUNCHER_APP_LAUNCH_FROM_ICON"), - traceDataCache_->GetDataIndex("H:LAUNCHER_APP_LAUNCH_FROM_NOTIFICATIONBAR"), - traceDataCache_->GetDataIndex("H:LAUNCHER_APP_LAUNCH_FROM_NOTIFICATIONBAR_IN_LOCKSCREEN"), - traceDataCache_->GetDataIndex("H:LAUNCHER_APP_LAUNCH_FROM_RECENT"), - traceDataCache_->GetDataIndex("H:LAUNCHER_APP_SWIPE_TO_HOME"), - traceDataCache_->GetDataIndex("H:LAUNCHER_APP_BACK_TO_HOME"), - traceDataCache_->GetDataIndex("H:APP_TRANSITION_TO_OTHER_APP"), - traceDataCache_->GetDataIndex("H:APP_TRANSITION_FROM_OTHER_APP"), - traceDataCache_->GetDataIndex("H:APP_LIST_FLING")}; } AnimationFilter::~AnimationFilter() {} +void AnimationFilter::InitAnimationStartEvents() +{ + auto res = streamFilters_->configFilter_->GetAnimationConfig().GetOnAnimationStartEvents(); + for (auto &eventName : res) { + onAnimationStartEvents_.insert(traceDataCache_->GetDataIndex(eventName)); + } +} bool AnimationFilter::UpdateDeviceFps(const BytraceLine &line) { generateVsyncCnt_++; @@ -87,24 +84,24 @@ bool AnimationFilter::UpdateDeviceScreenSize(const TracePoint &point) bool AnimationFilter::UpdateDeviceInfoEvent(const TracePoint &point, const BytraceLine &line) { if (traceDataCache_->GetConstDeviceInfo().PhysicalFrameRate() == INVALID_UINT32 && - StartWith(point.name_, frameRateCmd_)) { + streamFilters_->configFilter_->GetAnimationConfig().CheckIfFrameRateCmd(point.name_)) { return UpdateDeviceFps(line); } else if (traceDataCache_->GetConstDeviceInfo().PhysicalWidth() == INVALID_UINT32 && - (StartWith(point.name_, newScreenSizeCmd_) || StartWith(point.name_, screenSizeCmd_))) { + streamFilters_->configFilter_->GetAnimationConfig().CheckIfScreenSizeCmd(point.name_)) { return UpdateDeviceScreenSize(point); } return false; } bool AnimationFilter::BeginDynamicFrameEvent(const TracePoint &point, size_t callStackRow) { - if (StartWith(point.name_, paralleCmd_)) { + if (streamFilters_->configFilter_->GetAnimationConfig().CheckIfParallelCmd(point.name_)) { isNewAnimation_ = true; return true; } - if (StartWith(point.name_, frameCountCmd_)) { + if (streamFilters_->configFilter_->GetAnimationConfig().CheckIfFrameCountCmd(point.name_)) { frameCountRows_.insert(callStackRow); return true; - } else if (StartWith(point.name_, realFrameRateCmd_)) { + } else if (streamFilters_->configFilter_->GetAnimationConfig().CheckIfRealFrameRateCmd(point.name_)) { // eg: `frame rate is 88.61: APP_LIST_FLING, com.taobao.taobao, pages/Index` auto infos = SplitStringToVec(point.funcArgs_, ": "); auto curRealFrameRateFlagInadex = traceDataCache_->GetDataIndex("H:" + infos.back()); @@ -116,7 +113,7 @@ bool AnimationFilter::BeginDynamicFrameEvent(const TracePoint &point, size_t cal traceDataCache_->GetAnimation()->UpdateFrameInfo(animationRow, traceDataCache_->GetDataIndex(curFrameNum + curRealFrameRate)); return true; - } else if (StartWith(point.name_, newFrameBeginCmd_) || StartWith(point.name_, frameBeginCmd_)) { + } else if (streamFilters_->configFilter_->GetAnimationConfig().CheckIfFrameBeginCmd(point.name_)) { // get the parent frame of data const std::optional &parentId = callStackSlice_->ParentIdData()[callStackRow]; uint8_t depth = callStackSlice_->Depths()[callStackRow]; @@ -178,8 +175,9 @@ bool AnimationFilter::UpdateDynamicEndTime(const uint64_t curFrameRow, uint64_t curStackRow = callStackSlice_->ParentIdData()[curStackRow].value(); // use frameEndTimeCmd_'s endTime as dynamicFrame endTime auto nameIndex = callStackSlice_->NamesData()[curStackRow]; - if (isNewAnimation_ && StartWith(traceDataCache_->GetDataFromDict(nameIndex), renderFrameCmd_) || - StartWith(traceDataCache_->GetDataFromDict(nameIndex), frameEndTimeCmd_)) { + if ((!isNewAnimation_ && StartWith(traceDataCache_->GetDataFromDict(nameIndex), frameEndTimeCmd_)) || + streamFilters_->configFilter_->GetAnimationConfig().CheckIfFrameEndTimeCmd( + traceDataCache_->GetDataFromDict(nameIndex))) { auto endTime = callStackSlice_->TimeStampData()[curStackRow] + callStackSlice_->DursData()[curStackRow]; dynamicFrame_->UpdateEndTime(curFrameRow, endTime); return true; diff --git a/trace_streamer/src/filter/animation_filter.h b/trace_streamer/src/filter/animation_filter.h index 3201e06c..177ebbdd 100644 --- a/trace_streamer/src/filter/animation_filter.h +++ b/trace_streamer/src/filter/animation_filter.h @@ -25,6 +25,7 @@ #include "string_help.h" #include "string_to_numerical.h" #include "trace_streamer_filters.h" +#include "config_filter.h" namespace SysTuning { namespace TraceStreamer { @@ -40,6 +41,7 @@ public: bool FinishAnimationEvent(const BytraceLine &line, size_t callStackRow); void UpdateDynamicFrameInfo(); void UpdateFrameInfo(); + void InitAnimationStartEvents(); void Clear(); private: @@ -49,18 +51,7 @@ private: const std::regex framePixPattern_ = std::regex(R"(\[(.*?)\]\s*\(\s*-?(\d+),\s*-?(\d+),\s*(\d+),\s*(\d+)\)\s*Alpha:\s+-*(\d+\.\d+))"); // for calculate the frame rate - const std::string frameRateCmd_ = "H:GenerateVsyncCount"; - // if the realFrameRate present, no calculation is required - const std::string realFrameRateCmd_ = "H:RSJankStats::RecordAnimationDynamicFrameRate"; // 动效过程帧率 - const std::string frameCountCmd_ = "H:Repaint"; - const std::string frameBeginCmd_ = "H:RSUniRender::Process:[WindowScene_"; - const std::string newFrameBeginCmd_ = "H:RSSurfaceRenderNodeDrawable::OnDraw:[WindowScene_"; // 动效帧数据 - const std::string frameBeginPrefix_ = "H:RSUniRender::Process:["; - const std::string screenSizeCmd_ = "H:RSUniRender::Process:[SCBDesktop"; - const std::string newScreenSizeCmd_ = "H:RSSurfaceRenderNodeDrawable::OnDraw:[SCBDesktop"; // 设备分辨率 const std::string frameEndTimeCmd_ = "H:RSMainThread::DoComposition"; - const std::string paralleCmd_ = "H:PostAndWait, parallel type"; // 并行化标志 - const std::string renderFrameCmd_ = "H:RenderFrame"; // 并行化后动效帧结束时间相关trace点 std::unordered_set onAnimationStartEvents_ = {}; // for update dynamicFrameInfo at the end, first is callStackRow, second is dynamicFramRow std::deque callstackWithDynamicFrameRows_ = {}; diff --git a/trace_streamer/src/filter/app_start_filter.cpp b/trace_streamer/src/filter/app_start_filter.cpp index bc9c9244..88f0593e 100644 --- a/trace_streamer/src/filter/app_start_filter.cpp +++ b/trace_streamer/src/filter/app_start_filter.cpp @@ -175,20 +175,20 @@ void APPStartupFilter::ParserAppStartup() auto &nameString = traceDataCache_->GetDataFromDict(sliceData.NamesData()[i]); auto callId = sliceData.CallIds()[i]; auto startTime = sliceData.TimeStampData()[i]; - if (StartWith(nameString, procTouchCmd_)) { + if (streamFilters_->configFilter_->GetAppStartupConfig().CheckIfPhase1(nameString)) { procTouchItems_.emplace_back( std::make_unique(callId, INVALID_UINT32, INVALID_UINT32, startTime, INVALID_UINT64)); - } else if (StartWith(nameString, startUIAbilityBySCBCmd_)) { + } else if (streamFilters_->configFilter_->GetAppStartupConfig().CheckIfPhase2(nameString)) { startUIAbilityBySCBItems_.emplace_back( std::make_unique(callId, INVALID_UINT32, INVALID_UINT32, startTime, INVALID_UINT64)); - } else if (StartWith(nameString, loadAbilityCmd_)) { + } else if (streamFilters_->configFilter_->GetAppStartupConfig().CheckIfPhase3(nameString)) { loadAbilityItems_.emplace_back( std::make_unique(callId, INVALID_UINT32, INVALID_UINT32, startTime, INVALID_UINT64)); - } else if (StartWith(nameString, appLaunchCmd_)) { + } else if (streamFilters_->configFilter_->GetAppStartupConfig().CheckIfPhase4(nameString)) { UpdateAPPStartupData(i, nameString, APPLICATION_LAUNCHING); - } else if (StartWith(nameString, uiLaunchCmd_)) { + } else if (streamFilters_->configFilter_->GetAppStartupConfig().CheckIfPhase5(nameString)) { ProcAbilityLaunchData(nameString, i); - } else if (StartWith(nameString, uiOnForegroundFirstCmd_) || StartWith(nameString, uiOnForegroundSecCmd_)) { + } else if (streamFilters_->configFilter_->GetAppStartupConfig().CheckIfPhase6(nameString)) { ProcForegroundData(i); } } diff --git a/trace_streamer/src/filter/app_start_filter.h b/trace_streamer/src/filter/app_start_filter.h index e91befef..800658d1 100644 --- a/trace_streamer/src/filter/app_start_filter.h +++ b/trace_streamer/src/filter/app_start_filter.h @@ -23,6 +23,7 @@ #include "trace_data_cache.h" #include "trace_streamer_filters.h" #include "ts_common.h" +#include "config_filter.h" namespace SysTuning { namespace TraceStreamer { @@ -81,19 +82,6 @@ private: std::deque> loadAbilityItems_; appMap mAPPStartupData_; std::map mAPPStartupDataWithPid_; - const std::string procTouchCmd_ = "H:client dispatch touchId:"; - const std::string startUIAbilityBySCBCmd_ = - "H:OHOS::ErrCode OHOS::AAFwk::AbilityManagerClient::StartUIAbilityBySCB"; - const std::string loadAbilityCmd_ = "H:virtual void OHOS::AppExecFwk::AppMgrServiceInner::LoadAbility"; - const std::string appLaunchCmd_ = - "H:virtual void OHOS::AppExecFwk::AppMgrServiceInner::AttachApplication(const pid_t, const " - "sptr &)##"; - const std::string uiLaunchCmd_ = - "H:void OHOS::AppExecFwk::MainThread::HandleLaunchAbility(const std::shared_ptr &)##"; - const std::string uiOnForegroundFirstCmd_ = - "H:void OHOS::AbilityRuntime::FAAbilityThread::HandleAbilityTransaction(const OHOS::AbilityRuntime::Want &, " - "const OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##"; - const std::string uiOnForegroundSecCmd_ = "H:void OHOS::AbilityRuntime::UIAbilityThread::HandleAbilityTransaction"; const std::string dlopenCmd_ = "dlopen:"; }; } // namespace TraceStreamer diff --git a/trace_streamer/src/filter/config_filter.cpp b/trace_streamer/src/filter/config_filter.cpp new file mode 100644 index 00000000..d184bb8f --- /dev/null +++ b/trace_streamer/src/filter/config_filter.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "config_filter.h" +namespace SysTuning { +namespace TraceStreamer { +bool CheckIfStartWithKeywords(const std::string &eventName, const std::vector &keywords) +{ + for (auto &keyword : keywords) { + if (StartWith(eventName, keyword)) { + return true; + } + } + return false; +} +bool CheckIfEndWithKeywords(const std::string &eventName, const std::vector &keywords) +{ + for (auto &keyword : keywords) { + if (EndWith(eventName, keyword)) { + return true; + } + } + return false; +} +ConfigFilter::ConfigFilter(TraceDataCache *dataCache, const TraceStreamerFilters *filter) + : FilterBase(dataCache, filter) +{ +} + +ConfigFilter::~ConfigFilter() {} +bool ConfigFilter::SetConfig(const std::string &configFile) +{ + json configResult = json::parse(configFile); + if (configResult.is_discarded()) { + TS_LOGE("Failed to parse config file."); + return false; + } + InitConfig(configResult); + return true; +} +void ConfigFilter::InitConfig(const json &config) +{ + if (config.contains("Animation") && !config["Animation"].empty()) { + animationConfig_ = AnimationConfig(config["Animation"]); + } else { + animationConfig_ = AnimationConfig(); + } + if (config.contains("AppStartup") && !config["AppStartup"].empty()) { + appStartupConfig_ = AppStartupConfig(config["AppStartup"]); + } else { + appStartupConfig_ = AppStartupConfig(); + } + if (config.contains("config") && !config["config"].empty()) { + switchConfig_ = SwitchConfig(config["config"]); + } else { + switchConfig_ = SwitchConfig(); + } + streamFilters_->animationFilter_->InitAnimationStartEvents(); +} +const AnimationConfig &ConfigFilter::GetAnimationConfig() const +{ + return animationConfig_; +} + +const AppStartupConfig &ConfigFilter::GetAppStartupConfig() const +{ + return appStartupConfig_; +} +const SwitchConfig &ConfigFilter::GetSwitchConfig() const +{ + return switchConfig_; +} + +bool AnimationConfig::CheckIfAnimationEvents(const std::string &eventName) const +{ + return CheckIfEndWithKeywords(eventName, animationProcEvents_); +} + +bool AnimationConfig::CheckIfFrameRateCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, frameRateCmd_); +} +bool AnimationConfig::CheckIfRealFrameRateCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, realFrameRateCmd_); +} +bool AnimationConfig::CheckIfFrameCountCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, frameCountCmd_); +} +bool AnimationConfig::CheckIfFrameBeginCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, frameBeginCmd_); +} +bool AnimationConfig::CheckIfScreenSizeCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, screenSizeCmd_); +} +bool AnimationConfig::CheckIfFrameEndTimeCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, frameEndTimeCmd_); +} +bool AnimationConfig::CheckIfParallelCmd(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, parallelCmd_); +} +bool AppStartupConfig::CheckIfPhase1(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, phase1_.start); +} +bool AppStartupConfig::CheckIfPhase2(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, phase2_.start); +} +bool AppStartupConfig::CheckIfPhase3(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, phase3_.start); +} +bool AppStartupConfig::CheckIfPhase4(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, phase4_.start); +} +bool AppStartupConfig::CheckIfPhase5(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, phase5_.start); +} +bool AppStartupConfig::CheckIfPhase6(const std::string &eventName) const +{ + return CheckIfStartWithKeywords(eventName, phase6_.start); +} + +std::vector AnimationConfig::GetOnAnimationStartEvents() const +{ + return onAnimationStartEvents_; +} +SwitchConfig::SwitchConfig(const json &config) +{ + appConfigEnabled_ = config.value("AppStartup", 0) == 1; + animationConfigEnabled_ = config.value("AnimationAnalysis", 0) == 1; + taskPoolConfigEnabled_ = config.value("TaskPool", 0) == 1; + binderRunnableConfigEnabled_ = config.value("BinderRunnable", 0) == 1; + HMKernelTraceEnabled_ = config.value("HMKernel", 0) == 1; + rawTraceCutStartTsEnabled_ = config.value("RawTraceCutStartTs", 0) == 1; + ffrtConvertEnabled_ = config.value("FFRTConvert", 0) == 1; + std::string syscalls = config.at("System Calls"); + UpdateSyscallsTsSet(syscalls); + TS_LOGI( + "appConfigEnabled_=%d, animationConfigEnabled_=%d, taskPoolConfigEnabled_=%d, binderRunnableConfigEnabled_=%d, " + "HMKernelTraceEnabled_=%d, rawTraceCutStartTsEnabled_=%d, ffrtConvertEnabled_=%d, syscalls=%s", + appConfigEnabled_, animationConfigEnabled_, taskPoolConfigEnabled_, binderRunnableConfigEnabled_, + HMKernelTraceEnabled_, rawTraceCutStartTsEnabled_, ffrtConvertEnabled_, syscalls.c_str()); +} +bool SwitchConfig::AppConfigEnabled() const +{ + return appConfigEnabled_; +} +bool SwitchConfig::AnimationConfigEnabled() const +{ + return animationConfigEnabled_; +} +bool SwitchConfig::TaskPoolConfigEnabled() const +{ + return taskPoolConfigEnabled_; +} +bool SwitchConfig::BinderRunnableConfigEnabled() const +{ + return binderRunnableConfigEnabled_; +} +bool SwitchConfig::HMKernelTraceEnabled() const +{ + return HMKernelTraceEnabled_; +} +bool SwitchConfig::RawTraceCutStartTsEnabled() const +{ + return rawTraceCutStartTsEnabled_; +} +bool SwitchConfig::FfrtConfigEnabled() const +{ + return ffrtConvertEnabled_; +} +const std::set &SwitchConfig::SyscallsTsSet() const +{ + return syscallNrSet_; +} +void SwitchConfig::UpdateSyscallsTsSet(const std::string &syscalls) +{ + std::stringstream ss(syscalls); + std::string token; + + syscallNrSet_.clear(); + while (std::getline(ss, token, ';')) { + syscallNrSet_.insert(std::stoi(token)); + } +} +} // namespace TraceStreamer +} // namespace SysTuning diff --git a/trace_streamer/src/filter/config_filter.h b/trace_streamer/src/filter/config_filter.h new file mode 100644 index 00000000..4e405f5e --- /dev/null +++ b/trace_streamer/src/filter/config_filter.h @@ -0,0 +1,159 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CONFIG_FILTER_H +#define CONFIG_FILTER_H +#include +#include +#include +#include +#include +#include +#include "string_help.h" +#include "filter_base.h" +#include "trace_data_cache.h" +#include "trace_streamer_config.h" +#include "trace_streamer_filters.h" +#include "animation_filter.h" +namespace SysTuning { +namespace TraceStreamer { +using namespace SysTuning::base; +using json = nlohmann::json; +bool CheckIfStartWithKeywords(const std::string &eventName, const std::vector &keywords); +bool CheckIfEndWithKeywords(const std::string &eventName, const std::vector &keywords); +class AnimationConfig { +public: + AnimationConfig() = default; + AnimationConfig(const json &config) + { + animationProcEvents_ = config.value("animationProcEvents_", std::vector{}); + onAnimationStartEvents_ = config.value("onAnimationStartEvents_", std::vector{}); + frameRateCmd_ = config.value("frameRateCmd_", std::vector{}); + realFrameRateCmd_ = config.value("realFrameRateCmd_", std::vector{}); + frameCountCmd_ = config.value("frameCountCmd_", std::vector{}); + frameBeginCmd_ = config.value("frameBeginCmd_", std::vector{}); + screenSizeCmd_ = config.value("screenSizeCmd_", std::vector{}); + frameEndTimeCmd_ = config.value("frameEndTimeCmd_", std::vector{}); + parallelCmd_ = config.value("parallelCmd_", std::vector{}); + } + ~AnimationConfig() = default; + std::vector GetOnAnimationStartEvents() const; + bool CheckIfAnimationEvents(const std::string &eventName) const; + bool CheckIfFrameRateCmd(const std::string &eventName) const; + bool CheckIfRealFrameRateCmd(const std::string &eventName) const; + bool CheckIfFrameCountCmd(const std::string &eventName) const; + bool CheckIfFrameBeginCmd(const std::string &eventName) const; + bool CheckIfScreenSizeCmd(const std::string &eventName) const; + bool CheckIfFrameEndTimeCmd(const std::string &eventName) const; + bool CheckIfParallelCmd(const std::string &eventName) const; + +private: + std::vector animationProcEvents_; + std::vector onAnimationStartEvents_; + std::vector frameRateCmd_; + std::vector realFrameRateCmd_; + std::vector frameCountCmd_; + std::vector frameBeginCmd_; + std::vector screenSizeCmd_; + std::vector frameEndTimeCmd_; + std::vector parallelCmd_; +}; +struct StartUpPhase { + std::string pName; + std::vector start; + std::vector end; +}; +class AppStartupConfig { +public: + AppStartupConfig() = default; + AppStartupConfig(const json &config) + { + phase1_ = GetPhaseValue(config, "phase1"); + phase2_ = GetPhaseValue(config, "phase2"); + phase3_ = GetPhaseValue(config, "phase3"); + phase4_ = GetPhaseValue(config, "phase4"); + phase5_ = GetPhaseValue(config, "phase5"); + phase6_ = GetPhaseValue(config, "phase6"); + } + ~AppStartupConfig() = default; + bool CheckIfPhase1(const std::string &eventName) const; + bool CheckIfPhase2(const std::string &eventName) const; + bool CheckIfPhase3(const std::string &eventName) const; + bool CheckIfPhase4(const std::string &eventName) const; + bool CheckIfPhase5(const std::string &eventName) const; + bool CheckIfPhase6(const std::string &eventName) const; + +private: + StartUpPhase GetPhaseValue(const json &phaseConfig, const std::string &phaseName) + { + auto phaseContent = phaseConfig.value(phaseName, json::object()); + return {phaseContent.value("pName", ""), phaseContent.value("start", std::vector{}), + phaseContent.value("end", std::vector{})}; + } + StartUpPhase phase1_; + StartUpPhase phase2_; + StartUpPhase phase3_; + StartUpPhase phase4_; + StartUpPhase phase5_; + StartUpPhase phase6_; +}; + +class SwitchConfig { +public: + SwitchConfig() = default; + SwitchConfig(const json &config); + ~SwitchConfig() = default; + bool AppConfigEnabled() const; + bool AnimationConfigEnabled() const; + bool TaskPoolConfigEnabled() const; + bool BinderRunnableConfigEnabled() const; + bool HMKernelTraceEnabled() const; + bool RawTraceCutStartTsEnabled() const; + bool FfrtConfigEnabled() const; + const std::set &SyscallsTsSet() const; + +private: + void UpdateSyscallsTsSet(const std::string &syscalls); + +private: + bool appConfigEnabled_ = false; + bool animationConfigEnabled_ = false; + bool taskPoolConfigEnabled_ = false; + bool binderRunnableConfigEnabled_ = false; + bool HMKernelTraceEnabled_ = false; + bool rawTraceCutStartTsEnabled_ = false; + bool ffrtConvertEnabled_ = false; + std::set syscallNrSet_; +}; +class ConfigFilter : private FilterBase { +public: + ConfigFilter(TraceDataCache *dataCache, const TraceStreamerFilters *filter); + ConfigFilter(const ConfigFilter &) = delete; + ConfigFilter &operator=(const ConfigFilter &) = delete; + ~ConfigFilter() override; + bool SetConfig(const std::string &configFile); + const AnimationConfig &GetAnimationConfig() const; + const AppStartupConfig &GetAppStartupConfig() const; + const SwitchConfig &GetSwitchConfig() const; + +private: + AnimationConfig animationConfig_; + AppStartupConfig appStartupConfig_; + SwitchConfig switchConfig_; + void InitConfig(const json &config); +}; +} // namespace TraceStreamer +} // namespace SysTuning +#endif // CONFIG_FILTER_H diff --git a/trace_streamer/src/filter/cpu_filter.cpp b/trace_streamer/src/filter/cpu_filter.cpp index a280fcb8..93dcad60 100644 --- a/trace_streamer/src/filter/cpu_filter.cpp +++ b/trace_streamer/src/filter/cpu_filter.cpp @@ -69,7 +69,7 @@ void CpuFilter::ProcPrevPidSwitchEvent(uint64_t ts, auto lastState = traceDataCache_->GetConstThreadStateData().StatesData()[lastRow]; auto lastStartTs = traceDataCache_->GetConstThreadStateData().TimeStampData()[lastRow]; if ((cpu != lastCpu) && (lastState == TASK_RUNNING)) { - if (traceDataCache_->HMKernelTraceEnabled() || (ts == lastStartTs)) { + if (streamFilters_->configFilter_->GetSwitchConfig().HMKernelTraceEnabled() || (ts == lastStartTs)) { isChangeCpu = true; } } @@ -128,7 +128,8 @@ void CpuFilter::InsertSwitchEvent(uint64_t ts, if (prevPid) { ProcPrevPidSwitchEvent(ts, cpu, prevPid, prevState, btInfo); } - if (traceDataCache_->BinderRunnableTraceEnabled() && iTidToTransaction_.find(prevPid) != iTidToTransaction_.end()) { + if (streamFilters_->configFilter_->GetSwitchConfig().BinderRunnableConfigEnabled() && + iTidToTransaction_.find(prevPid) != iTidToTransaction_.end()) { uint64_t transactionId = iTidToTransaction_.at(prevPid); auto iter = transactionIdToInfo_.find(transactionId); if (prevState != TASK_NEW || iter == transactionIdToInfo_.end() || iter->second.iTidFrom != prevPid || diff --git a/trace_streamer/src/filter/cpu_filter.h b/trace_streamer/src/filter/cpu_filter.h index 2e9c25bd..3fd0b091 100644 --- a/trace_streamer/src/filter/cpu_filter.h +++ b/trace_streamer/src/filter/cpu_filter.h @@ -27,6 +27,7 @@ #include "trace_data_cache.h" #include "trace_streamer_filters.h" #include "ts_common.h" +#include "config_filter.h" namespace SysTuning { namespace TraceStreamer { diff --git a/trace_streamer/src/filter/slice_filter.cpp b/trace_streamer/src/filter/slice_filter.cpp index 0e14097f..63394dce 100644 --- a/trace_streamer/src/filter/slice_filter.cpp +++ b/trace_streamer/src/filter/slice_filter.cpp @@ -325,12 +325,9 @@ size_t SliceFilter::StartSlice(uint64_t timeStamp, uint32_t depth = stack.size(); auto slices = traceDataCache_->GetInternalSlicesData(); uint32_t parentId = depth == 0 ? INVALID_UINT32 : slices->IdsData()[stack.back().index]; - CallStackInternalRow callStackInternalRow = {sliceData.timeStamp, - static_cast(sliceData.duration), - sliceData.internalTid, - sliceData.cat, - sliceData.name, - 0, + CallStackInternalRow callStackInternalRow = {sliceData.timeStamp, static_cast(sliceData.duration), + sliceData.internalTid, sliceData.cat, + sliceData.name, 0, INVALID_UINT32}; size_t index = slices->AppendInternalSlice(callStackInternalRow, parentId); if (depth >= std::numeric_limits::max()) { @@ -469,8 +466,8 @@ uint64_t SliceFilter::StartAsyncSlice(uint64_t timeStamp, // do not mean the parent-to-child relationship, it is different from no-async call uint8_t depth = 0; uint32_t childCallid = parentId; - CallStackInternalRow callStackInternalRow = {timeStamp, static_cast(-1), internalTid, cat, nameIndex, - depth, childCallid}; + CallStackInternalRow callStackInternalRow = { + timeStamp, static_cast(-1), internalTid, cat, nameIndex, depth, childCallid}; size_t index = slices->AppendInternalAsyncSlice(callStackInternalRow, cookie, parentId); asyncEventFilterMap_.insert(std::make_pair(asyncEventSize_, AsyncEvent{timeStamp, index})); return index; diff --git a/trace_streamer/src/filter/syscall_filter.cpp b/trace_streamer/src/filter/syscall_filter.cpp index 2ded33ec..5f0f4907 100644 --- a/trace_streamer/src/filter/syscall_filter.cpp +++ b/trace_streamer/src/filter/syscall_filter.cpp @@ -15,6 +15,7 @@ #include "syscall_filter.h" +#include "config_filter.h" #include "process_filter.h" namespace SysTuning { @@ -27,23 +28,27 @@ SyscallFilter::~SyscallFilter() {} void SyscallFilter::UpdataSyscallEnterExitMap(const SyscallInfoRow &syscallInfoRow) { - TS_LOGI("SysEnterEvent: SysEnter ID %u", syscallInfoRow.number); - auto key = std::make_pair(syscallInfoRow.itid, syscallInfoRow.number); - syscallEnterExitMap_[key] = syscallInfoRow; + TS_LOGD("SysEnterEvent: SysEnter ID %u", syscallInfoRow.number); + const auto &syscallNrSet = streamFilters_->configFilter_->GetSwitchConfig().SyscallsTsSet(); + if (syscallNrSet.find(syscallInfoRow.number) == syscallNrSet.end()) { + return; + } + syscallEnterExitMap_[syscallInfoRow.itid] = syscallInfoRow; } void SyscallFilter::AppendSysCallInfo(uint32_t pid, uint32_t syscallNr, uint64_t ts, int64_t ret) { - TS_LOGI("SysExitEvent: SysEnter ID %u", syscallNr); - auto key = std::make_pair(pid, syscallNr); - auto syscallEnterExitItor = syscallEnterExitMap_.find(key); - if (syscallEnterExitItor != syscallEnterExitMap_.end() && syscallEnterExitItor->second.ts <= ts) { - uint64_t dur = ts - syscallEnterExitItor->second.ts; - syscallEnterExitItor->second.dur = dur; - syscallEnterExitItor->second.ret = ret; - syscallEnterExitItor->second.itid = streamFilters_->processFilter_->UpdateOrCreateThread(ts, pid); - traceDataCache_->GetSysCallData()->AppendSysCallData(syscallEnterExitItor->second); - syscallEnterExitMap_.erase(key); + TS_LOGD("SysExitEvent: SysEnter ID %u", syscallNr); + auto syscallEnterExitItor = syscallEnterExitMap_.find(pid); + if (syscallEnterExitItor != syscallEnterExitMap_.end()) { + auto &syscallInfoRow = syscallEnterExitItor->second; + if (syscallInfoRow.number == syscallNr && syscallInfoRow.ts <= ts) { + syscallInfoRow.dur = ts - syscallInfoRow.ts; + syscallInfoRow.ret = ret; + syscallInfoRow.itid = streamFilters_->processFilter_->UpdateOrCreateThread(ts, pid); + traceDataCache_->GetSysCallData()->AppendSysCallData(syscallInfoRow); + } + syscallEnterExitMap_.erase(pid); } else { TS_LOGW("SysExitEvent: No matching sysExit event found for syscallID = %u.", syscallNr); } diff --git a/trace_streamer/src/filter/syscall_filter.h b/trace_streamer/src/filter/syscall_filter.h index 93206ecf..9771bfc5 100644 --- a/trace_streamer/src/filter/syscall_filter.h +++ b/trace_streamer/src/filter/syscall_filter.h @@ -36,7 +36,7 @@ public: void Clear(); private: - std::map, SyscallInfoRow> syscallEnterExitMap_; + std::map syscallEnterExitMap_; }; } // namespace TraceStreamer } // namespace SysTuning diff --git a/trace_streamer/src/parser/hiperf_parser/perf_data_parser.cpp b/trace_streamer/src/parser/hiperf_parser/perf_data_parser.cpp index 548e0cdc..265feaa7 100644 --- a/trace_streamer/src/parser/hiperf_parser/perf_data_parser.cpp +++ b/trace_streamer/src/parser/hiperf_parser/perf_data_parser.cpp @@ -723,7 +723,7 @@ uint32_t PerfDataParser::UpdateCallChainUnCompressed(const PerfRecordSample *sam callChainId = ++callChainId_; pidAndStackHashToCallChainId_.Insert(pid, stackHash, callChainId); callChainIdToThreadInfo_.insert({callChainId, std::make_tuple(pid, sample->data_.tid)}); -uint32_t depth = 0; + uint32_t depth = 0; for (auto frame = sample->callFrames_.rbegin(); frame != sample->callFrames_.rend(); ++frame) { uint64_t fileId = INVALID_UINT64; auto fileDataIndex = traceDataCache_->dataDict_.GetStringIndex(frame->mapName); diff --git a/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp b/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp index 9f8efdfe..d68371a7 100644 --- a/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp +++ b/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp @@ -498,7 +498,8 @@ bool HtraceEventParser::BinderTractionEvent(const EventInfo &event) const destTid, transactionId, isReply, flags, msg.code()); streamFilters_->binderFilter_->SendTraction(event.timeStamp, event.pid, transactionId, destNode, destTgid, destTid, isReply, flags, msg.code()); - if (traceDataCache_->BinderRunnableTraceEnabled() && !streamFilters_->binderFilter_->IsAsync(flags)) { + if (streamFilters_->configFilter_->GetSwitchConfig().BinderRunnableConfigEnabled() && + !streamFilters_->binderFilter_->IsAsync(flags)) { streamFilters_->cpuFilter_->InsertRunnableBinderEvent( transactionId, streamFilters_->processFilter_->GetInternalTid(event.pid)); } @@ -510,7 +511,7 @@ bool HtraceEventParser::BinderTractionReceivedEvent(const EventInfo &event) cons ProtoReader::BinderTransactionReceivedFormat_Reader msg(event.detail); int32_t transactionId = msg.debug_id(); streamFilters_->binderFilter_->ReceiveTraction(event.timeStamp, event.pid, transactionId); - if (traceDataCache_->BinderRunnableTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().BinderRunnableConfigEnabled()) { streamFilters_->cpuFilter_->InsertRunnableBinderRecvEvent( transactionId, streamFilters_->processFilter_->GetInternalTid(event.pid)); } @@ -993,20 +994,41 @@ bool HtraceEventParser::DmaFenceSignaledEvent(const EventInfo &event) const } bool HtraceEventParser::SysEnterEvent(const EventInfo &event) const { - streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_RECEIVED); + if (streamFilters_->configFilter_->GetSwitchConfig().SyscallsTsSet().empty()) { + return true; + } ProtoReader::SysEnterFormat_Reader msg(event.detail); SyscallInfoRow syscallInfoRow; syscallInfoRow.ts = event.timeStamp; syscallInfoRow.itid = event.pid; syscallInfoRow.number = msg.id(); + // if (msg.has_args()) { + // bool parseErrorInfo = false; + // auto eventItor = msg.args(&parseErrorInfo); + // std::ostringstream oss; + // oss << "("; + // while (eventItor) { + // oss << std::hex << std::nouppercase << *eventItor; + // eventItor++; + // if (eventItor) { + // oss << ", "; + // } + // } + // oss << ")"; + // syscallInfoRow.args = traceDataCache_->GetDataIndex(oss.str()); + // } streamFilters_->syscallFilter_->UpdataSyscallEnterExitMap(syscallInfoRow); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_RECEIVED); return true; } bool HtraceEventParser::SysExitEvent(const EventInfo &event) const { - streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_EXIT, STAT_EVENT_RECEIVED); + if (streamFilters_->configFilter_->GetSwitchConfig().SyscallsTsSet().empty()) { + return true; + } ProtoReader::SysExitFormat_Reader msg(event.detail); streamFilters_->syscallFilter_->AppendSysCallInfo(event.pid, msg.id(), event.timeStamp, msg.ret()); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_EXIT, STAT_EVENT_RECEIVED); return true; } @@ -1070,7 +1092,7 @@ void HtraceEventParser::FilterAllEvents() streamFilters_->cpuFilter_->Finish(); traceDataCache_->dataDict_.Finish(); traceDataCache_->UpdataZeroThreadInfo(); - if (traceDataCache_->AppStartTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().AppConfigEnabled()) { streamFilters_->appStartupFilter_->FilterAllAPPStartupData(); } traceDataCache_->GetThreadStateData()->SortAllRowByTs(); diff --git a/trace_streamer/src/parser/print_event_parser.cpp b/trace_streamer/src/parser/print_event_parser.cpp index 6d324cbb..19f78d28 100644 --- a/trace_streamer/src/parser/print_event_parser.cpp +++ b/trace_streamer/src/parser/print_event_parser.cpp @@ -116,10 +116,10 @@ void PrintEventParser::ParseBeginEvent(const std::string &comm, return; } bool isDiscontinued = false; - if (traceDataCache_->TaskPoolTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().TaskPoolConfigEnabled()) { isDiscontinued = streamFilters_->taskPoolFilter_->TaskPoolEvent(point.name_, index); } - if (traceDataCache_->AnimationTraceEnabled() && !isDiscontinued) { + if (streamFilters_->configFilter_->GetSwitchConfig().AnimationConfigEnabled() && !isDiscontinued) { (void)HandleAnimationBeginEvent(point, index, line); } } else { @@ -130,7 +130,7 @@ void PrintEventParser::ParseEndEvent(uint64_t ts, uint32_t pid, const TracePoint { uint32_t index = streamFilters_->sliceFilter_->EndSlice(ts, pid, point.tgid_); HandleFrameSliceEndEvent(ts, point.tgid_, pid, index); - if (traceDataCache_->AnimationTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().AnimationConfigEnabled()) { streamFilters_->animationFilter_->EndDynamicFrameEvent(ts, index); } } @@ -152,9 +152,9 @@ void PrintEventParser::ParseStartEvent(const std::string &comm, if (point.name_ == onFrameQueeuStartEvent_) { OnFrameQueueStart(ts, index, point.tgid_); - } else if (traceDataCache_->AnimationTraceEnabled() && - (base::EndWith(comm, onAnimationProcEvent_) || - base::EndWith(comm, newOnAnimationProcEvent_))) { // the comm is taskName + } else if (streamFilters_->configFilter_->GetSwitchConfig().AnimationConfigEnabled() && index != INVALID_UINT64 && + streamFilters_->configFilter_->GetAnimationConfig().CheckIfAnimationEvents( + comm)) { // the comm is taskName streamFilters_->animationFilter_->StartAnimationEvent(line, point, index); } } @@ -164,7 +164,7 @@ void PrintEventParser::ParseFinishEvent(uint64_t ts, uint32_t pid, const TracePo auto index = streamFilters_->sliceFilter_->FinishAsyncSlice(ts, pid, point.tgid_, cookie, traceDataCache_->GetDataIndex(point.name_)); HandleFrameQueueEndEvent(ts, point.tgid_, point.tgid_, index); - if (traceDataCache_->AnimationTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().AnimationConfigEnabled()) { streamFilters_->animationFilter_->FinishAnimationEvent(line, index); } } diff --git a/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp b/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp index 71978acc..2722273a 100644 --- a/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp +++ b/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp @@ -195,17 +195,21 @@ void BytraceEventParser::StackEventsInitialization() bool BytraceEventParser::SysEnterEvent(const ArgsMap &args, const BytraceLine &line) { + if (streamFilters_->configFilter_->GetSwitchConfig().SyscallsTsSet().empty()) { + return true; + } Unused(args); - streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_RECEIVED); std::string sysEnterStr = base::Strip(line.argsStr); if (sysEnterStr.empty()) { TS_LOGD("SysEnterEvent: Empty args string for sysEnterStr, skipping."); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_DATA_INVALID); return true; } auto firstSpacePos = sysEnterStr.find(" "); if (firstSpacePos == std::string::npos) { TS_LOGD("SysEnterEvent: No space found in sysEnterStr: '%s', skipping.", sysEnterStr.c_str()); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_DATA_INVALID); return true; } @@ -226,22 +230,27 @@ bool BytraceEventParser::SysEnterEvent(const ArgsMap &args, const BytraceLine &l syscallInfoRow.args = argsDataIndex; syscallInfoRow.number = syscallNumber; streamFilters_->syscallFilter_->UpdataSyscallEnterExitMap(syscallInfoRow); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_RECEIVED); return true; } bool BytraceEventParser::SysExitEvent(const ArgsMap &args, const BytraceLine &line) { + if (streamFilters_->configFilter_->GetSwitchConfig().SyscallsTsSet().empty()) { + return true; + } Unused(args); - streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_EXIT, STAT_EVENT_RECEIVED); std::string sysExitStr = base::Strip(line.argsStr); if (sysExitStr.empty()) { TS_LOGD("SysExitEvent: Empty args string for sysExitStr, skipping."); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_EXIT, STAT_EVENT_DATA_INVALID); return true; } auto firstSpacePos = sysExitStr.find(" "); if (firstSpacePos == std::string::npos) { TS_LOGD("SysExitEvent: No space found in sysExitStr: '%s', skipping.", sysExitStr.c_str()); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_EXIT, STAT_EVENT_DATA_INVALID); return true; } @@ -256,6 +265,7 @@ bool BytraceEventParser::SysExitEvent(const ArgsMap &args, const BytraceLine &li uint32_t sysExitId = std::atoi(sysExitStr.substr(firstSpacePos, secondSpacePos).c_str()); streamFilters_->syscallFilter_->AppendSysCallInfo(line.pid, sysExitId, line.ts, ret); + streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_RECEIVED); return true; } @@ -778,8 +788,8 @@ bool BytraceEventParser::BinderTransaction(const ArgsMap &args, const BytraceLin streamFilters_->binderFilter_->SendTraction(line.ts, line.pid, transactionId.value(), destNode.value(), destProc.value(), destThread.value(), isReply.value(), flags.value(), codeStr.value()); - if (traceDataCache_->BinderRunnableTraceEnabled() && transactionId.has_value() && flags.has_value() && - !streamFilters_->binderFilter_->IsAsync(flags.value())) { + if (streamFilters_->configFilter_->GetSwitchConfig().BinderRunnableConfigEnabled() && transactionId.has_value() && + flags.has_value() && !streamFilters_->binderFilter_->IsAsync(flags.value())) { streamFilters_->cpuFilter_->InsertRunnableBinderEvent(transactionId.value(), streamFilters_->processFilter_->GetInternalTid(line.pid)); } @@ -795,7 +805,7 @@ bool BytraceEventParser::BinderTransactionReceived(const ArgsMap &args, const By streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_BINDER_TRANSACTION_RECEIVED, STAT_EVENT_RECEIVED); auto transactionId = base::StrToInt(args.at("transaction")); streamFilters_->binderFilter_->ReceiveTraction(line.ts, line.pid, transactionId.value()); - if (traceDataCache_->BinderRunnableTraceEnabled() && transactionId.has_value()) { + if (streamFilters_->configFilter_->GetSwitchConfig().BinderRunnableConfigEnabled() && transactionId.has_value()) { streamFilters_->cpuFilter_->InsertRunnableBinderRecvEvent( transactionId.value(), streamFilters_->processFilter_->GetInternalTid(line.pid)); } @@ -892,7 +902,7 @@ void BytraceEventParser::FilterAllEvents() streamFilters_->cpuFilter_->Finish(); traceDataCache_->dataDict_.Finish(); traceDataCache_->UpdataZeroThreadInfo(); - if (traceDataCache_->AppStartTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().AppConfigEnabled()) { streamFilters_->appStartupFilter_->FilterAllAPPStartupData(); } traceDataCache_->GetThreadStateData()->SortAllRowByTs(); diff --git a/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp b/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp index 801a81f8..108f1db6 100644 --- a/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp +++ b/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp @@ -244,7 +244,7 @@ void CpuDetailParser::FinishCpuDetailParser() streamFilters_->cpuFilter_->Finish(); traceDataCache_->dataDict_.Finish(); traceDataCache_->UpdataZeroThreadInfo(); - if (traceDataCache_->AppStartTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().AppConfigEnabled()) { streamFilters_->appStartupFilter_->FilterAllAPPStartupData(); } Clear(); diff --git a/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.cpp b/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.cpp index bc7e3cf0..4811a53c 100644 --- a/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.cpp +++ b/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.cpp @@ -46,7 +46,7 @@ void RawTraceParser::WaitForParserEnd() } void RawTraceParser::UpdateTraceMinRange() { - if (!traceDataCache_->RawTraceCutStartTsEnabled()) { + if (!streamFilters_->configFilter_->GetSwitchConfig().RawTraceCutStartTsEnabled()) { return; } auto schedSlice = traceDataCache_->GetConstSchedSliceData(); diff --git a/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.h b/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.h index e9838364..e9661956 100644 --- a/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.h +++ b/trace_streamer/src/parser/rawtrace_parser/rawtrace_parser.h @@ -21,6 +21,7 @@ #include "ftrace_processor.h" #include "kernel_symbols_processor.h" #include "trace_data_cache.h" +#include "config_filter.h" namespace SysTuning { namespace TraceStreamer { diff --git a/trace_streamer/src/rpc/rpc_server.cpp b/trace_streamer/src/rpc/rpc_server.cpp index 4e8195bf..39dc4f49 100644 --- a/trace_streamer/src/rpc/rpc_server.cpp +++ b/trace_streamer/src/rpc/rpc_server.cpp @@ -839,13 +839,8 @@ bool RpcServer::ParserConfig(std::string parserConfigJson) { json jMessage = json::parse(parserConfigJson); jsonns::ParserConfig parserConfig = jMessage.at("config"); - ts_->UpdateAppStartTraceStatus(parserConfig.appConfigValue); - ts_->UpdateAnimationTraceStatus(parserConfig.aniConfigValue); - ts_->UpdateTaskPoolTraceStatus(parserConfig.taskConfigValue); - ts_->UpdateBinderRunnableTraceStatus(parserConfig.binderConfigValue); - ts_->UpdateHMKernelTraceStatus(parserConfig.HMKernelConfigValue); - ts_->UpdateRawTraceCutStartTsStatus(parserConfig.rawTraceCutStartTsValue); - ffrtConvertEnabled_ = parserConfig.ffrtConvertConfigValue; + ts_->SetConfigFile(parserConfigJson); + ffrtConvertEnabled_ = ts_->GetFfrtConfig(); startParseTime_ = (std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch())) .count(); diff --git a/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.cpp b/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.cpp index 3094cee0..70a402b6 100644 --- a/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.cpp +++ b/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.cpp @@ -15,7 +15,7 @@ #include "syscall_stdtype.h" namespace SysTuning { namespace TraceStdtype { -size_t SysCall::AppendSysCallData(const SyscallInfoRow& syscallInfoRow) +size_t SysCall::AppendSysCallData(const SyscallInfoRow &syscallInfoRow) { sysCallNumbers_.emplace_back(syscallInfoRow.number); timeStamps_.emplace_back(syscallInfoRow.ts); diff --git a/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.h b/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.h index e0834b94..5e85ad52 100644 --- a/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.h +++ b/trace_streamer/src/trace_data/trace_stdtype/ftrace/syscall_stdtype.h @@ -29,7 +29,7 @@ struct SyscallInfoRow { }; class SysCall : public CacheBase, public BatchCacheBase { public: - size_t AppendSysCallData(const SyscallInfoRow& syscallNrInfoRow); + size_t AppendSysCallData(const SyscallInfoRow &syscallNrInfoRow); const std::deque &SysCallNumbersData() const { return sysCallNumbers_; diff --git a/trace_streamer/src/trace_streamer/trace_streamer_filters.cpp b/trace_streamer/src/trace_streamer/trace_streamer_filters.cpp index 590125c3..734bc852 100644 --- a/trace_streamer/src/trace_streamer/trace_streamer_filters.cpp +++ b/trace_streamer/src/trace_streamer/trace_streamer_filters.cpp @@ -34,6 +34,7 @@ #include "syscall_filter.h" #include "system_event_measure_filter.h" #include "task_pool_filter.h" +#include "config_filter.h" namespace SysTuning { namespace TraceStreamer { diff --git a/trace_streamer/src/trace_streamer/trace_streamer_filters.h b/trace_streamer/src/trace_streamer/trace_streamer_filters.h index b82a2218..d4667c28 100644 --- a/trace_streamer/src/trace_streamer/trace_streamer_filters.h +++ b/trace_streamer/src/trace_streamer/trace_streamer_filters.h @@ -32,6 +32,7 @@ class ArgsFilter; class IrqFilter; class SyscallFilter; class SystemEventMeasureFilter; +class ConfigFilter; #ifdef ENABLE_HISYSEVENT class HiSysEventMeasureFilter; #endif @@ -61,6 +62,7 @@ public: std::unique_ptr sysEventMemMeasureFilter_; std::unique_ptr sysEventVMemMeasureFilter_; std::unique_ptr sysEventSourceFilter_; + std::unique_ptr configFilter_; #ifdef ENABLE_HISYSEVENT std::unique_ptr hiSysEventMeasureFilter_; #endif diff --git a/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp b/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp index 4bb54b5f..393f6957 100644 --- a/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp +++ b/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp @@ -30,6 +30,7 @@ #include "file.h" #include "filter_filter.h" #include "frame_filter.h" +#include "config_filter.h" #ifdef ENABLE_HISYSEVENT #include "hi_sysevent_measure_filter.h" #endif @@ -145,6 +146,7 @@ void TraceStreamerSelector::InitFilter() { streamFilters_ = std::make_unique(); traceDataCache_ = std::make_unique(); + streamFilters_->configFilter_ = std::make_unique(traceDataCache_.get(), streamFilters_.get()); streamFilters_->animationFilter_ = std::make_unique(traceDataCache_.get(), streamFilters_.get()); streamFilters_->cpuFilter_ = std::make_unique(traceDataCache_.get(), streamFilters_.get()); streamFilters_->sliceFilter_ = std::make_unique(traceDataCache_.get(), streamFilters_.get()); @@ -174,6 +176,9 @@ void TraceStreamerSelector::InitFilter() std::make_unique(traceDataCache_.get(), streamFilters_.get()); #endif streamFilters_->taskPoolFilter_ = std::make_unique(traceDataCache_.get(), streamFilters_.get()); +#if !IS_WASM + GetConfigFile(); +#endif } void TraceStreamerSelector::WaitForParserEnd() @@ -197,7 +202,7 @@ void TraceStreamerSelector::WaitForParserEnd() } #endif traceDataCache_->UpdateTraceRange(); - if (traceDataCache_->AnimationTraceEnabled()) { + if (streamFilters_->configFilter_->GetSwitchConfig().AnimationConfigEnabled()) { streamFilters_->animationFilter_->UpdateFrameInfo(); streamFilters_->animationFilter_->UpdateDynamicFrameInfo(); } @@ -205,7 +210,17 @@ void TraceStreamerSelector::WaitForParserEnd() ComputeDataDictStrHash(); #endif } - +void TraceStreamerSelector ::GetConfigFile() +{ + std::ifstream configReading("config/config.json"); + if (!configReading.is_open()) { + TS_LOGE("Open config file failed!Please make sure that config/config.json exists."); + return; + } + std::stringstream buffer; + buffer << configReading.rdbuf(); + streamFilters_->configFilter_->SetConfig(buffer.str()); +} MetaData *TraceStreamerSelector::GetMetaData() { return traceDataCache_->GetMetaData(); @@ -532,6 +547,14 @@ void TraceStreamerSelector::UpdateRawTraceCutStartTsStatus(bool status) { traceDataCache_->UpdateRawTraceCutStartTsStatus(status); } +void TraceStreamerSelector::SetConfigFile(std::string &filePath) +{ + streamFilters_->configFilter_->SetConfig(filePath); +} +bool TraceStreamerSelector::GetFfrtConfig() +{ + return streamFilters_->configFilter_->GetSwitchConfig().FfrtConfigEnabled(); +} bool TraceStreamerSelector::LoadQueryFile(const std::string &sqlOperator, std::vector &sqlStrings) { std::ifstream file(sqlOperator); diff --git a/trace_streamer/src/trace_streamer/trace_streamer_selector.h b/trace_streamer/src/trace_streamer/trace_streamer_selector.h index 3187a817..bc8d4786 100644 --- a/trace_streamer/src/trace_streamer/trace_streamer_selector.h +++ b/trace_streamer/src/trace_streamer/trace_streamer_selector.h @@ -71,6 +71,9 @@ public: void UpdateHMKernelTraceStatus(bool status); void UpdateRawTraceCutStartTsStatus(bool status); void InitMetricsMap(std::map &metricsMap); + void SetConfigFile(std::string &filePath); + bool GetFfrtConfig(); + void GetConfigFile(); const std::string MetricsSqlQuery(const std::string &metrics); auto GetPtreaderParser() { diff --git a/trace_streamer/src/version.cpp b/trace_streamer/src/version.cpp index 7b3d690b..98b29dd9 100644 --- a/trace_streamer/src/version.cpp +++ b/trace_streamer/src/version.cpp @@ -17,7 +17,7 @@ namespace SysTuning { namespace TraceStreamer { size_t g_loadSize = 0; size_t g_fileSize = 0; -const std::string TRACE_STREAMER_VERSION = "4.3.4"; // version -const std::string TRACE_STREAMER_PUBLISH_VERSION = "2025/5/9"; // publish datetime +const std::string TRACE_STREAMER_VERSION = "4.3.5"; // version +const std::string TRACE_STREAMER_PUBLISH_VERSION = "2025/5/15"; // publish datetime } // namespace TraceStreamer } // namespace SysTuning -- Gitee From 9cd61ac3d1ac4a174a95f562d514485707b5d6b3 Mon Sep 17 00:00:00 2001 From: zhangzhuozhou Date: Fri, 11 Jul 2025 15:23:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzhuozhou --- .../htrace_parser/htrace_event_parser.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp b/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp index d68371a7..d78ac448 100644 --- a/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp +++ b/trace_streamer/src/parser/pbreader_parser/htrace_parser/htrace_event_parser.cpp @@ -1002,21 +1002,6 @@ bool HtraceEventParser::SysEnterEvent(const EventInfo &event) const syscallInfoRow.ts = event.timeStamp; syscallInfoRow.itid = event.pid; syscallInfoRow.number = msg.id(); - // if (msg.has_args()) { - // bool parseErrorInfo = false; - // auto eventItor = msg.args(&parseErrorInfo); - // std::ostringstream oss; - // oss << "("; - // while (eventItor) { - // oss << std::hex << std::nouppercase << *eventItor; - // eventItor++; - // if (eventItor) { - // oss << ", "; - // } - // } - // oss << ")"; - // syscallInfoRow.args = traceDataCache_->GetDataIndex(oss.str()); - // } streamFilters_->syscallFilter_->UpdataSyscallEnterExitMap(syscallInfoRow); streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_SYS_ENTRY, STAT_EVENT_RECEIVED); return true; -- Gitee