1 /*
2 * Copyright (c) 2025 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
16 #include "base/perfmonitor/perf_interfaces.h"
17
18 #include "adapter/ohos/entrance/ace_container.h"
19 #include "core/common/ace_application_info.h"
20 #include "perf_monitor_adapter.h"
21 #include "xcollie/watchdog.h"
22
23 namespace OHOS::Ace {
24
25 using PerfMonitorAdapter = OHOS::HiviewDFX::PerfMonitorAdapter;
26
GetAceAppInfo()27 OHOS::HiviewDFX::AceAppInfo GetAceAppInfo()
28 {
29 OHOS::HiviewDFX::AceAppInfo appInfo;
30 appInfo.pid = AceApplicationInfo::GetInstance().GetPid();
31 appInfo.bundleName = Container::CurrentBundleName();
32 appInfo.versionCode = static_cast<int32_t>(AceApplicationInfo::GetInstance().GetAppVersionCode());
33 appInfo.versionName = AceApplicationInfo::GetInstance().GetAppVersionName();
34 appInfo.processName = AceApplicationInfo::GetInstance().GetProcessName();
35 appInfo.abilityName = AceApplicationInfo::GetInstance().GetAbilityName();
36 return appInfo;
37 }
38
SetScrollState(bool state)39 void PerfInterfaces::SetScrollState(bool state)
40 {
41 OHOS::HiviewDFX::Watchdog::GetInstance().SetScrollState(state);
42 }
43
RecordInputEvent(PerfActionType type,PerfSourceType sourceType,int64_t time)44 void PerfInterfaces::RecordInputEvent(PerfActionType type, PerfSourceType sourceType, int64_t time)
45 {
46 HiviewDFX::PerfActionType dfxType = static_cast<HiviewDFX::PerfActionType>(static_cast<int>(type));
47 HiviewDFX::PerfSourceType dfxSourceType = static_cast<HiviewDFX::PerfSourceType>(static_cast<int>(sourceType));
48 PerfMonitorAdapter::GetInstance().RecordInputEvent(dfxType, dfxSourceType, time);
49 }
50
GetInputTime(const std::string & sceneId,PerfActionType type,const std::string & note)51 int64_t PerfInterfaces::GetInputTime(const std::string& sceneId, PerfActionType type, const std::string& note)
52 {
53 HiviewDFX::PerfActionType dfxType = static_cast<HiviewDFX::PerfActionType>(static_cast<int>(type));
54 return PerfMonitorAdapter::GetInstance().GetInputTime(sceneId, dfxType, note);
55 }
56
NotifyAppJankStatsBegin()57 void PerfInterfaces::NotifyAppJankStatsBegin()
58 {
59 PerfMonitorAdapter::GetInstance().NotifyAppJankStatsBegin();
60 }
61
NotifyAppJankStatsEnd()62 void PerfInterfaces::NotifyAppJankStatsEnd()
63 {
64 PerfMonitorAdapter::GetInstance().NotifyAppJankStatsEnd();
65 }
66
SetPageUrl(const std::string & pageUrl)67 void PerfInterfaces::SetPageUrl(const std::string& pageUrl)
68 {
69 PerfMonitorAdapter::GetInstance().SetPageUrl(pageUrl);
70 }
71
GetPageUrl()72 std::string PerfInterfaces::GetPageUrl()
73 {
74 return PerfMonitorAdapter::GetInstance().GetPageUrl();
75 }
76
SetPageName(const std::string & pageName)77 void PerfInterfaces::SetPageName(const std::string& pageName)
78 {
79 PerfMonitorAdapter::GetInstance().SetPageName(pageName);
80 }
81
GetPageName()82 std::string PerfInterfaces::GetPageName()
83 {
84 return PerfMonitorAdapter::GetInstance().GetPageName();
85 }
86
SetAppForeground(bool isShow)87 void PerfInterfaces::SetAppForeground(bool isShow)
88 {
89 PerfMonitorAdapter::GetInstance().SetAppForeground(isShow);
90 }
91
SetAppStartStatus()92 void PerfInterfaces::SetAppStartStatus()
93 {
94 PerfMonitorAdapter::GetInstance().SetAppStartStatus();
95 }
96
IsScrollJank(const std::string & sceneId)97 bool PerfInterfaces::IsScrollJank(const std::string& sceneId)
98 {
99 return PerfMonitorAdapter::GetInstance().IsScrollJank(sceneId);
100 }
101
Start(const std::string & sceneId,PerfActionType type,const std::string & note)102 void PerfInterfaces::Start(const std::string& sceneId, PerfActionType type, const std::string& note)
103 {
104 auto appInfo = GetAceAppInfo();
105 PerfMonitorAdapter::GetInstance().SetAppInfo(appInfo);
106 HiviewDFX::PerfActionType dfxType = static_cast<HiviewDFX::PerfActionType>(static_cast<int>(type));
107 PerfMonitorAdapter::GetInstance().Start(sceneId, dfxType, note);
108 }
109
End(const std::string & sceneId,bool isRsRender)110 void PerfInterfaces::End(const std::string& sceneId, bool isRsRender)
111 {
112 PerfMonitorAdapter::GetInstance().End(sceneId, isRsRender);
113 }
114
StartCommercial(const std::string & sceneId,PerfActionType type,const std::string & note)115 void PerfInterfaces::StartCommercial(const std::string& sceneId, PerfActionType type, const std::string& note)
116 {
117 auto appInfo = GetAceAppInfo();
118 PerfMonitorAdapter::GetInstance().SetAppInfo(appInfo);
119 HiviewDFX::PerfActionType dfxType = static_cast<HiviewDFX::PerfActionType>(static_cast<int>(type));
120 PerfMonitorAdapter::GetInstance().StartCommercial(sceneId, dfxType, note);
121 }
122
EndCommercial(const std::string & sceneId,bool isRsRender)123 void PerfInterfaces::EndCommercial(const std::string& sceneId, bool isRsRender)
124 {
125 PerfMonitorAdapter::GetInstance().EndCommercial(sceneId, isRsRender);
126 }
127
SetFrameTime(int64_t vsyncTime,int64_t duration,double jank,const std::string & windowName)128 void PerfInterfaces::SetFrameTime(int64_t vsyncTime, int64_t duration, double jank, const std::string& windowName)
129 {
130 PerfMonitorAdapter::GetInstance().SetFrameTime(vsyncTime, duration, jank, windowName);
131 }
132
SetSubHealthInfo(const std::string & info,const std::string & reason,const int32_t duration)133 void PerfInterfaces::SetSubHealthInfo(const std::string& info, const std::string& reason, const int32_t duration)
134 {
135 PerfMonitorAdapter::GetInstance().SetSubHealthInfo(info, reason, duration);
136 }
137
ReportJankFrameApp(double jank,int32_t jankThreshold)138 void PerfInterfaces::ReportJankFrameApp(double jank, int32_t jankThreshold)
139 {
140 PerfMonitorAdapter::GetInstance().ReportJankFrameApp(jank, jankThreshold);
141 }
142
ReportPageShowMsg(const std::string & pageUrl,const std::string & bundleName,const std::string & pageName)143 void PerfInterfaces::ReportPageShowMsg(const std::string& pageUrl, const std::string& bundleName,
144 const std::string& pageName)
145 {
146 PerfMonitorAdapter::GetInstance().ReportPageShowMsg(pageUrl, bundleName, pageName);
147 }
148
SetApplicationInfo()149 void PerfInterfaces::SetApplicationInfo()
150 {
151 auto appInfo = GetAceAppInfo();
152 PerfMonitorAdapter::GetInstance().SetAppInfo(appInfo);
153 }
154
155 } // namespace OHOS::Ace
156