• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "window_frame_trace.h"
17 #include <unistd.h>
18 #ifdef FRAME_TRACE_ENABLE
19 #include "frame_trace.h"
20 #endif
21 
22 namespace FRAME_TRACE {
23 
24 #ifdef __aarch64__
25 const char* FRAME_TRACE_SO_PATH = "/system/lib64/libframe_trace_intf.z.so";
26 #else
27 const char* FRAME_TRACE_SO_PATH = "/system/lib/libframe_trace_intf.z.so";
28 #endif
29 
GetInstance()30 WindowFrameTraceImpl* WindowFrameTraceImpl::GetInstance()
31 {
32     static WindowFrameTraceImpl ftWindow;
33     return &ftWindow;
34 }
35 #ifdef FRAME_TRACE_ENABLE
AccessFrameTrace()36 bool WindowFrameTraceImpl::AccessFrameTrace()
37 {
38     if (!judgeFrameTrace_) {
39         judgeFrameTrace_ = true;
40         accessFrameTrace_ = access(FRAME_TRACE_SO_PATH, F_OK) ? false : true;
41     }
42     return accessFrameTrace_;
43 }
44 
VsyncStartFrameTrace()45 void WindowFrameTraceImpl::VsyncStartFrameTrace()
46 {
47     if (!AccessFrameTrace()) {
48         return;
49     }
50     if (FrameAwareTraceEnable(intervalName_)) {
51         if (handleUI_ == nullptr) {
52             handleUI_ = CreateTraceTag(intervalName_);
53         }
54         if (handleUI_ != nullptr) {
55             EnableTraceForThread(handleUI_);
56             StartFrameTrace(handleUI_);
57         }
58     }
59 }
60 
VsyncStopFrameTrace()61 void WindowFrameTraceImpl::VsyncStopFrameTrace()
62 {
63     if (!AccessFrameTrace()) {
64         return;
65     }
66     if (FrameAwareTraceEnable(intervalName_)) {
67         if (handleUI_ != nullptr) {
68             StopFrameTrace(handleUI_);
69         }
70     }
71 }
72 #endif
73 } // namespace FRAME_TRACE
74