• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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/log/frame_report.h"
17 
18 #include <dlfcn.h>
19 #include <frame_collector.h>
20 
21 #include "base/utils/utils.h"
22 
23 namespace OHOS::Ace {
24 namespace {
25 const std::string FRAME_AWARE_SO_PATH = "libframe_ui_intf.z.so";
26 } // namespace
GetInstance()27 FrameReport& FrameReport::GetInstance()
28 {
29     static FrameReport instance;
30     return instance;
31 }
32 
FrameReport()33 FrameReport::FrameReport() {}
34 
~FrameReport()35 FrameReport::~FrameReport()
36 {
37     CloseLibrary();
38 }
39 
LoadLibrary()40 bool FrameReport::LoadLibrary()
41 {
42     if (!frameSchedSoLoaded_) {
43         frameSchedHandle_ = dlopen(FRAME_AWARE_SO_PATH.c_str(), RTLD_LAZY);
44         CHECK_NULL_RETURN(frameSchedHandle_, false);
45         frameInitFunc_ = (FrameInitFunc)LoadSymbol("Init");
46         CHECK_NULL_RETURN(frameInitFunc_, false);
47         frameGetEnableFunc_ = (FrameGetEnableFunc)LoadSymbol("GetSenseSchedEnable");
48         CHECK_NULL_RETURN(frameGetEnableFunc_, false);
49         beginFlushAnimationFunc_ = (BeginFlushAnimationFunc)LoadSymbol("BeginFlushAnimation");
50         CHECK_NULL_RETURN(beginFlushAnimationFunc_, false);
51         endFlushAnimationFunc_ = (EndFlushAnimationFunc)LoadSymbol("EndFlushAnimation");
52         CHECK_NULL_RETURN(endFlushAnimationFunc_, false);
53         beginFlushBuildFunc_ = (BeginFlushBuildFunc)LoadSymbol("BeginFlushBuild");
54         CHECK_NULL_RETURN(beginFlushBuildFunc_, false);
55         endFlushBuildFunc_ = (EndFlushBuildFunc)LoadSymbol("EndFlushBuild");
56         CHECK_NULL_RETURN(endFlushBuildFunc_, false);
57         beginFlushLayoutFunc_ = (BeginFlushLayoutFunc)LoadSymbol("BeginFlushLayout");
58         CHECK_NULL_RETURN(beginFlushLayoutFunc_, false);
59         endFlushLayoutFunc_ = (EndFlushLayoutFunc)LoadSymbol("EndFlushLayout");
60         CHECK_NULL_RETURN(endFlushLayoutFunc_, false);
61         beginFlushRenderFunc_ = (BeginFlushRenderFunc)LoadSymbol("BeginFlushRender");
62         CHECK_NULL_RETURN(beginFlushRenderFunc_, false);
63         endFlushRenderFunc_ = (EndFlushRenderFunc)LoadSymbol("EndFlushRender");
64         CHECK_NULL_RETURN(endFlushRenderFunc_, false);
65         beginFlushRenderFinishFunc_ = (BeginFlushRenderFinishFunc)LoadSymbol("BeginFlushRenderFinish");
66         CHECK_NULL_RETURN(beginFlushRenderFinishFunc_, false);
67         endFlushRenderFinishFunc_ = (EndFlushRenderFinishFunc)LoadSymbol("EndFlushRenderFinish");
68         CHECK_NULL_RETURN(endFlushRenderFinishFunc_, false);
69         beginProcessPostFunc_ = (BeginProcessPostFlushFunc)LoadSymbol("BeginProcessPostFlush");
70         CHECK_NULL_RETURN(beginProcessPostFunc_, false);
71         beginListFlingFunc_ = (BeginListFlingFunc)LoadSymbol("BeginListFling");
72         CHECK_NULL_RETURN(beginListFlingFunc_, false);
73         endListFlingFunc_ = (EndListFlingFunc)LoadSymbol("EndListFling");
74         CHECK_NULL_RETURN(endListFlingFunc_, false);
75         flushBeginFunc_ = (FlushBeginFunc)LoadSymbol("FlushBegin");
76         CHECK_NULL_RETURN(flushBeginFunc_, false);
77         flushEndFunc_ = (FlushEndFunc)LoadSymbol("FlushEnd");
78         CHECK_NULL_RETURN(flushEndFunc_, false);
79         setFrameParamFunc_ = (SetFrameParamFunc)LoadSymbol("SetFrameParam");
80         CHECK_NULL_RETURN(setFrameParamFunc_, false);
81         enableSelfRenderFunc_ = (EnableSelfRenderFunc)LoadSymbol("EnableSelfRender");
82         CHECK_NULL_RETURN(enableSelfRenderFunc_, false);
83         disableSelfRenderFunc_ = (DisableSelfRenderFunc)LoadSymbol("DisableSelfRender");
84         CHECK_NULL_RETURN(disableSelfRenderFunc_, false);
85         reportSchedEventFunc_ = (ReportSchedEventFunc)LoadSymbol("ReportSchedEvent");
86         frameSchedSoLoaded_ = true;
87     }
88     return true;
89 }
90 
CloseLibrary()91 void FrameReport::CloseLibrary()
92 {
93     if (dlclose(frameSchedHandle_) != 0) {
94         LOGE("frame-ace:[CloseLibrary]libframe_ui_intf.so failed!\n");
95         return;
96     }
97     frameSchedHandle_ = nullptr;
98     frameSchedSoLoaded_ = false;
99 }
100 
LoadSymbol(const char * symName)101 void* FrameReport::LoadSymbol(const char* symName)
102 {
103     CHECK_NULL_RETURN(frameSchedHandle_, nullptr);
104     return dlsym(frameSchedHandle_, symName);
105 }
106 
Init()107 void FrameReport::Init()
108 {
109     if (LoadLibrary()) {
110         frameInitFunc_();
111         enable_ = frameGetEnableFunc_() != 0;
112     }
113 }
114 
GetEnable()115 int FrameReport::GetEnable()
116 {
117     return true;
118 }
119 
GetFrameReportEnable()120 int FrameReport::GetFrameReportEnable()
121 {
122     if (!frameSchedSoLoaded_) {
123         return 0;
124     }
125     return frameGetEnableFunc_();
126 }
127 
BeginFlushAnimation()128 void FrameReport::BeginFlushAnimation()
129 {
130     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::AnimateStart);
131     if (!enable_) {
132         return;
133     }
134     beginFlushAnimationFunc_();
135 }
136 
EndFlushAnimation()137 void FrameReport::EndFlushAnimation()
138 {
139     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::AnimateEnd);
140     if (!enable_) {
141         return;
142     }
143     endFlushAnimationFunc_();
144 }
145 
BeginFlushBuild()146 void FrameReport::BeginFlushBuild()
147 {
148     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::BuildStart);
149     if (!enable_) {
150         return;
151     }
152     beginFlushBuildFunc_();
153 }
154 
EndFlushBuild()155 void FrameReport::EndFlushBuild()
156 {
157     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::BuildEnd);
158     if (!enable_) {
159         return;
160     }
161     endFlushBuildFunc_();
162 }
163 
BeginFlushLayout()164 void FrameReport::BeginFlushLayout()
165 {
166     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::LayoutStart);
167     if (!enable_) {
168         return;
169     }
170     beginFlushLayoutFunc_();
171 }
172 
EndFlushLayout()173 void FrameReport::EndFlushLayout()
174 {
175     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::LayoutEnd);
176     if (!enable_) {
177         return;
178     }
179     endFlushLayoutFunc_();
180 }
181 
BeginFlushRender()182 void FrameReport::BeginFlushRender()
183 {
184     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::DrawStart);
185     if (!enable_) {
186         return;
187     }
188     beginFlushRenderFunc_();
189 }
190 
EndFlushRender()191 void FrameReport::EndFlushRender()
192 {
193     if (!enable_) {
194         return;
195     }
196     endFlushRenderFunc_();
197 }
198 
BeginFlushRenderFinish()199 void FrameReport::BeginFlushRenderFinish()
200 {
201     if (!enable_) {
202         return;
203     }
204     beginFlushRenderFinishFunc_();
205 }
206 
EndFlushRenderFinish()207 void FrameReport::EndFlushRenderFinish()
208 {
209     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::DrawEnd);
210     if (!enable_) {
211         return;
212     }
213     endFlushRenderFinishFunc_();
214 }
215 
BeginProcessPostFlush()216 void FrameReport::BeginProcessPostFlush()
217 {
218     if (!enable_) {
219         return;
220     }
221     beginProcessPostFunc_();
222 }
223 
BeginListFling()224 void FrameReport::BeginListFling()
225 {
226     if (!enable_) {
227         return;
228     }
229     beginListFlingFunc_();
230 }
231 
EndListFling()232 void FrameReport::EndListFling()
233 {
234     if (!enable_) {
235         return;
236     }
237     endListFlingFunc_();
238 }
239 
FlushBegin()240 void FrameReport::FlushBegin()
241 {
242     if (!enable_) {
243         return;
244     }
245     flushBeginFunc_();
246 }
247 
FlushEnd()248 void FrameReport::FlushEnd()
249 {
250     if (!enable_) {
251         return;
252     }
253     flushEndFunc_();
254 }
255 
SetFrameParam(int requestId,int load,int schedFrameNum,int value)256 void FrameReport::SetFrameParam(int requestId, int load, int schedFrameNum, int value)
257 {
258     if (!enable_) {
259         return;
260     }
261     setFrameParamFunc_(requestId, load, schedFrameNum, value);
262 }
263 
EnableSelfRender()264 void FrameReport::EnableSelfRender()
265 {
266     if (!enable_) {
267         return;
268     }
269     enableSelfRenderFunc_();
270 }
271 
DisableSelfRender()272 void FrameReport::DisableSelfRender()
273 {
274     if (!enable_) {
275         return;
276     }
277     disableSelfRenderFunc_();
278 }
279 
ReportSchedEvent(FrameSchedEvent event,const std::unordered_map<std::string,std::string> & payLoad)280 void FrameReport::ReportSchedEvent(
281     FrameSchedEvent event, const std::unordered_map<std::string, std::string>& payLoad)
282 {
283     if (!enable_ || !reportSchedEventFunc_) {
284         return;
285     }
286     reportSchedEventFunc_(event, payLoad);
287 }
288 } // namespace OHOS::Ace
289