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 #ifndef RME_SCOPED_TRACE_H 17 #define RME_SCOPED_TRACE_H 18 19 #include "bytrace.h" 20 21 #include <cstdarg> 22 #include <cstdio> 23 24 #define RME_SCOPED_TRACE(fmt, ...) RmeScopedTrace rmeScopedTrace(fmt, ##__VA_ARGS__) 25 #ifdef RME_DEBUG 26 #define RME_DEBUG_SCOPED_TRACE(fmt, ...) RmeScopedTrace rmeScopedTrace(fmt, ##__VA_ARGS__) 27 #else 28 #define RME_DEBUG_SCOPED_TRACE(fmt, ...) 29 #endif 30 31 #define RME_FUNCTION_TRACE() RME_SCOPED_TRACE(__func__) 32 33 namespace OHOS { 34 namespace RME { 35 bool RmeTraceEnable(); 36 void RmeTraceBegin(const char* name); 37 bool RmeTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2))); 38 bool RmeTraceBeginWithArgvs(const char* format, va_list args); 39 void RmeTraceEnd(); 40 41 class RmeScopedTrace final { 42 public: 43 explicit RmeScopedTrace(const char* format, ...) __attribute__((__format__(printf, 2, 3))); 44 ~RmeScopedTrace(); 45 46 private: 47 bool traceEnabled_ { false }; 48 }; 49 } // namespace RME 50 } // namespace OHOS 51 #endif 52