• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 STATS_LOG_H
17 #define STATS_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 FORMAT(fmt, ...) "[%{public}s:%{public}d] %{public}s# " fmt, FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__
28 
29 #ifdef STATS_HILOGF
30 #undef STATS_HILOGF
31 #endif
32 
33 #ifdef STATS_HILOGE
34 #undef STATS_HILOGE
35 #endif
36 
37 #ifdef STATS_HILOGW
38 #undef STATS_HILOGW
39 #endif
40 
41 #ifdef STATS_HILOGI
42 #undef STATS_HILOGI
43 #endif
44 
45 #ifdef STATS_HILOGD
46 #undef STATS_HILOGD
47 #endif
48 
49 namespace {
50 // Battery stats reserved domain id range
51 constexpr uint32_t STATS_DOMAIN_ID_START = 0xD002960;
52 constexpr uint32_t STATS_DOMAIN_ID_END = STATS_DOMAIN_ID_START + 32;
53 constexpr uint32_t TEST_DOMAIN_ID = 0xD000F00;
54 }
55 
56 enum BatteryStatsLogLabel {
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     // Test label
65     LABEL_TEST,
66     // The end of labels, max to the domain id range length 32
67     LABEL_END,
68 };
69 
70 enum BatteryStatsLogDomain {
71     DOMAIN_APP = STATS_DOMAIN_ID_START + COMP_APP, // 0xD002960
72     DOMAIN_FRAMEWORK, // 0xD002961
73     DOMAIN_SERVICE, // 0xD002962
74     DOMAIN_HDI, // 0xD002963
75     DOMAIN_DRIVER, // 0xD002964
76     DOMAIN_UTILS, // 0xD002965
77     DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
78     DOMAIN_END = STATS_DOMAIN_ID_END, // Max to 0xD002980, keep the sequence and length same as BatteryStatsLogLabel
79 };
80 
81 // Keep the sequence and length same as BatteryStatsLogDomain
82 static constexpr OHOS::HiviewDFX::HiLogLabel STATS_LABEL[LABEL_END] = {
83     {LOG_CORE, DOMAIN_APP,       "StatsApp"},
84     {LOG_CORE, DOMAIN_FRAMEWORK, "StatsFwk"},
85     {LOG_CORE, DOMAIN_SERVICE,   "StatsSvc"},
86     {LOG_CORE, DOMAIN_HDI,       "StatsHdi"},
87     {LOG_CORE, DOMAIN_DRIVER,    "StatsDrv"},
88     {LOG_CORE, DOMAIN_UTILS,     "StatsUtils"},
89     {LOG_CORE, DOMAIN_TEST,      "StatsTest"},
90 };
91 
92 #define STATS_HILOGF(domain, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(STATS_LABEL[domain], FORMAT(__VA_ARGS__))
93 #define STATS_HILOGE(domain, ...) (void)OHOS::HiviewDFX::HiLog::Error(STATS_LABEL[domain], FORMAT(__VA_ARGS__))
94 #define STATS_HILOGW(domain, ...) (void)OHOS::HiviewDFX::HiLog::Warn(STATS_LABEL[domain], FORMAT(__VA_ARGS__))
95 #define STATS_HILOGI(domain, ...) (void)OHOS::HiviewDFX::HiLog::Info(STATS_LABEL[domain], FORMAT(__VA_ARGS__))
96 #define STATS_HILOGD(domain, ...) (void)OHOS::HiviewDFX::HiLog::Debug(STATS_LABEL[domain], FORMAT(__VA_ARGS__))
97 } // namespace PowerMgr
98 } // namespace OHOS
99 
100 #else
101 
102 #define STATS_HILOGF(...)
103 #define STATS_HILOGE(...)
104 #define STATS_HILOGW(...)
105 #define STATS_HILOGI(...)
106 #define STATS_HILOGD(...)
107 
108 #endif // CONFIG_HILOG
109 
110 #endif // STATS_LOG_H