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 #ifndef OHOS_WM_INCLUDE_WM_TRACE_H 17 #define OHOS_WM_INCLUDE_WM_TRACE_H 18 19 #include <cstdarg> 20 #include <cstdio> 21 22 #include "noncopyable.h" 23 24 #define WM_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__) 25 #ifdef WM_DEBUG 26 #define WM_DEBUG_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__) 27 #else 28 #define WM_DEBUG_SCOPED_TRACE(fmt, ...) 29 #endif 30 31 #define WM_FUNCTION_TRACE() WM_SCOPED_TRACE(__func__) 32 #define WM_SCOPED_TRACE_BEGIN(fmt, ...) WmTraceBeginWithArgs(fmt, ##__VA_ARGS__) 33 #define WM_SCOPED_TRACE_END() WmTraceEnd() 34 35 namespace OHOS { 36 namespace Rosen { 37 bool WmTraceEnabled(); 38 void WmTraceBegin(const char* name); 39 bool WmTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2))); 40 bool WmTraceBeginWithArgv(const char* format, va_list args); 41 void WmTraceEnd(); 42 43 class WmScopedTrace final { 44 public: 45 explicit WmScopedTrace(const char* format, ...) __attribute__((__format__(printf, 2, 3))); 46 ~WmScopedTrace(); 47 48 WM_DISALLOW_COPY_AND_MOVE(WmScopedTrace); 49 50 private: 51 bool traceEnabled_ { false }; 52 }; 53 } // namespace OHOS 54 } 55 #endif // OHOS_WM_INCLUDE_WM_TRACE_H