• 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 THERMAL_LOG_H
17 #define THERMAL_LOG_H
18 
19 #define CONFIG_HILOG
20 #ifdef CONFIG_HILOG
21 #include "hilog/log.h"
22 namespace OHOS {
23 namespace PowerMgr {
24 #define FILENAME (__builtin_strrchr("/" __FILE__, '/') + 1)
25 #define FORMAT(fmt, ...) "[%{public}s:%{public}d] %{public}s# " fmt, FILENAME, __LINE__, __FUNCTION__, ##__VA_ARGS__
26 
27 #ifdef THERMAL_HILOGF
28 #undef THERMAL_HILOGF
29 #endif
30 
31 #ifdef THERMAL_HILOGE
32 #undef THERMAL_HILOGE
33 #endif
34 
35 #ifdef THERMAL_HILOGW
36 #undef THERMAL_HILOGW
37 #endif
38 
39 #ifdef THERMAL_HILOGI
40 #undef THERMAL_HILOGI
41 #endif
42 
43 #ifdef THERMAL_HILOGD
44 #undef THERMAL_HILOGD
45 #endif
46 
47 namespace {
48 // Thermal manager reserved domain id range
49 constexpr unsigned int THERMAL_DOMAIN_ID_START = 0xD002940;
50 constexpr unsigned int THERMAL_DOMAIN_ID_END = THERMAL_DOMAIN_ID_START + 32;
51 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
52 }
53 
54 enum ThermalManagerLogLabel {
55     // Component labels, you can add if needed
56     COMP_APP = 0,
57     COMP_FWK = 1,
58     COMP_SVC = 2,
59     COMP_HDI = 3,
60     COMP_DRV = 4,
61     // Feature labels, use to mark major features
62     FEATURE_PROTECTOR,
63     // Test label
64     LABEL_TEST,
65     // The end of labels, max to the domain id range length 32
66     LABEL_END,
67 };
68 
69 enum ThermalManagerLogDomain {
70     DOMAIN_APP = THERMAL_DOMAIN_ID_START + COMP_APP, // 0xD002940
71     DOMAIN_FRAMEWORK, // 0xD002941
72     DOMAIN_SERVICE, // 0xD002942
73     DOMAIN_HDI, // 0xD002943
74     DOMAIN_DRIVER, // 0xD002944
75     DOMAIN_FEATURE_PROTECTOR,
76     DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
77     DOMAIN_END = THERMAL_DOMAIN_ID_END, // Max to 0xD002960, keep the sequence and length same as ThermalManagerLogLabel
78 };
79 
80 // Keep the sequence and length same as ThermalManagerLogDomain
81 static constexpr OHOS::HiviewDFX::HiLogLabel THERMAL_LABEL[LABEL_END] = {
82     {LOG_CORE, DOMAIN_APP, "ThermalApp"},
83     {LOG_CORE, DOMAIN_FRAMEWORK, "ThermalFwk"},
84     {LOG_CORE, DOMAIN_SERVICE, "ThermalSvc"},
85     {LOG_CORE, DOMAIN_HDI, "ThermalHdi"},
86     {LOG_CORE, DOMAIN_DRIVER, "ThermalDrv"},
87     {LOG_CORE, DOMAIN_FEATURE_PROTECTOR, "ThermalProtector"},
88     {LOG_CORE, DOMAIN_TEST, "ThermalTest"},
89 };
90 
91 // In order to improve performance, do not check the module range, module should less than THERMALMGR_MODULE_BUTT.
92 #define THERMAL_HILOGF(module, ...) \
93     (void)OHOS::HiviewDFX::HiLog::Fatal(THERMAL_LABEL[module], FORMAT(__VA_ARGS__))
94 #define THERMAL_HILOGE(module, ...) \
95     (void)OHOS::HiviewDFX::HiLog::Error(THERMAL_LABEL[module], FORMAT(__VA_ARGS__))
96 #define THERMAL_HILOGW(module, ...) \
97     (void)OHOS::HiviewDFX::HiLog::Warn(THERMAL_LABEL[module], FORMAT(__VA_ARGS__))
98 #define THERMAL_HILOGI(module, ...) \
99     (void)OHOS::HiviewDFX::HiLog::Info(THERMAL_LABEL[module], FORMAT(__VA_ARGS__))
100 #define THERMAL_HILOGD(module, ...) \
101     (void)OHOS::HiviewDFX::HiLog::Debug(THERMAL_LABEL[module], FORMAT(__VA_ARGS__))
102 } // namespace PowerMgr
103 } // namespace OHOS
104 
105 #else
106 
107 #define THERMAL_HILOGF(...)
108 #define THERMAL_HILOGE(...)
109 #define THERMAL_HILOGW(...)
110 #define THERMAL_HILOGI(...)
111 #define THERMAL_HILOGD(...)
112 
113 #endif // CONFIG_HILOG
114 #endif // THERMAL_LOG_H
115