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