• 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 
27 #ifdef STATS_HILOGF
28 #undef STATS_HILOGF
29 #endif
30 
31 #ifdef STATS_HILOGE
32 #undef STATS_HILOGE
33 #endif
34 
35 #ifdef STATS_HILOGW
36 #undef STATS_HILOGW
37 #endif
38 
39 #ifdef STATS_HILOGI
40 #undef STATS_HILOGI
41 #endif
42 
43 #ifdef STATS_HILOGD
44 #undef STATS_HILOGD
45 #endif
46 
47 namespace {
48 // Battery stats reserved domain id range
49 constexpr uint32_t STATS_DOMAIN_ID_START = 0xD002960;
50 constexpr uint32_t STATS_DOMAIN_ID_END = STATS_DOMAIN_ID_START + 32;
51 constexpr uint32_t TEST_DOMAIN_ID = 0xD000F00;
52 }
53 
54 enum BatteryStatsLogLabel {
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     COMP_UTILS = 5,
62     // Test label
63     LABEL_TEST,
64     // The end of labels, max to the domain id range length 32
65     LABEL_END,
66 };
67 
68 enum BatteryStatsLogDomain {
69     DOMAIN_APP = STATS_DOMAIN_ID_START + COMP_APP, // 0xD002960
70     DOMAIN_FRAMEWORK, // 0xD002961
71     DOMAIN_SERVICE, // 0xD002962
72     DOMAIN_HDI, // 0xD002963
73     DOMAIN_DRIVER, // 0xD002964
74     DOMAIN_UTILS, // 0xD002965
75     DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
76     DOMAIN_END = STATS_DOMAIN_ID_END, // Max to 0xD002980, keep the sequence and length same as BatteryStatsLogLabel
77 };
78 
79 struct BatteryStatsLogLabelDomain {
80     uint32_t domainId;
81     const char* tag;
82 };
83 
84 // Keep the sequence and length same as BatteryStatsLogDomain
85 static const BatteryStatsLogLabelDomain STATS_LABEL[LABEL_END] = {
86     {DOMAIN_APP,       "StatsApp"},
87     {DOMAIN_FRAMEWORK, "StatsFwk"},
88     {DOMAIN_SERVICE,   "StatsSvc"},
89     {DOMAIN_HDI,       "StatsHdi"},
90     {DOMAIN_DRIVER,    "StatsDrv"},
91     {DOMAIN_UTILS,     "StatsUtils"},
92     {DOMAIN_TEST,      "StatsTest"},
93 };
94 
95 #define STATS_HILOGF(domain, ...) \
96     ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
97 #define STATS_HILOGE(domain, ...) \
98     ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
99 #define STATS_HILOGW(domain, ...) \
100     ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
101 #define STATS_HILOGI(domain, ...) \
102     ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
103 #define STATS_HILOGD(domain, ...) \
104     ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, STATS_LABEL[domain].domainId, STATS_LABEL[domain].tag, ##__VA_ARGS__))
105 } // namespace PowerMgr
106 } // namespace OHOS
107 
108 #else
109 
110 #define STATS_HILOGF(...)
111 #define STATS_HILOGE(...)
112 #define STATS_HILOGW(...)
113 #define STATS_HILOGI(...)
114 #define STATS_HILOGD(...)
115 
116 #endif // CONFIG_HILOG
117 
118 #endif // STATS_LOG_H