• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 GE_TRACE_H
17 #define GE_TRACE_H
18 
19 #ifdef NOT_BUILD_FOR_OHOS_SDK
20 #include "ge_system_properties.h"
21 #include "hitrace_meter.h"
22 
23 namespace OHOS::Rosen {
24 
25 #define LIKELY(exp) (__builtin_expect((exp) != 0, true))
26 #define UNLIKELY(exp) (__builtin_expect((exp) != 0, false))
27 #define GE_TRACE(name)                                                                                                \
28     static bool debugTraceEnable = (OHOS::system::GetIntParameter("persist.sys.graphic.openDebugTrace", 0) != 0);     \
29     auto geNameTrace = (UNLIKELY(debugTraceEnable)) ?                                                                 \
30                         std::make_unique<GEOptionalTrace>(name) :                                                     \
31                         nullptr
32 
33 #define GE_TRACE_FUNC()                                                                                               \
34     static bool debugTraceEnable = (OHOS::system::GetIntParameter("persist.sys.graphic.openDebugTrace", 0) != 0);     \
35     auto geNameTrace = (UNLIKELY(debugTraceEnable)) ?                                                                 \
36                         std::make_unique<GEOptionalTrace>(__func__) :                                                 \
37                         nullptr
38 
39 #define GE_TRACE_NAME_FMT(fmt, ...)                                                                                   \
40     do {                                                                                                              \
41         static bool debugTraceEnable = (OHOS::system::GetIntParameter("persist.sys.graphic.openDebugTrace", 0) != 0); \
42         if (UNLIKELY(debugTraceEnable)) {                                                                             \
43             std::string name { "GE#" };                                                                               \
44             name.append(fmt);                                                                                         \
45             HITRACE_METER_FMT(HITRACE_TAG_GRAPHIC_AGP, name.c_str(), ##__VA_ARGS__);                                  \
46         }                                                                                                             \
47     } while (0)
48 
49 class GEOptionalTrace {
50 public:
GEOptionalTrace(std::string traceStr)51     GEOptionalTrace(std::string traceStr)
52     {
53         std::string name { "GE#" };
54         name.append(traceStr);
55         StartTrace(HITRACE_TAG_GRAPHIC_AGP | HITRACE_TAG_COMMERCIAL, name);
56     }
57 
~GEOptionalTrace()58     ~GEOptionalTrace()
59     {
60         FinishTrace(HITRACE_TAG_GRAPHIC_AGP | HITRACE_TAG_COMMERCIAL);
61     }
62 };
63 } // namespace OHOS::Rosen
64 
65 #else
66 #define GE_TRACE(name)
67 #define GE_TRACE_FUNC()
68 #define GE_TRACE_NAME_FMT(fmt, ...)
69 #endif // NOT_BUILD_FOR_OHOS_SDK
70 
71 #endif // GE_TRACE_H
72