1 /* 2 * Copyright (c) 2022-2023 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 #ifndef RENDER_SERVICE_BASE_COMMON_OPTIONAL_TRACE 17 #define RENDER_SERVICE_BASE_COMMON_OPTIONAL_TRACE 18 19 #include "rs_trace.h" 20 #include "platform/common/rs_system_properties.h" 21 22 #define RS_OPTIONAL_TRACE_BEGIN(name) \ 23 do { \ 24 if (Rosen::RSSystemProperties::GetDebugTraceEnabled()) { \ 25 RS_TRACE_BEGIN(name); \ 26 } \ 27 } while (0) 28 29 #define RS_OPTIONAL_TRACE_END() \ 30 do { \ 31 if (Rosen::RSSystemProperties::GetDebugTraceEnabled()) { \ 32 RS_TRACE_END(); \ 33 } \ 34 } while (0) 35 36 #define RS_OPTIONAL_TRACE_NAME_FMT(fmt, ...) \ 37 do { \ 38 if (Rosen::RSSystemProperties::GetDebugTraceEnabled()) { \ 39 HITRACE_METER_FMT(HITRACE_TAG_GRAPHIC_AGP, fmt, ##__VA_ARGS__); \ 40 } \ 41 } while (0) 42 43 #define RS_APPOINTED_TRACE_BEGIN(node, name) \ 44 do { \ 45 if (Rosen::RSSystemProperties::GetDebugTraceEnabled() || \ 46 Rosen::RSSystemProperties::FindNodeInTargetList(node)) { \ 47 RS_TRACE_BEGIN(name); \ 48 } \ 49 } while (0) 50 51 #define RS_APPOINTED_TRACE_END(node) \ 52 do { \ 53 if (Rosen::RSSystemProperties::GetDebugTraceEnabled() || \ 54 Rosen::RSSystemProperties::FindNodeInTargetList(node)) { \ 55 RS_TRACE_END(); \ 56 } \ 57 } while (0) 58 59 #define RS_OPTIONAL_TRACE_NAME(name) RSOptionalTrace optionalTrace(name) 60 61 #define RS_OPTIONAL_TRACE_FUNC() RSOptionalTrace optionalTrace(__func__) 62 63 #define RS_PROCESS_TRACE(forceEnable, name) RSProcessTrace processTrace(forceEnable, name) 64 65 class RSOptionalTrace { 66 public: RSOptionalTrace(const std::string & traceStr)67 RSOptionalTrace(const std::string& traceStr) 68 { 69 debugTraceEnable_ = OHOS::Rosen::RSSystemProperties::GetDebugTraceEnabled(); 70 if (debugTraceEnable_) { 71 RS_TRACE_BEGIN(traceStr); 72 } 73 } ~RSOptionalTrace()74 ~RSOptionalTrace() 75 { 76 if (debugTraceEnable_) { 77 RS_TRACE_END(); 78 } 79 } 80 81 private: 82 bool debugTraceEnable_ = false; 83 }; 84 85 class RSProcessTrace { 86 public: RSProcessTrace(bool forceEnable,const std::string & traceStr)87 RSProcessTrace(bool forceEnable, const std::string& traceStr) 88 { 89 debugTraceEnable_ = OHOS::Rosen::RSSystemProperties::GetDebugTraceEnabled(); 90 forceEnable_ = forceEnable; 91 if (debugTraceEnable_ || forceEnable_) { 92 RS_TRACE_BEGIN(traceStr); 93 } 94 } ~RSProcessTrace()95 ~RSProcessTrace() 96 { 97 if (debugTraceEnable_ || forceEnable_) { 98 RS_TRACE_END(); 99 } 100 } 101 private: 102 bool debugTraceEnable_ = false; 103 bool forceEnable_ = false; 104 }; 105 #endif // RENDER_SERVICE_BASE_COMMON_OPTIONAL_TRACE