1 /* 2 * Copyright (c) 2021 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 "scoped_bytrace.h" 17 18 #include <hitrace_meter.h> 19 #include <hilog/log.h> 20 #include "parameters.h" 21 ScopedBytrace(const std::string & proc)22ScopedBytrace::ScopedBytrace(const std::string &proc) : proc_(proc) 23 { 24 StartTrace(HITRACE_TAG_GRAPHIC_AGP, proc_); 25 isEnd = false; 26 } 27 ~ScopedBytrace()28ScopedBytrace::~ScopedBytrace() 29 { 30 if (isEnd == false) { 31 FinishTrace(HITRACE_TAG_GRAPHIC_AGP); 32 } 33 } 34 End()35void ScopedBytrace::End() 36 { 37 if (isEnd == false) { 38 FinishTrace(HITRACE_TAG_GRAPHIC_AGP); 39 } 40 } 41 42 bool ScopedDebugTrace::debugTraceEnabled_ = 43 std::atoi((OHOS::system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0; ScopedDebugTrace(const std::string & traceStr)44ScopedDebugTrace::ScopedDebugTrace(const std::string &traceStr) 45 { 46 if (debugTraceEnabled_) { 47 StartTrace(HITRACE_TAG_GRAPHIC_AGP, traceStr); 48 } 49 } ~ScopedDebugTrace()50ScopedDebugTrace::~ScopedDebugTrace() 51 { 52 if (debugTraceEnabled_) { 53 FinishTrace(HITRACE_TAG_GRAPHIC_AGP); 54 } 55 } 56