1 /* 2 * Copyright (c) 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 POWER_LOG_H 17 #define POWER_LOG_H 18 19 #define CONFIG_HILOG 20 #ifdef CONFIG_HILOG 21 22 #include "hilog/log.h" 23 24 namespace OHOS { 25 namespace PowerMgr { 26 #define FILE_NAME (__builtin_strrchr("/" __FILE__, '/') + 1) 27 #define FORMATED(fmt, ...) "[%{public}s:%{public}d] %{public}s# " fmt, FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__ 28 29 #ifdef POWER_HILOGF 30 #undef POWER_HILOGF 31 #endif 32 33 #ifdef POWER_HILOGE 34 #undef POWER_HILOGE 35 #endif 36 37 #ifdef POWER_HILOGW 38 #undef POWER_HILOGW 39 #endif 40 41 #ifdef POWER_HILOGI 42 #undef POWER_HILOGI 43 #endif 44 45 #ifdef POWER_HILOGD 46 #undef POWER_HILOGD 47 #endif 48 49 namespace { 50 // Power manager reserved domain id range 51 constexpr unsigned int POWER_DOMAIN_ID_START = 0xD002900; 52 constexpr unsigned int POWER_DOMAIN_ID_END = POWER_DOMAIN_ID_START + 32; 53 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00; 54 } 55 56 enum PowerManagerLogLabel { 57 // Component labels, you can add if needed 58 COMP_APP = 0, 59 COMP_FWK = 1, 60 COMP_SVC = 2, 61 COMP_HDI = 3, 62 COMP_DRV = 4, 63 COMP_UTILS = 5, 64 // Feature labels, use to mark major features 65 FEATURE_WAKEUP, 66 FEATURE_SUSPEND, 67 FEATURE_RUNNING_LOCK, 68 FEATURE_ACTIVITY, 69 FEATURE_POWER_STATE, 70 FEATURE_POWER_MODE, 71 FEATURE_SHUTDOWN, 72 FEATURE_INPUT, 73 // Test label 74 LABEL_TEST, 75 // The end of labels, max to the domain id range length 32 76 LABEL_END, 77 }; 78 79 enum PowerManagerLogDomain { 80 DOMAIN_APP = POWER_DOMAIN_ID_START + COMP_APP, // 0xD002900 81 DOMAIN_FRAMEWORK, // 0xD002901 82 DOMAIN_SERVICE, // 0xD002902 83 DOMAIN_HDI, // 0xD002903 84 DOMAIN_DRIVER, // 0xD002904 85 DOMAIN_UTILS, // 0xD002905 86 DOMAIN_FEATURE_WAKEUP, 87 DOMAIN_FEATURE_SUSPEND, 88 DOMAIN_FEATURE_RUNNING_LOCK, 89 DOMAIN_FEATURE_ACTIVITY, 90 DOMAIN_FEATURE_POWER_STATE, 91 DOMAIN_FEATURE_POWER_MODE, 92 DOMAIN_FEATURE_SHUTDOWN, 93 DOMAIN_FEATURE_INPUT, 94 DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00 95 DOMAIN_END = POWER_DOMAIN_ID_END, // Max to 0xD002920, keep the sequence and length same as PowerManagerLogLabel 96 }; 97 98 // Keep the sequence and length same as PowerManagerLogDomain 99 static constexpr OHOS::HiviewDFX::HiLogLabel POWER_LABEL[LABEL_END] = { 100 {LOG_CORE, DOMAIN_APP, "PowerApp"}, 101 {LOG_CORE, DOMAIN_FRAMEWORK, "PowerFwk"}, 102 {LOG_CORE, DOMAIN_SERVICE, "PowerSvc"}, 103 {LOG_CORE, DOMAIN_HDI, "PowerHdi"}, 104 {LOG_CORE, DOMAIN_DRIVER, "PowerDrv"}, 105 {LOG_CORE, DOMAIN_UTILS, "PowerUtils"}, 106 {LOG_CORE, DOMAIN_FEATURE_WAKEUP, "PowerWakeup"}, 107 {LOG_CORE, DOMAIN_FEATURE_SUSPEND, "PowerSuspend"}, 108 {LOG_CORE, DOMAIN_FEATURE_RUNNING_LOCK, "PowerRunningLock"}, 109 {LOG_CORE, DOMAIN_FEATURE_ACTIVITY, "PowerActivity"}, 110 {LOG_CORE, DOMAIN_FEATURE_POWER_STATE, "PowerState"}, 111 {LOG_CORE, DOMAIN_FEATURE_POWER_MODE, "PowerMode"}, 112 {LOG_CORE, DOMAIN_FEATURE_SHUTDOWN, "PowerShutdown"}, 113 {LOG_CORE, DOMAIN_FEATURE_INPUT, "PowerInput"}, 114 {LOG_CORE, DOMAIN_TEST, "PowerTest"}, 115 }; 116 117 #define POWER_HILOGF(domain, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(POWER_LABEL[domain], FORMATED(__VA_ARGS__)) 118 #define POWER_HILOGE(domain, ...) (void)OHOS::HiviewDFX::HiLog::Error(POWER_LABEL[domain], FORMATED(__VA_ARGS__)) 119 #define POWER_HILOGW(domain, ...) (void)OHOS::HiviewDFX::HiLog::Warn(POWER_LABEL[domain], FORMATED(__VA_ARGS__)) 120 #define POWER_HILOGI(domain, ...) (void)OHOS::HiviewDFX::HiLog::Info(POWER_LABEL[domain], FORMATED(__VA_ARGS__)) 121 #define POWER_HILOGD(domain, ...) (void)OHOS::HiviewDFX::HiLog::Debug(POWER_LABEL[domain], FORMATED(__VA_ARGS__)) 122 123 } // namespace PowerMgr 124 } // namespace OHOS 125 126 #else 127 128 #define POWER_HILOGF(...) 129 #define POWER_HILOGE(...) 130 #define POWER_HILOGW(...) 131 #define POWER_HILOGI(...) 132 #define POWER_HILOGD(...) 133 134 #endif // CONFIG_HILOG 135 136 #endif // POWER_LOG_H 137