• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 HILOG_CMD_H
17 #define HILOG_CMD_H
18 
19 #include "hilog_common.h"
20 #include "hilog/log.h"
21 
22 #define MSG_VER (0)
23 #define MAX_DOMAINS (5)
24 #define MAX_TAGS (10)
25 #define MAX_PIDS (5)
26 #define MAX_FILE_NAME_LEN (64)
27 #define MAX_STREAM_NAME_LEN (16)
28 #define MAX_PROC_NAME_LEN (32)
29 
30 constexpr int LevelBase = static_cast<int>(LOG_DEBUG);
31 constexpr int LevelNum = static_cast<int>(LOG_LEVEL_MAX) - LevelBase;
32 constexpr int TypeNum = static_cast<int>(LOG_TYPE_MAX);
33 
34 enum class IoctlCmd {
35     INVALID = -1,
36     OUTPUT_RQST = 1,
37     OUTPUT_RSP,
38     PERSIST_START_RQST,
39     PERSIST_START_RSP,
40     PERSIST_STOP_RQST,
41     PERSIST_STOP_RSP,
42     PERSIST_QUERY_RQST,
43     PERSIST_QUERY_RSP,
44     PERSIST_REFRESH_RQST,
45     PERSIST_REFRESH_RSP,
46     PERSIST_CLEAR_RQST,
47     PERSIST_CLEAR_RSP,
48     BUFFERSIZE_GET_RQST,
49     BUFFERSIZE_GET_RSP,
50     BUFFERSIZE_SET_RQST,
51     BUFFERSIZE_SET_RSP,
52     STATS_QUERY_RQST,
53     STATS_QUERY_RSP,
54     STATS_CLEAR_RQST,
55     STATS_CLEAR_RSP,
56     DOMAIN_FLOWCTRL_RQST,
57     DOMAIN_FLOWCTRL_RSP,
58     LOG_REMOVE_RQST,
59     LOG_REMOVE_RSP,
60     KMSG_ENABLE_RQST,
61     KMSG_ENABLE_RSP,
62     // Process error response with same logic
63     RSP_ERROR,
64     CMD_COUNT
65 };
66 
67 struct MsgHeader {
68     uint8_t ver;
69     uint8_t cmd;
70     int16_t err;
71     uint16_t len;
72 } __attribute__((__packed__));
73 
74 struct OutputRqst {
75     uint16_t headLines;
76     uint16_t types;
77     uint16_t levels;
78     bool blackDomain;
79     uint8_t domainCount;
80     uint32_t domains[MAX_DOMAINS];
81     bool blackTag;
82     uint8_t tagCount;
83     char tags[MAX_TAGS][MAX_TAG_LEN];
84     bool blackPid;
85     int pidCount;
86     uint32_t pids[MAX_PIDS];
87     char regex[MAX_REGEX_STR_LEN];
88     bool noBlock;
89     uint16_t tailLines;
90 } __attribute__((__packed__));
91 
92 struct OutputRsp {
93     uint16_t len; /* data len, equals tagLen plus content length, include '\0' */
94     uint8_t level;
95     uint8_t type;
96     uint32_t pid;
97     uint32_t tid;
98     uint32_t domain;
99     uint32_t tv_sec;
100     uint32_t tv_nsec;
101     uint32_t mono_sec;
102     uint8_t tagLen;
103     bool end;
104     char data[]; /* tag and content, include '\0' */
105 } __attribute__((__packed__));
106 
107 enum class FormatTime {
108     INVALID = 0,
109     TIME = 1,
110     EPOCH,
111     MONOTONIC,
112 };
113 
114 enum class FormatTimeAccu {
115     INVALID = 0,
116     MSEC,
117     USEC,
118     NSEC,
119 };
120 
121 struct PersistStartRqst {
122     OutputRqst outputFilter;
123     uint32_t jobId;
124     uint32_t fileSize;
125     uint16_t fileNum;
126     char fileName[MAX_FILE_NAME_LEN];
127     char stream[MAX_STREAM_NAME_LEN];
128 } __attribute__((__packed__));
129 
130 struct PersistStartRsp {
131     uint32_t jobId;
132 } __attribute__((__packed__));
133 
134 struct PersistStopRqst {
135     uint32_t jobId;
136 } __attribute__((__packed__));
137 
138 struct PersistStopRsp {
139     uint8_t jobNum;
140     uint32_t jobId[MAX_JOBS];
141 } __attribute__((__packed__));
142 
143 struct PersistQueryRqst {
144     char placeholder; // Query tasks needn't any parameter, this is just a placeholder
145 } __attribute__((__packed__));
146 
147 using PersistTaskInfo = struct PersistStartRqst;
148 struct PersistQueryRsp {
149     uint8_t jobNum;
150     PersistTaskInfo taskInfo[MAX_JOBS];
151 } __attribute__((__packed__));
152 
153 struct PersistRefreshRqst {
154     uint32_t jobId;
155 } __attribute__((__packed__));
156 
157 struct PersistRefreshRsp {
158     uint8_t jobNum;
159     uint32_t jobId[MAX_JOBS];
160 } __attribute__((__packed__));
161 
162 struct PersistClearRqst {
163     char placeholder; // Clear tasks needn't any parameter, this is just a placeholder
164 } __attribute__((__packed__));
165 
166 struct PersistClearRsp {
167     char placeholder;
168 } __attribute__((__packed__));
169 
170 struct BufferSizeSetRqst {
171     uint16_t types;
172     int32_t size;
173 } __attribute__((__packed__));
174 
175 struct BufferSizeSetRsp {
176     int32_t size[LOG_TYPE_MAX];
177 } __attribute__((__packed__));
178 
179 struct BufferSizeGetRqst {
180     uint16_t types;
181 } __attribute__((__packed__));
182 
183 struct BufferSizeGetRsp {
184     uint32_t size[LOG_TYPE_MAX];
185 } __attribute__((__packed__));
186 
187 struct StatsQueryRqst {
188     uint16_t types;
189     uint8_t domainCount;
190     uint32_t domains[MAX_DOMAINS];
191 } __attribute__((__packed__));
192 
193 struct StatsRsp {
194     uint32_t lines[LevelNum];
195     uint64_t len[LevelNum];
196     uint32_t dropped;
197     float freqMax; // lines per second, average value
198     uint32_t freqMaxSec;
199     uint32_t freqMaxNsec;
200     float throughputMax; // length per second, average value
201     uint32_t tpMaxSec;
202     uint32_t tpMaxNsec;
203 } __attribute__((__packed__));
204 
205 struct TagStatsRsp {
206     char tag[MAX_TAG_LEN];
207     StatsRsp stats;
208 } __attribute__((__packed__));
209 
210 struct DomainStatsRsp {
211     uint32_t domain;
212     StatsRsp stats;
213     uint16_t tagNum;
214     TagStatsRsp *tStats;
215 } __attribute__((__packed__));
216 
217 struct LogTypeDomainStatsRsp {
218     uint16_t type;
219     uint16_t domainNum;
220     DomainStatsRsp *dStats;
221 } __attribute__((__packed__));
222 
223 struct LogTypeStatsRsp {
224     uint16_t type;
225     StatsRsp stats;
226 } __attribute__((__packed__));
227 
228 struct ProcStatsRsp {
229     uint32_t pid;
230     char name[MAX_PROC_NAME_LEN];
231     StatsRsp stats;
232     uint16_t typeNum;
233     uint16_t tagNum;
234     LogTypeStatsRsp *lStats;
235     TagStatsRsp *tStats;
236 } __attribute__((__packed__));
237 
238 struct StatsQueryRsp {
239     uint32_t tsBeginSec;
240     uint32_t tsBeginNsec;
241     uint32_t durationSec;
242     uint32_t durationNsec;
243     uint32_t totalLines[LevelNum];
244     uint64_t totalLens[LevelNum];
245     uint16_t typeNum;
246     uint16_t procNum;
247     LogTypeDomainStatsRsp *ldStats;
248     ProcStatsRsp *pStats;
249 } __attribute__((__packed__));
250 
251 struct StatsClearRqst {
252     char placeholder;
253 } __attribute__((__packed__));
254 
255 struct StatsClearRsp {
256     char placeholder;
257 } __attribute__((__packed__));
258 
259 struct DomainFlowCtrlRqst {
260     bool on;
261 } __attribute__((__packed__));
262 
263 struct DomainFlowCtrlRsp {
264     char placeholder;
265 } __attribute__((__packed__));
266 
267 struct LogRemoveRqst {
268     uint16_t types;
269 } __attribute__((__packed__));
270 
271 struct LogRemoveRsp {
272     uint16_t types;
273 } __attribute__((__packed__));
274 
275 struct KmsgEnableRqst {
276     bool on;
277 } __attribute__((__packed__));
278 
279 struct KmsgEnableRsp {
280     char placeholder;
281 } __attribute__((__packed__));
282 #endif /* HILOG_CMD_H */