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