12498b56bSopenharmony_ci/* 22498b56bSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 32498b56bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42498b56bSopenharmony_ci * you may not use this file except in compliance with the License. 52498b56bSopenharmony_ci * You may obtain a copy of the License at 62498b56bSopenharmony_ci * 72498b56bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82498b56bSopenharmony_ci * 92498b56bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102498b56bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112498b56bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122498b56bSopenharmony_ci * See the License for the specific language governing permissions and 132498b56bSopenharmony_ci * limitations under the License. 142498b56bSopenharmony_ci */ 152498b56bSopenharmony_ci 162498b56bSopenharmony_ci#ifndef HILOG_CMD_H 172498b56bSopenharmony_ci#define HILOG_CMD_H 182498b56bSopenharmony_ci 192498b56bSopenharmony_ci#include "hilog_common.h" 202498b56bSopenharmony_ci#include "hilog/log.h" 212498b56bSopenharmony_ci 222498b56bSopenharmony_ci#define MSG_VER (0) 232498b56bSopenharmony_ci#define MAX_DOMAINS (5) 242498b56bSopenharmony_ci#define MAX_TAGS (10) 252498b56bSopenharmony_ci#define MAX_PIDS (5) 262498b56bSopenharmony_ci#define MAX_FILE_NAME_LEN (64) 272498b56bSopenharmony_ci#define MAX_STREAM_NAME_LEN (16) 282498b56bSopenharmony_ci#define MAX_PROC_NAME_LEN (32) 292498b56bSopenharmony_ci 302498b56bSopenharmony_ciconstexpr int LevelBase = static_cast<int>(LOG_DEBUG); 312498b56bSopenharmony_ciconstexpr int LevelNum = static_cast<int>(LOG_LEVEL_MAX) - LevelBase; 322498b56bSopenharmony_ciconstexpr int TypeNum = static_cast<int>(LOG_TYPE_MAX); 332498b56bSopenharmony_ci 342498b56bSopenharmony_cienum class IoctlCmd { 352498b56bSopenharmony_ci INVALID = -1, 362498b56bSopenharmony_ci OUTPUT_RQST = 1, 372498b56bSopenharmony_ci OUTPUT_RSP, 382498b56bSopenharmony_ci PERSIST_START_RQST, 392498b56bSopenharmony_ci PERSIST_START_RSP, 402498b56bSopenharmony_ci PERSIST_STOP_RQST, 412498b56bSopenharmony_ci PERSIST_STOP_RSP, 422498b56bSopenharmony_ci PERSIST_QUERY_RQST, 432498b56bSopenharmony_ci PERSIST_QUERY_RSP, 442498b56bSopenharmony_ci PERSIST_REFRESH_RQST, 452498b56bSopenharmony_ci PERSIST_REFRESH_RSP, 462498b56bSopenharmony_ci PERSIST_CLEAR_RQST, 472498b56bSopenharmony_ci PERSIST_CLEAR_RSP, 482498b56bSopenharmony_ci BUFFERSIZE_GET_RQST, 492498b56bSopenharmony_ci BUFFERSIZE_GET_RSP, 502498b56bSopenharmony_ci BUFFERSIZE_SET_RQST, 512498b56bSopenharmony_ci BUFFERSIZE_SET_RSP, 522498b56bSopenharmony_ci STATS_QUERY_RQST, 532498b56bSopenharmony_ci STATS_QUERY_RSP, 542498b56bSopenharmony_ci STATS_CLEAR_RQST, 552498b56bSopenharmony_ci STATS_CLEAR_RSP, 562498b56bSopenharmony_ci DOMAIN_FLOWCTRL_RQST, 572498b56bSopenharmony_ci DOMAIN_FLOWCTRL_RSP, 582498b56bSopenharmony_ci LOG_REMOVE_RQST, 592498b56bSopenharmony_ci LOG_REMOVE_RSP, 602498b56bSopenharmony_ci KMSG_ENABLE_RQST, 612498b56bSopenharmony_ci KMSG_ENABLE_RSP, 622498b56bSopenharmony_ci // Process error response with same logic 632498b56bSopenharmony_ci RSP_ERROR, 642498b56bSopenharmony_ci CMD_COUNT 652498b56bSopenharmony_ci}; 662498b56bSopenharmony_ci 672498b56bSopenharmony_cistruct MsgHeader { 682498b56bSopenharmony_ci uint8_t ver; 692498b56bSopenharmony_ci uint8_t cmd; 702498b56bSopenharmony_ci int16_t err; 712498b56bSopenharmony_ci uint16_t len; 722498b56bSopenharmony_ci} __attribute__((__packed__)); 732498b56bSopenharmony_ci 742498b56bSopenharmony_cistruct OutputRqst { 752498b56bSopenharmony_ci uint16_t headLines; 762498b56bSopenharmony_ci uint16_t types; 772498b56bSopenharmony_ci uint16_t levels; 782498b56bSopenharmony_ci bool blackDomain; 792498b56bSopenharmony_ci uint8_t domainCount; 802498b56bSopenharmony_ci uint32_t domains[MAX_DOMAINS]; 812498b56bSopenharmony_ci bool blackTag; 822498b56bSopenharmony_ci uint8_t tagCount; 832498b56bSopenharmony_ci char tags[MAX_TAGS][MAX_TAG_LEN]; 842498b56bSopenharmony_ci bool blackPid; 852498b56bSopenharmony_ci int pidCount; 862498b56bSopenharmony_ci uint32_t pids[MAX_PIDS]; 872498b56bSopenharmony_ci char regex[MAX_REGEX_STR_LEN]; 882498b56bSopenharmony_ci bool noBlock; 892498b56bSopenharmony_ci uint16_t tailLines; 902498b56bSopenharmony_ci} __attribute__((__packed__)); 912498b56bSopenharmony_ci 922498b56bSopenharmony_cistruct OutputRsp { 932498b56bSopenharmony_ci uint16_t len; /* data len, equals tagLen plus content length, include '\0' */ 942498b56bSopenharmony_ci uint8_t level; 952498b56bSopenharmony_ci uint8_t type; 962498b56bSopenharmony_ci uint32_t pid; 972498b56bSopenharmony_ci uint32_t tid; 982498b56bSopenharmony_ci uint32_t domain; 992498b56bSopenharmony_ci uint32_t tv_sec; 1002498b56bSopenharmony_ci uint32_t tv_nsec; 1012498b56bSopenharmony_ci uint32_t mono_sec; 1022498b56bSopenharmony_ci uint8_t tagLen; 1032498b56bSopenharmony_ci bool end; 1042498b56bSopenharmony_ci char data[]; /* tag and content, include '\0' */ 1052498b56bSopenharmony_ci} __attribute__((__packed__)); 1062498b56bSopenharmony_ci 1072498b56bSopenharmony_cienum class FormatTime { 1082498b56bSopenharmony_ci INVALID = 0, 1092498b56bSopenharmony_ci TIME = 1, 1102498b56bSopenharmony_ci EPOCH, 1112498b56bSopenharmony_ci MONOTONIC, 1122498b56bSopenharmony_ci}; 1132498b56bSopenharmony_ci 1142498b56bSopenharmony_cienum class FormatTimeAccu { 1152498b56bSopenharmony_ci INVALID = 0, 1162498b56bSopenharmony_ci MSEC, 1172498b56bSopenharmony_ci USEC, 1182498b56bSopenharmony_ci NSEC, 1192498b56bSopenharmony_ci}; 1202498b56bSopenharmony_ci 1212498b56bSopenharmony_cistruct PersistStartRqst { 1222498b56bSopenharmony_ci OutputRqst outputFilter; 1232498b56bSopenharmony_ci uint32_t jobId; 1242498b56bSopenharmony_ci uint32_t fileSize; 1252498b56bSopenharmony_ci uint16_t fileNum; 1262498b56bSopenharmony_ci char fileName[MAX_FILE_NAME_LEN]; 1272498b56bSopenharmony_ci char stream[MAX_STREAM_NAME_LEN]; 1282498b56bSopenharmony_ci} __attribute__((__packed__)); 1292498b56bSopenharmony_ci 1302498b56bSopenharmony_cistruct PersistStartRsp { 1312498b56bSopenharmony_ci uint32_t jobId; 1322498b56bSopenharmony_ci} __attribute__((__packed__)); 1332498b56bSopenharmony_ci 1342498b56bSopenharmony_cistruct PersistStopRqst { 1352498b56bSopenharmony_ci uint32_t jobId; 1362498b56bSopenharmony_ci} __attribute__((__packed__)); 1372498b56bSopenharmony_ci 1382498b56bSopenharmony_cistruct PersistStopRsp { 1392498b56bSopenharmony_ci uint8_t jobNum; 1402498b56bSopenharmony_ci uint32_t jobId[MAX_JOBS]; 1412498b56bSopenharmony_ci} __attribute__((__packed__)); 1422498b56bSopenharmony_ci 1432498b56bSopenharmony_cistruct PersistQueryRqst { 1442498b56bSopenharmony_ci char placeholder; // Query tasks needn't any parameter, this is just a placeholder 1452498b56bSopenharmony_ci} __attribute__((__packed__)); 1462498b56bSopenharmony_ci 1472498b56bSopenharmony_ciusing PersistTaskInfo = struct PersistStartRqst; 1482498b56bSopenharmony_cistruct PersistQueryRsp { 1492498b56bSopenharmony_ci uint8_t jobNum; 1502498b56bSopenharmony_ci PersistTaskInfo taskInfo[MAX_JOBS]; 1512498b56bSopenharmony_ci} __attribute__((__packed__)); 1522498b56bSopenharmony_ci 1532498b56bSopenharmony_cistruct PersistRefreshRqst { 1542498b56bSopenharmony_ci uint32_t jobId; 1552498b56bSopenharmony_ci} __attribute__((__packed__)); 1562498b56bSopenharmony_ci 1572498b56bSopenharmony_cistruct PersistRefreshRsp { 1582498b56bSopenharmony_ci uint8_t jobNum; 1592498b56bSopenharmony_ci uint32_t jobId[MAX_JOBS]; 1602498b56bSopenharmony_ci} __attribute__((__packed__)); 1612498b56bSopenharmony_ci 1622498b56bSopenharmony_cistruct PersistClearRqst { 1632498b56bSopenharmony_ci char placeholder; // Clear tasks needn't any parameter, this is just a placeholder 1642498b56bSopenharmony_ci} __attribute__((__packed__)); 1652498b56bSopenharmony_ci 1662498b56bSopenharmony_cistruct PersistClearRsp { 1672498b56bSopenharmony_ci char placeholder; 1682498b56bSopenharmony_ci} __attribute__((__packed__)); 1692498b56bSopenharmony_ci 1702498b56bSopenharmony_cistruct BufferSizeSetRqst { 1712498b56bSopenharmony_ci uint16_t types; 1722498b56bSopenharmony_ci int32_t size; 1732498b56bSopenharmony_ci} __attribute__((__packed__)); 1742498b56bSopenharmony_ci 1752498b56bSopenharmony_cistruct BufferSizeSetRsp { 1762498b56bSopenharmony_ci int32_t size[LOG_TYPE_MAX]; 1772498b56bSopenharmony_ci} __attribute__((__packed__)); 1782498b56bSopenharmony_ci 1792498b56bSopenharmony_cistruct BufferSizeGetRqst { 1802498b56bSopenharmony_ci uint16_t types; 1812498b56bSopenharmony_ci} __attribute__((__packed__)); 1822498b56bSopenharmony_ci 1832498b56bSopenharmony_cistruct BufferSizeGetRsp { 1842498b56bSopenharmony_ci uint32_t size[LOG_TYPE_MAX]; 1852498b56bSopenharmony_ci} __attribute__((__packed__)); 1862498b56bSopenharmony_ci 1872498b56bSopenharmony_cistruct StatsQueryRqst { 1882498b56bSopenharmony_ci uint16_t types; 1892498b56bSopenharmony_ci uint8_t domainCount; 1902498b56bSopenharmony_ci uint32_t domains[MAX_DOMAINS]; 1912498b56bSopenharmony_ci} __attribute__((__packed__)); 1922498b56bSopenharmony_ci 1932498b56bSopenharmony_cistruct StatsRsp { 1942498b56bSopenharmony_ci uint32_t lines[LevelNum]; 1952498b56bSopenharmony_ci uint64_t len[LevelNum]; 1962498b56bSopenharmony_ci uint32_t dropped; 1972498b56bSopenharmony_ci float freqMax; // lines per second, average value 1982498b56bSopenharmony_ci uint32_t freqMaxSec; 1992498b56bSopenharmony_ci uint32_t freqMaxNsec; 2002498b56bSopenharmony_ci float throughputMax; // length per second, average value 2012498b56bSopenharmony_ci uint32_t tpMaxSec; 2022498b56bSopenharmony_ci uint32_t tpMaxNsec; 2032498b56bSopenharmony_ci} __attribute__((__packed__)); 2042498b56bSopenharmony_ci 2052498b56bSopenharmony_cistruct TagStatsRsp { 2062498b56bSopenharmony_ci char tag[MAX_TAG_LEN]; 2072498b56bSopenharmony_ci StatsRsp stats; 2082498b56bSopenharmony_ci} __attribute__((__packed__)); 2092498b56bSopenharmony_ci 2102498b56bSopenharmony_cistruct DomainStatsRsp { 2112498b56bSopenharmony_ci uint32_t domain; 2122498b56bSopenharmony_ci StatsRsp stats; 2132498b56bSopenharmony_ci uint16_t tagNum; 2142498b56bSopenharmony_ci TagStatsRsp *tStats; 2152498b56bSopenharmony_ci} __attribute__((__packed__)); 2162498b56bSopenharmony_ci 2172498b56bSopenharmony_cistruct LogTypeDomainStatsRsp { 2182498b56bSopenharmony_ci uint16_t type; 2192498b56bSopenharmony_ci uint16_t domainNum; 2202498b56bSopenharmony_ci DomainStatsRsp *dStats; 2212498b56bSopenharmony_ci} __attribute__((__packed__)); 2222498b56bSopenharmony_ci 2232498b56bSopenharmony_cistruct LogTypeStatsRsp { 2242498b56bSopenharmony_ci uint16_t type; 2252498b56bSopenharmony_ci StatsRsp stats; 2262498b56bSopenharmony_ci} __attribute__((__packed__)); 2272498b56bSopenharmony_ci 2282498b56bSopenharmony_cistruct ProcStatsRsp { 2292498b56bSopenharmony_ci uint32_t pid; 2302498b56bSopenharmony_ci char name[MAX_PROC_NAME_LEN]; 2312498b56bSopenharmony_ci StatsRsp stats; 2322498b56bSopenharmony_ci uint16_t typeNum; 2332498b56bSopenharmony_ci uint16_t tagNum; 2342498b56bSopenharmony_ci LogTypeStatsRsp *lStats; 2352498b56bSopenharmony_ci TagStatsRsp *tStats; 2362498b56bSopenharmony_ci} __attribute__((__packed__)); 2372498b56bSopenharmony_ci 2382498b56bSopenharmony_cistruct StatsQueryRsp { 2392498b56bSopenharmony_ci uint32_t tsBeginSec; 2402498b56bSopenharmony_ci uint32_t tsBeginNsec; 2412498b56bSopenharmony_ci uint32_t durationSec; 2422498b56bSopenharmony_ci uint32_t durationNsec; 2432498b56bSopenharmony_ci uint32_t totalLines[LevelNum]; 2442498b56bSopenharmony_ci uint64_t totalLens[LevelNum]; 2452498b56bSopenharmony_ci uint16_t typeNum; 2462498b56bSopenharmony_ci uint16_t procNum; 2472498b56bSopenharmony_ci LogTypeDomainStatsRsp *ldStats; 2482498b56bSopenharmony_ci ProcStatsRsp *pStats; 2492498b56bSopenharmony_ci} __attribute__((__packed__)); 2502498b56bSopenharmony_ci 2512498b56bSopenharmony_cistruct StatsClearRqst { 2522498b56bSopenharmony_ci char placeholder; 2532498b56bSopenharmony_ci} __attribute__((__packed__)); 2542498b56bSopenharmony_ci 2552498b56bSopenharmony_cistruct StatsClearRsp { 2562498b56bSopenharmony_ci char placeholder; 2572498b56bSopenharmony_ci} __attribute__((__packed__)); 2582498b56bSopenharmony_ci 2592498b56bSopenharmony_cistruct DomainFlowCtrlRqst { 2602498b56bSopenharmony_ci bool on; 2612498b56bSopenharmony_ci} __attribute__((__packed__)); 2622498b56bSopenharmony_ci 2632498b56bSopenharmony_cistruct DomainFlowCtrlRsp { 2642498b56bSopenharmony_ci char placeholder; 2652498b56bSopenharmony_ci} __attribute__((__packed__)); 2662498b56bSopenharmony_ci 2672498b56bSopenharmony_cistruct LogRemoveRqst { 2682498b56bSopenharmony_ci uint16_t types; 2692498b56bSopenharmony_ci} __attribute__((__packed__)); 2702498b56bSopenharmony_ci 2712498b56bSopenharmony_cistruct LogRemoveRsp { 2722498b56bSopenharmony_ci uint16_t types; 2732498b56bSopenharmony_ci} __attribute__((__packed__)); 2742498b56bSopenharmony_ci 2752498b56bSopenharmony_cistruct KmsgEnableRqst { 2762498b56bSopenharmony_ci bool on; 2772498b56bSopenharmony_ci} __attribute__((__packed__)); 2782498b56bSopenharmony_ci 2792498b56bSopenharmony_cistruct KmsgEnableRsp { 2802498b56bSopenharmony_ci char placeholder; 2812498b56bSopenharmony_ci} __attribute__((__packed__)); 2822498b56bSopenharmony_ci#endif /* HILOG_CMD_H */