• 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 }
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         frameSchedSoLoaded_ = true;
54     }
55     LOGD("frame-ace:[LoadLibrary]dlopen libframe_ui_intf.so success");
56     return true;
57 }
58 
CloseLibrary()59 void FrameReport::CloseLibrary()
60 {
61     if (dlclose(frameSchedHandle_) != 0) {
62         LOGE("frame-ace:[CloseLibrary]libframe_ui_intf.so failed!\n");
63         return;
64     }
65     frameSchedHandle_ = nullptr;
66     frameSchedSoLoaded_ = false;
67     LOGD("frame-ace:[CloseLibrary]libframe_ui_intf.so close success!\n");
68 }
69 
LoadSymbol(const char * symName)70 void *FrameReport::LoadSymbol(const char *symName)
71 {
72     CHECK_NULL_RETURN(frameSchedSoLoaded_, nullptr);
73 
74     void *funcSym = dlsym(frameSchedHandle_, symName);
75     CHECK_NULL_RETURN(funcSym, nullptr);
76     return funcSym;
77 }
78 
Init()79 void FrameReport::Init()
80 {
81     LoadLibrary();
82     frameInitFunc_ = (FrameInitFunc)LoadSymbol("Init");
83     CHECK_NULL_VOID(frameInitFunc_);
84     frameInitFunc_();
85 }
86 
GetEnable()87 int FrameReport::GetEnable()
88 {
89     return true;
90 }
91 
GetFrameReportEnable()92 int FrameReport::GetFrameReportEnable()
93 {
94     if (!frameSchedSoLoaded_) {
95         return 0;
96     }
97     frameGetEnableFunc_ = (FrameGetEnableFunc)LoadSymbol("GetSenseSchedEnable");
98     CHECK_NULL_RETURN(frameGetEnableFunc_, 0);
99     return frameGetEnableFunc_();
100 }
101 
BeginFlushAnimation()102 void FrameReport::BeginFlushAnimation()
103 {
104     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::AnimateStart);
105     if (GetFrameReportEnable() == 0) {
106         return;
107     }
108     beginFlushAnimationFunc_ = (BeginFlushAnimationFunc)LoadSymbol("BeginFlushAnimation");
109     CHECK_NULL_VOID(beginFlushAnimationFunc_);
110     beginFlushAnimationFunc_();
111 }
112 
EndFlushAnimation()113 void FrameReport::EndFlushAnimation()
114 {
115     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::AnimateEnd);
116     if (GetFrameReportEnable() == 0) {
117         return;
118     }
119     endFlushAnimationFunc_ = (EndFlushAnimationFunc)LoadSymbol("EndFlushAnimation");
120     CHECK_NULL_VOID(endFlushAnimationFunc_);
121     endFlushAnimationFunc_();
122 }
123 
BeginFlushBuild()124 void FrameReport::BeginFlushBuild()
125 {
126     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::BuildStart);
127     if (GetFrameReportEnable() == 0) {
128         return;
129     }
130     beginFlushBuildFunc_ = (BeginFlushBuildFunc)LoadSymbol("BeginFlushBuild");
131     CHECK_NULL_VOID(beginFlushBuildFunc_);
132     beginFlushBuildFunc_();
133 }
134 
EndFlushBuild()135 void FrameReport::EndFlushBuild()
136 {
137     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::BuildEnd);
138     if (GetFrameReportEnable() == 0) {
139         return;
140     }
141     endFlushBuildFunc_ = (EndFlushBuildFunc)LoadSymbol("EndFlushBuild");
142     CHECK_NULL_VOID(endFlushBuildFunc_);
143     endFlushBuildFunc_();
144 }
145 
BeginFlushLayout()146 void FrameReport::BeginFlushLayout()
147 {
148     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::LayoutStart);
149     if (GetFrameReportEnable() == 0) {
150         return;
151     }
152     beginFlushLayoutFunc_ = (BeginFlushLayoutFunc)LoadSymbol("BeginFlushLayout");
153     CHECK_NULL_VOID(beginFlushLayoutFunc_);
154     beginFlushLayoutFunc_();
155 }
156 
EndFlushLayout()157 void FrameReport::EndFlushLayout()
158 {
159     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::LayoutEnd);
160     if (GetFrameReportEnable() == 0) {
161         return;
162     }
163     endFlushLayoutFunc_ = (EndFlushLayoutFunc)LoadSymbol("EndFlushLayout");
164     CHECK_NULL_VOID(endFlushLayoutFunc_);
165     endFlushLayoutFunc_();
166 }
167 
BeginFlushRender()168 void FrameReport::BeginFlushRender()
169 {
170     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::DrawStart);
171     if (GetFrameReportEnable() == 0) {
172         return;
173     }
174     beginFlushRenderFunc_ = (BeginFlushRenderFunc)LoadSymbol("BeginFlushRender");
175     CHECK_NULL_VOID(beginFlushRenderFunc_);
176     beginFlushRenderFunc_();
177 }
178 
EndFlushRender()179 void FrameReport::EndFlushRender()
180 {
181     if (GetFrameReportEnable() == 0) {
182         return;
183     }
184     endFlushRenderFunc_ = (EndFlushRenderFunc)LoadSymbol("EndFlushRender");
185     CHECK_NULL_VOID(endFlushRenderFunc_);
186     endFlushRenderFunc_();
187 }
188 
BeginFlushRenderFinish()189 void FrameReport::BeginFlushRenderFinish()
190 {
191     if (GetFrameReportEnable() == 0) {
192         return;
193     }
194     beginFlushRenderFinishFunc_ = (BeginFlushRenderFinishFunc)LoadSymbol("BeginFlushRenderFinish");
195     CHECK_NULL_VOID(beginFlushRenderFinishFunc_);
196     beginFlushRenderFinishFunc_();
197 }
198 
EndFlushRenderFinish()199 void FrameReport::EndFlushRenderFinish()
200 {
201     Rosen::FrameCollector::GetInstance().MarkFrameEvent(Rosen::FrameEventType::DrawEnd);
202     if (GetFrameReportEnable() == 0) {
203         return;
204     }
205     endFlushRenderFinishFunc_ = (EndFlushRenderFinishFunc)LoadSymbol("EndFlushRenderFinish");
206     CHECK_NULL_VOID(endFlushRenderFinishFunc_);
207     endFlushRenderFinishFunc_();
208 }
209 
BeginProcessPostFlush()210 void FrameReport::BeginProcessPostFlush()
211 {
212     if (GetFrameReportEnable() == 0) {
213         return;
214     }
215     beginProcessPostFunc_ = (BeginProcessPostFlushFunc)LoadSymbol("BeginProcessPostFlush");
216     CHECK_NULL_VOID(beginProcessPostFunc_);
217     beginProcessPostFunc_();
218 }
219 
BeginListFling()220 void FrameReport::BeginListFling()
221 {
222     if (GetFrameReportEnable() == 0) {
223         return;
224     }
225     beginListFlingFunc_ = (BeginListFlingFunc)LoadSymbol("BeginListFling");
226     CHECK_NULL_VOID(beginListFlingFunc_);
227     beginListFlingFunc_();
228 }
229 
EndListFling()230 void FrameReport::EndListFling()
231 {
232     if (GetFrameReportEnable() == 0) {
233         return;
234     }
235     endListFlingFunc_ = (EndListFlingFunc)LoadSymbol("EndListFling");
236     CHECK_NULL_VOID(beginListFlingFunc_);
237     endListFlingFunc_();
238 }
239 } // namespace OHOS::Ace
240