• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 SOC_PERF_COMMON_INCLUDE_SOCPERF_LOG_H
17 #define SOC_PERF_COMMON_INCLUDE_SOCPERF_LOG_H
18 
19 #include "hilog/log.h"
20 
21 namespace OHOS {
22 namespace SOCPERF {
23 #ifndef LOG_TAG_SOC_PERF
24 #define LOG_TAG_SOC_PERF "socperf"
25 #endif
26 
27 #ifndef LOG_TAG_DOMAIN_ID_SOC_PERF
28 #define LOG_TAG_DOMAIN_ID_SOC_PERF 0xD001703
29 #endif
30 
31 static constexpr OHOS::HiviewDFX::HiLogLabel SOC_PERF_LOG_LABEL = {
32     LOG_CORE,
33     LOG_TAG_DOMAIN_ID_SOC_PERF,
34     LOG_TAG_SOC_PERF
35 };
36 
37 class SocPerfLog {
38 public:
39     SocPerfLog() = delete;
40     ~SocPerfLog() = delete;
41 
IsDebugLogEnabled()42     static bool IsDebugLogEnabled()
43     {
44         return isDebugLogEnabled_;
45     }
46 
EnableDebugLog()47     static void EnableDebugLog()
48     {
49         isDebugLogEnabled_ = true;
50     }
51 
DisableDebugLog()52     static void DisableDebugLog()
53     {
54         isDebugLogEnabled_ = false;
55     }
56 
57 private:
58     static bool isDebugLogEnabled_;
59 };
60 
61 #define SOC_PERF_PRINT_LOG(Level, fmt, ...)                     \
62     OHOS::HiviewDFX::HiLog::Level(SOC_PERF_LOG_LABEL, "[%{public}s]: " fmt, __FUNCTION__, ##__VA_ARGS__)
63 
64 #define SOC_PERF_LOGD(fmt, ...)                                 \
65     if (SocPerfLog::IsDebugLogEnabled())                        \
66     SOC_PERF_PRINT_LOG(Debug, fmt, ##__VA_ARGS__)
67 
68 #define SOC_PERF_LOGI(fmt, ...) SOC_PERF_PRINT_LOG(Info, fmt, ##__VA_ARGS__)
69 #define SOC_PERF_LOGW(fmt, ...) SOC_PERF_PRINT_LOG(Warn, fmt, ##__VA_ARGS__)
70 #define SOC_PERF_LOGE(fmt, ...) SOC_PERF_PRINT_LOG(Error, fmt, ##__VA_ARGS__)
71 #define SOC_PERF_LOGF(fmt, ...) SOC_PERF_PRINT_LOG(Fatal, fmt, ##__VA_ARGS__)
72 } // namespace SOCPERF
73 } // namespace OHOS
74 
75 #endif // SOC_PERF_COMMON_INCLUDE_SOCPERF_LOG_H
76