• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_ACE_TRACE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_ACE_TRACE_H
18 
19 #include <cstdarg>
20 #include <cstdio>
21 
22 #include "base/utils/macros.h"
23 #include "base/utils/noncopyable.h"
24 
25 #define ACE_SCOPED_TRACE(fmt, ...) AceScopedTrace aceScopedTrace(fmt, ##__VA_ARGS__)
26 #ifdef ACE_DEBUG
27 #define ACE_DEBUG_SCOPED_TRACE(fmt, ...) AceScopedTrace aceScopedTrace(fmt, ##__VA_ARGS__)
28 #else
29 #define ACE_DEBUG_SCOPED_TRACE(fmt, ...)
30 #endif
31 
32 #define ACE_FUNCTION_TRACE() ACE_SCOPED_TRACE(__func__)
33 
34 namespace OHOS::Ace {
35 
36 bool ACE_EXPORT AceTraceEnabled();
37 void ACE_EXPORT AceTraceBegin(const char* name);
38 bool ACE_EXPORT AceTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2)));
39 bool ACE_EXPORT AceTraceBeginWithArgv(const char* format, va_list args);
40 void ACE_EXPORT AceTraceEnd();
41 
42 class ACE_EXPORT AceScopedTrace final {
43 public:
44     explicit AceScopedTrace(const char* format, ...) __attribute__((__format__(printf, 2, 3)));
45     ~AceScopedTrace();
46 
47     ACE_DISALLOW_COPY_AND_MOVE(AceScopedTrace);
48 
49 private:
50     bool traceEnabled_ { false };
51 };
52 
53 } // namespace OHOS::Ace
54 
55 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_ACE_TRACE_H
56