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 "frame_trace_adapter_impl.h" 17 #include <unistd.h> 18 #include "frame_trace.h" 19 20 namespace OHOS::Ace { 21 #ifdef __aarch64__ 22 const char* FRAME_TRACE_SO_PATH = "/system/lib64/libframe_trace_intf.z.so"; 23 #else 24 const char* FRAME_TRACE_SO_PATH = "/system/lib/libframe_trace_intf.z.so"; 25 #endif 26 27 static bool judgeFrameTrace = false; 28 static bool accessFrameTrace = false; 29 AccessFrameTrace()30bool FrameTraceAdapterImpl::AccessFrameTrace() 31 { 32 if (!judgeFrameTrace) { 33 judgeFrameTrace = true; 34 accessFrameTrace = access(FRAME_TRACE_SO_PATH, F_OK) ? false : true; 35 } 36 return accessFrameTrace; 37 } 38 QuickExecute(std::function<void ()> && func)39void FrameTraceAdapterImpl::QuickExecute(std::function<void()> && func) 40 { 41 if (AccessFrameTrace()) { 42 FRAME_TRACE::TraceAndExecute(std::move(func), FRAME_TRACE::TraceType::QUICK_TRACE); 43 } 44 } 45 SlowExecute(std::function<void ()> && func)46void FrameTraceAdapterImpl::SlowExecute(std::function<void()> && func) 47 { 48 if (AccessFrameTrace()) { 49 FRAME_TRACE::TraceAndExecute(std::move(func), FRAME_TRACE::TraceType::SLOW_TRACE); 50 } 51 } 52 EnableFrameTrace(const std::string & traceTag)53bool FrameTraceAdapterImpl::EnableFrameTrace(const std::string &traceTag) 54 { 55 if (AccessFrameTrace()) { 56 return FRAME_TRACE::FrameAwareTraceEnable(traceTag); 57 } 58 return false; 59 } 60 GetInstance()61FrameTraceAdapter* FrameTraceAdapter::GetInstance() 62 { 63 static FrameTraceAdapterImpl instance; 64 return &instance; 65 } 66 IsEnabled()67bool FrameTraceAdapterImpl::IsEnabled() 68 { 69 if (AccessFrameTrace()) { 70 return FRAME_TRACE::IsEnabled(); 71 } 72 return false; 73 } 74 } 75