• 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 <cstdint>
23 
24 #include "hilog/log.h"
25 
26 namespace OHOS {
27 namespace PowerMgr {
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 struct BatteryStatsLogLabelDomain {
82     uint32_t domainId;
83     const char* tag;
84 };
85 
86 // Keep the sequence and length same as BatteryStatsLogDomain
87 static const BatteryStatsLogLabelDomain STATS_LABEL[LABEL_END] = {
88     {DOMAIN_APP,       "StatsApp"},
89     {DOMAIN_FRAMEWORK, "StatsFwk"},
90     {DOMAIN_SERVICE,   "StatsSvc"},
91     {DOMAIN_HDI,       "StatsHdi"},
92     {DOMAIN_DRIVER,    "StatsDrv"},
93     {DOMAIN_UTILS,     "StatsUtils"},
94     {DOMAIN_TEST,      "StatsTest"},
95 };
96 
97 #define STATS_HILOGF(domain, ...) \
98     ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
99 #define STATS_HILOGE(domain, ...) \
100     ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
101 #define STATS_HILOGW(domain, ...) \
102     ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
103 #define STATS_HILOGI(domain, ...) \
104     ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
105 #define STATS_HILOGD(domain, ...) \
106     ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
107 } // namespace PowerMgr
108 } // namespace OHOS
109 
110 #else
111 
112 #define STATS_HILOGF(...)
113 #define STATS_HILOGE(...)
114 #define STATS_HILOGW(...)
115 #define STATS_HILOGI(...)
116 #define STATS_HILOGD(...)
117 
118 #endif // CONFIG_HILOG
119 
120 #endif // STATS_LOG_H