• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2025 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "perf_monitor_adapter.h"
18 
19 #include "animator_monitor.h"
20 #include "input_monitor.h"
21 #include "jank_frame_monitor.h"
22 #include "perf_reporter.h"
23 #include "perf_utils.h"
24 #include "scene_monitor.h"
25 #include "white_block_monitor.h"
26 #include "surface_monitor.h"
27 
28 namespace OHOS {
29 namespace HiviewDFX {
30 
GetInstance()31 PerfMonitorAdapter& PerfMonitorAdapter::GetInstance()
32 {
33     static PerfMonitorAdapter instance;
34     return instance;
35 }
36 
RegisterFrameCallback(IFrameCallback * cb)37 void PerfMonitorAdapter::RegisterFrameCallback(IFrameCallback * cb)
38 {
39     JankFrameMonitor::GetInstance().RegisterFrameCallback(cb);
40 }
41 
UnregisterFrameCallback(IFrameCallback * cb)42 void PerfMonitorAdapter::UnregisterFrameCallback(IFrameCallback * cb)
43 {
44     JankFrameMonitor::GetInstance().UnregisterFrameCallback(cb);
45 }
46 
RegisterAnimatorCallback(IAnimatorCallback * cb)47 void PerfMonitorAdapter::RegisterAnimatorCallback(IAnimatorCallback * cb)
48 {
49     AnimatorMonitor::GetInstance().RegisterAnimatorCallback(cb);
50 }
51 
UnregisterAnimatorCallback(IAnimatorCallback * cb)52 void PerfMonitorAdapter::UnregisterAnimatorCallback(IAnimatorCallback * cb)
53 {
54     AnimatorMonitor::GetInstance().UnregisterAnimatorCallback(cb);
55 }
56 
RegisterSceneCallback(ISceneCallback * cb)57 void PerfMonitorAdapter::RegisterSceneCallback(ISceneCallback* cb)
58 {
59     SceneMonitor::GetInstance().RegisterSceneCallback(cb);
60 }
61 
UnregisterSceneCallback(ISceneCallback * cb)62 void PerfMonitorAdapter::UnregisterSceneCallback(ISceneCallback* cb)
63 {
64     SceneMonitor::GetInstance().UnregisterSceneCallback(cb);
65 }
66 
RecordInputEvent(PerfActionType type,PerfSourceType sourceType,int64_t time)67 void PerfMonitorAdapter::RecordInputEvent(PerfActionType type, PerfSourceType sourceType, int64_t time)
68 {
69     InputMonitor::GetInstance().RecordInputEvent(type, sourceType, time);
70 }
71 
GetInputTime(const std::string & sceneId,PerfActionType type,const std::string & note)72 int64_t PerfMonitorAdapter::GetInputTime(const std::string& sceneId, PerfActionType type, const std::string& note)
73 {
74     return InputMonitor::GetInstance().GetInputTime(sceneId, type, note);
75 }
76 
NotifyAppJankStatsBegin()77 void PerfMonitorAdapter::NotifyAppJankStatsBegin()
78 {
79     SceneMonitor::GetInstance().NotifyAppJankStatsBegin();
80 }
81 
NotifyAppJankStatsEnd()82 void PerfMonitorAdapter::NotifyAppJankStatsEnd()
83 {
84     SceneMonitor::GetInstance().NotifyAppJankStatsEnd();
85 }
86 
SetPageUrl(const std::string & pageUrl)87 void PerfMonitorAdapter::SetPageUrl(const std::string& pageUrl)
88 {
89     SceneMonitor::GetInstance().SetPageUrl(pageUrl);
90 }
91 
GetPageUrl()92 std::string PerfMonitorAdapter::GetPageUrl()
93 {
94     return SceneMonitor::GetInstance().GetPageUrl();
95 }
96 
SetPageName(const std::string & pageName)97 void PerfMonitorAdapter::SetPageName(const std::string& pageName)
98 {
99     SceneMonitor::GetInstance().SetPageName(pageName);
100 }
101 
GetPageName()102 std::string PerfMonitorAdapter::GetPageName()
103 {
104     return SceneMonitor::GetInstance().GetPageName();
105 }
106 
SetAppForeground(bool isShow)107 void PerfMonitorAdapter::SetAppForeground(bool isShow)
108 {
109     SceneMonitor::GetInstance().SetAppForeground(isShow);
110 }
111 
SetAppStartStatus()112 void PerfMonitorAdapter::SetAppStartStatus()
113 {
114     SceneMonitor::GetInstance().SetAppStartStatus();
115 }
116 
SetAppInfo(AceAppInfo & appInfo)117 void PerfMonitorAdapter::SetAppInfo(AceAppInfo& appInfo)
118 {
119     SceneMonitor::GetInstance().SetAppInfo(appInfo);
120 }
121 
IsScrollJank(const std::string & sceneId)122 bool PerfMonitorAdapter::IsScrollJank(const std::string& sceneId)
123 {
124     return SceneMonitor::GetInstance().IsScrollJank(sceneId);
125 }
126 
Start(const std::string & sceneId,PerfActionType type,const std::string & note)127 void PerfMonitorAdapter::Start(const std::string& sceneId, PerfActionType type, const std::string& note)
128 {
129     AnimatorMonitor::GetInstance().Start(sceneId, type, note);
130 }
131 
End(const std::string & sceneId,bool isRsRender)132 void PerfMonitorAdapter::End(const std::string& sceneId, bool isRsRender)
133 {
134     AnimatorMonitor::GetInstance().End(sceneId, isRsRender);
135 }
136 
StartCommercial(const std::string & sceneId,PerfActionType type,const std::string & note)137 void PerfMonitorAdapter::StartCommercial(const std::string& sceneId, PerfActionType type, const std::string& note)
138 {
139     AnimatorMonitor::GetInstance().Start(sceneId, type, note);
140 }
141 
EndCommercial(const std::string & sceneId,bool isRsRender)142 void PerfMonitorAdapter::EndCommercial(const std::string& sceneId, bool isRsRender)
143 {
144     AnimatorMonitor::GetInstance().End(sceneId, isRsRender);
145 }
146 
SetFrameTime(int64_t vsyncTime,int64_t duration,double jank,const std::string & windowName)147 void PerfMonitorAdapter::SetFrameTime(int64_t vsyncTime, int64_t duration, double jank, const std::string& windowName)
148 {
149     JankFrameMonitor::GetInstance().OnFrameEnd(vsyncTime, duration, jank, windowName);
150 }
151 
SetSubHealthInfo(const std::string & info,const std::string & reason,const int32_t duration)152 void PerfMonitorAdapter::SetSubHealthInfo(const std::string& info, const std::string& reason, const int32_t duration)
153 {
154     SubHealthInfo subHealthInfo;
155     subHealthInfo.info = info;
156     subHealthInfo.subHealthReason = reason;
157     subHealthInfo.subHealthTime = duration;
158     AnimatorMonitor::GetInstance().SetSubHealthInfo(subHealthInfo);
159 }
160 
ReportJankFrameApp(double jank,int32_t jankThreshold)161 void PerfMonitorAdapter::ReportJankFrameApp(double jank, int32_t jankThreshold)
162 {
163     PerfReporter::GetInstance().ReportJankFrameApp(jank, jankThreshold);
164 }
165 
ReportPageShowMsg(const std::string & pageUrl,const std::string & bundleName,const std::string & pageName)166 void PerfMonitorAdapter::ReportPageShowMsg(const std::string& pageUrl, const std::string& bundleName,
167     const std::string& pageName)
168 {
169     PerfReporter::GetInstance().ReportPageShowMsg(pageUrl, bundleName, pageName);
170 }
171 
StartRecordImageLoadStat(int64_t id)172 void PerfMonitorAdapter::StartRecordImageLoadStat(int64_t id)
173 {
174     WhiteBlockMonitor::GetInstance().StartRecordImageLoadStat(id);
175 }
176 
EndRecordImageLoadStat(int64_t id,std::pair<int,int> size,const std::string & type,int state)177 void PerfMonitorAdapter::EndRecordImageLoadStat(int64_t id, std::pair<int, int> size, const std::string& type,
178                                                 int state)
179 {
180     WhiteBlockMonitor::GetInstance().EndRecordImageLoadStat(id, size, type, state);
181 }
182 
OnSceneChanged(const SceneType & type,bool status)183 void PerfMonitorAdapter::OnSceneChanged(const SceneType& type, bool status)
184 {
185     SceneMonitor::GetInstance().OnSceneChanged(type, status);
186 }
187 
ReportSurface(const int64_t & uniqueId,const std::string & surfaceName,const std::string & componentName,const std::string & bundleName,const int32_t & pid)188 void PerfMonitorAdapter::ReportSurface(const int64_t& uniqueId, const std::string& surfaceName,
189     const std::string& componentName, const std::string& bundleName, const int32_t& pid)
190 {
191     SurfaceMonitor::GetInstance().ReportSurface(uniqueId, surfaceName, componentName, bundleName, pid);
192 }
193 
194 }
195 }