From 71f6c4a730588bb34b63510d0de27c5c90050f6a Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 22 Jun 2021 13:16:18 +0800 Subject: [PATCH 01/20] Description: Enable exclusion for type, level, domain and tag Team: OTHERS Feature or Bugfix: Feature Binary Source: No PrivateCode(Yes/No): No Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 10 ++++ services/hilogd/include/log_reader.h | 6 ++ services/hilogd/log_buffer.cpp | 16 ++++++ services/hilogd/log_querier.cpp | 14 ++++- services/hilogtool/log_controller.cpp | 13 +++++ services/hilogtool/main.cpp | 69 +++++++++++++++++++---- 6 files changed, 115 insertions(+), 13 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index cd4b03c..0f518d1 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -107,6 +107,11 @@ typedef struct { uint32_t timeBegin; uint32_t timeEnd; uint16_t logCount; + uint8_t exclude; + uint8_t noLevels; + uint16_t noTypes; + uint32_t noDomain; + char noTag[MAX_TAG_LEN]; } LogQueryRequest; typedef struct { @@ -325,6 +330,11 @@ typedef struct { time_t endTime; std::string domain; std::string tag; + uint8_t exclude; + uint16_t noTypes; + uint16_t noLevels; + std::string noDomain; + std::string noTag; std::string regexArgs; std::string buffSizeArgs; std::string logFileCtrlArgs; diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index aed5feb..0a33f4a 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -38,6 +38,11 @@ using QueryCondition = struct QueryCondition { uint32_t domain = 0; uint32_t timeBegin = 0; uint32_t timeEnd = 0; + uint8_t exclude = 0; + uint8_t noLevels = 0; + uint16_t noTypes = 0; + uint32_t noDomain = 0; + std::string noTag; }; class LogReader : public std::enable_shared_from_this { @@ -46,6 +51,7 @@ public: std::list::iterator lastPos; std::list oldData; QueryCondition queryCondition; + bool exclude = false; std::unique_ptr hilogtoolConnectSocket; bool isNotified; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 70c694f..9f2bad0 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -338,6 +338,14 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) const int DOMAIN_STRICT_MASK = 0xd000000; const int DOMAIN_FUZZY_MASK = 0xdffff; const int DOMAIN_MODULE_BITS = 8; + + // domain exclusion + if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.noDomain != 0) && + ((reader->queryCondition.noDomain >= 0xd000000 && reader->queryCondition.noDomain == reader->readPos->domain) || + (reader->queryCondition.noDomain <= 0xdffff && reader->queryCondition.noDomain == (reader->readPos->domain >> 8))) + ) { + return false; + } if ((reader->queryCondition.domain != 0) && ((reader->queryCondition.domain >= DOMAIN_STRICT_MASK && reader->queryCondition.domain != reader->readPos->domain) || @@ -352,6 +360,14 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) ((reader->readPos->tv_sec >= reader->queryCondition.timeBegin) && (reader->readPos->tv_sec <= reader->queryCondition.timeEnd))) { // type and level condition + // exclusion check first + if ((reader->queryCondition.exclude == 1) && + ((static_cast(0b01 << (reader->readPos->type) & reader->queryCondition.noTypes) != 0) || + (static_cast(0b01 << (reader->readPos->level) & reader->queryCondition.noLevels) != 0) || + reader->readPos->tag == reader->queryCondition.noTag) + ) { + return false; + } if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) != 0) && (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) != 0)) { return true; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 8ef90ac..67fe30f 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -94,9 +94,10 @@ LogPersisterRotator* MakeRotator(LogPersistStartMsg& pLogPersistStartMsg) }; } -void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer* buffer) +void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer* buffer, bool exclude = false) { logReader->SetCmd(LOG_QUERY_RESPONSE); + logReader->exclude = exclude; buffer->AddLogReader(logReader); buffer->Query(logReader); } @@ -406,7 +407,16 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) logReader->queryCondition.domain = qRstMsg->domain; logReader->queryCondition.timeBegin = qRstMsg->timeBegin; logReader->queryCondition.timeEnd = qRstMsg->timeEnd; - HandleLogQueryRequest(logReader, hilogBuffer); + if (qRstMsg->exclude == 1) { + logReader->queryCondition.exclude = 1; + logReader->queryCondition.noLevels = qRstMsg->noLevels; + logReader->queryCondition.noTypes = qRstMsg->noTypes; + logReader->queryCondition.noDomain = qRstMsg->noDomain; + logReader->queryCondition.noTag = qRstMsg->noTag; + } else { + logReader->queryCondition.exclude = 0; + } + HandleLogQueryRequest(logReader, hilogBuffer, logReader->queryCondition.exclude); break; case NEXT_REQUEST: nRstMsg = (NextRequest*) g_tempBuffer; diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 84ddbfc..088b62d 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -161,6 +161,19 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte } logQueryRequest.timeBegin = context->beginTime; logQueryRequest.timeEnd = context->endTime; + if (context->exclude == 1) { + logQueryRequest.noLevels = context->noLevels; + logQueryRequest.noTypes = context->noTypes; + std::istringstream(context->noDomain) >> std::hex >> logQueryRequest.noDomain; + if (context->noTag.length() >= MAX_TAG_LEN) { + strncpy_s(logQueryRequest.noTag, MAX_TAG_LEN, context->noTag.c_str(), MAX_TAG_LEN - 1); + } else { + strncpy_s(logQueryRequest.noTag, context->noTag.length() + 1, context->noTag.c_str(), context->noTag.length()); + } + logQueryRequest.exclude = 1; + } else { + logQueryRequest.exclude = 0; + } SetMsgHead(&logQueryRequest.header, LOG_QUERY_REQUEST, sizeof(LogQueryRequest)-sizeof(MessageHeader)); logQueryRequest.header.version = 0; controller.WriteAll((char*)&logQueryRequest, sizeof(LogQueryRequest)); diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 36b54c5..5d99774 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -24,7 +24,7 @@ #include #include #include - +#include #include "hilog/log.h" #include "hilog_common.h" #include "hilogtool_msg.h" @@ -121,9 +121,14 @@ static std::time_t Str2Time(const std::string& str, bool isDst = false, return mktime(&t); } } -static int GetTypes(HilogArgs context, string typesArgs) +static int GetTypes(HilogArgs context, string typesArgs, bool exclude = false) { - uint16_t types = context.types; + uint16_t types = 0; + if (exclude) { + types = context.noTypes; + } else { + types = context.types; + } if (typesArgs == "init") { types |= 1< v(std::sregex_token_iterator(types.begin()+1, types.end(), ws_re, -1), + std::sregex_token_iterator()); + for(auto&& s: v){ + context.noTypes = GetTypes(context, s, true); + } + } else { + typesArgs += types; + context.types = GetTypes(context, types); + } } else { break; } @@ -255,8 +275,18 @@ int HilogEntry(int argc, char* argv[]) string levels(argv[indexLevel]); indexLevel++; if (!strstr(levels.c_str(), "-")) { - levelsArgs += levels; - context.levels = GetLevels(context, levels); + if (levels.front() == '^') { + context.exclude = 1; + std::regex ws_re(","); // whitespace + std::vector v(std::sregex_token_iterator(levels.begin()+1, levels.end(), ws_re, -1), + std::sregex_token_iterator()); + for(auto&& s: v){ + context.noLevels = GetLevels(context, s, true); + } + } else { + levelsArgs += levels; + context.levels = GetLevels(context, levels); + } } else { break; } @@ -330,7 +360,18 @@ int HilogEntry(int argc, char* argv[]) noLogOption = true; break; case 'D': - context.domainArgs = optarg; + if (optarg[0] == '^') { + std::string domain(optarg); + context.exclude = 1; + std::regex ws_re(","); // whitespace + std::vector v(std::sregex_token_iterator(domain.begin()+1, domain.end(), ws_re, -1), + std::sregex_token_iterator()); + for(auto&& s: v){ + context.noDomain = s; + } + } else { + context.domainArgs = optarg; + } break; case 's': context.statisticArgs = "query"; @@ -341,7 +382,13 @@ int HilogEntry(int argc, char* argv[]) noLogOption = true; break; case 'T': - context.tagArgs = optarg; + if (optarg[0] == '^') { + context.exclude = 1; + context.tagArgs = ""; + context.noTag = &optarg[1]; + } else { + context.tagArgs = optarg; + } break; case 'b': context.logLevelArgs = optarg; -- Gitee From d8006224ef3166b933e3f9595af2fa53d80ed02e Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 22 Jun 2021 14:21:21 +0800 Subject: [PATCH 02/20] Description: Code format Team: OTHERS Feature or Bugfix: Bugfix PrivateCode(Yes/No): No Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogd/log_buffer.cpp | 8 ++++---- services/hilogd/log_querier.cpp | 15 +++++++++----- services/hilogtool/log_controller.cpp | 6 ++++-- services/hilogtool/main.cpp | 28 +++++++++++++-------------- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 9f2bad0..6bf7e08 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -341,8 +341,8 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) // domain exclusion if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.noDomain != 0) && - ((reader->queryCondition.noDomain >= 0xd000000 && reader->queryCondition.noDomain == reader->readPos->domain) || - (reader->queryCondition.noDomain <= 0xdffff && reader->queryCondition.noDomain == (reader->readPos->domain >> 8))) + ((reader->queryCondition.noDomain >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomain == reader->readPos->domain) || + (reader->queryCondition.noDomain <= DOMAIN_FUZZY_MASK && reader->queryCondition.noDomain == (reader->readPos->domain >> DOMAIN_MODULE_BITS))) ) { return false; } @@ -362,8 +362,8 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) // type and level condition // exclusion check first if ((reader->queryCondition.exclude == 1) && - ((static_cast(0b01 << (reader->readPos->type) & reader->queryCondition.noTypes) != 0) || - (static_cast(0b01 << (reader->readPos->level) & reader->queryCondition.noLevels) != 0) || + ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || + (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0) || reader->readPos->tag == reader->queryCondition.noTag) ) { return false; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 67fe30f..14e0313 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -390,6 +390,15 @@ void HandleBufferClearRequest(char* reqMsg, std::shared_ptr logReader logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); } +void setExclusion(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) +{ + logReader->queryCondition.exclude = 1; + logReader->queryCondition.noLevels = qRstMsg->noLevels; + logReader->queryCondition.noTypes = qRstMsg->noTypes; + logReader->queryCondition.noDomain = qRstMsg->noDomain; + logReader->queryCondition.noTag = qRstMsg->noTag; +} + void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) { cout << "Start log_querier thread!\n" << std::endl; @@ -408,11 +417,7 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) logReader->queryCondition.timeBegin = qRstMsg->timeBegin; logReader->queryCondition.timeEnd = qRstMsg->timeEnd; if (qRstMsg->exclude == 1) { - logReader->queryCondition.exclude = 1; - logReader->queryCondition.noLevels = qRstMsg->noLevels; - logReader->queryCondition.noTypes = qRstMsg->noTypes; - logReader->queryCondition.noDomain = qRstMsg->noDomain; - logReader->queryCondition.noTag = qRstMsg->noTag; + setExclusion(logReader, qRstMsg); } else { logReader->queryCondition.exclude = 0; } diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 088b62d..149e15f 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -166,9 +166,11 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte logQueryRequest.noTypes = context->noTypes; std::istringstream(context->noDomain) >> std::hex >> logQueryRequest.noDomain; if (context->noTag.length() >= MAX_TAG_LEN) { - strncpy_s(logQueryRequest.noTag, MAX_TAG_LEN, context->noTag.c_str(), MAX_TAG_LEN - 1); + strncpy_s(logQueryRequest.noTag, MAX_TAG_LEN, + context->noTag.c_str(), MAX_TAG_LEN - 1); } else { - strncpy_s(logQueryRequest.noTag, context->noTag.length() + 1, context->noTag.c_str(), context->noTag.length()); + strncpy_s(logQueryRequest.noTag, context->noTag.length() + 1, + context->noTag.c_str(), context->noTag.length()); } logQueryRequest.exclude = 1; } else { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 5d99774..59c0e0f 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -22,9 +22,9 @@ #include #include #include +#include #include #include -#include #include "hilog/log.h" #include "hilog_common.h" #include "hilogtool_msg.h" @@ -254,10 +254,10 @@ int HilogEntry(int argc, char* argv[]) if (!strstr(types.c_str(), "-")) { if (types.front() == '^') { context.exclude = 1; - std::regex ws_re(","); // whitespace - std::vector v(std::sregex_token_iterator(types.begin()+1, types.end(), ws_re, -1), - std::sregex_token_iterator()); - for(auto&& s: v){ + regex delimiter(","); // whitespace + vector v(sregex_token_iterator(types.begin() + 1, types.end(), delimiter, -1), + sregex_token_iterator()); + for (auto&& s : v) { context.noTypes = GetTypes(context, s, true); } } else { @@ -277,10 +277,10 @@ int HilogEntry(int argc, char* argv[]) if (!strstr(levels.c_str(), "-")) { if (levels.front() == '^') { context.exclude = 1; - std::regex ws_re(","); // whitespace - std::vector v(std::sregex_token_iterator(levels.begin()+1, levels.end(), ws_re, -1), - std::sregex_token_iterator()); - for(auto&& s: v){ + regex delimiter(","); // whitespace + vector v(sregex_token_iterator(levels.begin() + 1, levels.end(), delimiter, -1), + sregex_token_iterator()); + for (auto&& s : v) { context.noLevels = GetLevels(context, s, true); } } else { @@ -361,12 +361,12 @@ int HilogEntry(int argc, char* argv[]) break; case 'D': if (optarg[0] == '^') { - std::string domain(optarg); + string domain(optarg); context.exclude = 1; - std::regex ws_re(","); // whitespace - std::vector v(std::sregex_token_iterator(domain.begin()+1, domain.end(), ws_re, -1), - std::sregex_token_iterator()); - for(auto&& s: v){ + regex delimiter(","); // whitespace + vector v(sregex_token_iterator(domain.begin() + 1, domain.end(), delimiter, -1), + sregex_token_iterator()); + for (auto&& s : v) { context.noDomain = s; } } else { -- Gitee From a9e405c8c8645f49541eb88467a3c26166fb5daf Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 22 Jun 2021 14:54:46 +0800 Subject: [PATCH 03/20] LogReader: Shorten LogThreadFunc Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogd/log_querier.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 14e0313..b5d87d9 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -390,7 +390,16 @@ void HandleBufferClearRequest(char* reqMsg, std::shared_ptr logReader logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); } -void setExclusion(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) +inline void SetCondition(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) +{ + logReader->queryCondition.levels = qRstMsg->levels; + logReader->queryCondition.types = qRstMsg->types; + logReader->queryCondition.domain = qRstMsg->domain; + logReader->queryCondition.timeBegin = qRstMsg->timeBegin; + logReader->queryCondition.timeEnd = qRstMsg->timeEnd; +} + +inline void SetExclusion(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) { logReader->queryCondition.exclude = 1; logReader->queryCondition.noLevels = qRstMsg->noLevels; @@ -411,13 +420,9 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) switch (header->msgType) { case LOG_QUERY_REQUEST: qRstMsg = (LogQueryRequest*) g_tempBuffer; - logReader->queryCondition.levels = qRstMsg->levels; - logReader->queryCondition.types = qRstMsg->types; - logReader->queryCondition.domain = qRstMsg->domain; - logReader->queryCondition.timeBegin = qRstMsg->timeBegin; - logReader->queryCondition.timeEnd = qRstMsg->timeEnd; + SetCondition(logReader, qRstMsg); if (qRstMsg->exclude == 1) { - setExclusion(logReader, qRstMsg); + SetExclusion(logReader, qRstMsg); } else { logReader->queryCondition.exclude = 0; } -- Gitee From 9a89b9a72d78d318c7440d238dde39a3906e3518 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Fri, 25 Jun 2021 14:04:58 +0800 Subject: [PATCH 04/20] Support multiple domain query Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilog_common.h | 2 ++ frameworks/native/include/hilogtool_msg.h | 8 +++-- services/hilogd/include/log_reader.h | 4 ++- services/hilogd/log_buffer.cpp | 19 ++++++----- services/hilogd/log_querier.cpp | 5 ++- services/hilogtool/log_controller.cpp | 11 ++++--- services/hilogtool/main.cpp | 39 ++++++++++++++++------- 7 files changed, 60 insertions(+), 28 deletions(-) diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index 1567e86..e9371c8 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -30,6 +30,8 @@ #define MULARGS 5 #define MAX_LOG_LEN 1024 /* maximum length of a log, include '\0' */ #define MAX_TAG_LEN 32 /* log tag size, include '\0' */ +#define MAX_DOMAINS 5 +#define MAX_TAGS 10 #define RET_SUCCESS 0 #define RET_FAIL (-1) #define IS_ONE(number, n) ((number>>n)&0x01) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index 0f518d1..b8b4409 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -101,9 +101,11 @@ typedef struct { typedef struct { MessageHeader header; + uint8_t nDomain : 4; + uint8_t nTag : 4; uint8_t levels; uint16_t types; - uint32_t domain; + uint32_t domains[MAX_DOMAINS]; uint32_t timeBegin; uint32_t timeEnd; uint16_t logCount; @@ -322,6 +324,8 @@ typedef struct { typedef struct { uint16_t noBlockMode; + uint8_t nDomain : 4; + uint8_t nTag : 4; uint16_t types; uint16_t levels; uint16_t headLines; @@ -357,4 +361,4 @@ typedef struct { std::string algorithmArgs; } HilogArgs; -#endif /* HILOGTOOL_MSG_H */ \ No newline at end of file +#endif /* HILOGTOOL_MSG_H */ diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index 0a33f4a..bb1b072 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -33,9 +33,11 @@ class HilogBuffer; #define TYPE_PERSISTER 2 using QueryCondition = struct QueryCondition { + uint8_t nDomain : 4; + uint8_t nTag : 4; uint16_t levels = 0; uint16_t types = 0; - uint32_t domain = 0; + uint32_t domains[MAX_DOMAINS]; uint32_t timeBegin = 0; uint32_t timeEnd = 0; uint8_t exclude = 0; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 6bf7e08..0efa26b 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -340,20 +340,23 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) const int DOMAIN_MODULE_BITS = 8; // domain exclusion + int ret = 0; if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.noDomain != 0) && ((reader->queryCondition.noDomain >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomain == reader->readPos->domain) || (reader->queryCondition.noDomain <= DOMAIN_FUZZY_MASK && reader->queryCondition.noDomain == (reader->readPos->domain >> DOMAIN_MODULE_BITS))) ) { return false; } - if ((reader->queryCondition.domain != 0) && - ((reader->queryCondition.domain >= DOMAIN_STRICT_MASK && - reader->queryCondition.domain != reader->readPos->domain) || - (reader->queryCondition.domain <= DOMAIN_FUZZY_MASK && - reader->queryCondition.domain != (reader->readPos->domain >> DOMAIN_MODULE_BITS))) - ) { - return false; - } + if (reader->queryCondition.nDomain > 0) { + for (int i = 0; i < reader->queryCondition.nDomain; i++) { + if (!((reader->queryCondition.domains[i] >= 0xd000000 && reader->queryCondition.domains[i] != reader->readPos->domain) || + (reader->queryCondition.domains[i] <= 0xdffff && reader->queryCondition.domains[i] != (reader->readPos->domain >> 8)))) { + ret = 1; + break; + } + } + if (ret == 0) return false; + ret = 0; // time condition if ((reader->queryCondition.timeBegin == 0 && reader->queryCondition.timeEnd == 0) || diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index b5d87d9..1e0abd9 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -394,7 +394,10 @@ inline void SetCondition(std::shared_ptr logReader, const LogQueryReq { logReader->queryCondition.levels = qRstMsg->levels; logReader->queryCondition.types = qRstMsg->types; - logReader->queryCondition.domain = qRstMsg->domain; + logReader->queryCondition.nDomain = qRstMsg->nDomain; + for (int i = 0; i < qRstMsg->nDomain; i++) { + logReader->queryCondition.domains[i] = qRstMsg->domains[i]; + } logReader->queryCondition.timeBegin = qRstMsg->timeBegin; logReader->queryCondition.timeEnd = qRstMsg->timeEnd; } diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 149e15f..e348222 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -152,11 +152,14 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte memset_s(&logQueryRequest, sizeof(LogQueryRequest), 0, sizeof(LogQueryRequest)); logQueryRequest.levels = context->levels; logQueryRequest.types = context->types; + logQueryRequest.nDomain = context->nDomain; if (context->domainArgs != "") { - std::istringstream(context->domainArgs) >> std::hex >> logQueryRequest.domain; - if (logQueryRequest.domain == 0) { - std::cout << "Invalid parameter" << std::endl; - return; + vector vecLogDomain; + Split(context->domainArgs, " ", vecLogDomain); + int nDomain = 0; + for (auto s : vecLogDomain) { + if (s == " ") continue; + std::istringstream(s) >> std::hex >> logQueryRequest.domains[nDomain++]; } } logQueryRequest.timeBegin = context->beginTime; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 59c0e0f..757d766 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -177,6 +177,8 @@ int HilogEntry(int argc, char* argv[]) int optIndex = 0; int indexLevel = 0; int indexType = 0; + int indexDomain = 0; + int indexTag = 0; bool noLogOption = false; context.noBlockMode = 0; @@ -360,19 +362,30 @@ int HilogEntry(int argc, char* argv[]) noLogOption = true; break; case 'D': - if (optarg[0] == '^') { - string domain(optarg); - context.exclude = 1; - regex delimiter(","); // whitespace - vector v(sregex_token_iterator(domain.begin() + 1, domain.end(), delimiter, -1), - sregex_token_iterator()); - for (auto&& s : v) { - context.noDomain = s; + indexDomain = optind - 1; + while (indexDomain < argc) { + if(context.nDomain++ >= MAX_DOMAINS) { + break; } - } else { - context.domainArgs = optarg; - } - break; + std::string domains(argv[indexDomain]); + indexDomain++; + if (!strstr(domains.c_str(), "-")) { + if (domains.front() == '^') { + context.exclude = 1; + std::regex delimiter(","); // whitespace + std::vector v(std::sregex_token_iterator(domains.begin()+1, domains.end(), delimiter, -1), + std::sregex_token_iterator()); + for(auto&& s: v){ + context.noDomain = s; + } + } else { + context.domainArgs += (domains + " "); + } + } else { + break; + } + } + break; case 's': context.statisticArgs = "query"; noLogOption = true; @@ -508,6 +521,8 @@ int HilogEntry(int argc, char* argv[]) } } else { LogQueryRequestOp(controller, &context); + context.nDomain = 0; + context.nTag = 0; } memset_s(recvBuffer, sizeof(recvBuffer), 0, sizeof(recvBuffer)); -- Gitee From 2668b78d2245c4b6db3db16df1f6a1570449d678 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Fri, 25 Jun 2021 14:14:45 +0800 Subject: [PATCH 05/20] Support multiple domains exclusion Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 16 ++++++++++------ services/hilogd/include/log_reader.h | 8 +++++--- services/hilogd/log_buffer.cpp | 12 +++++++----- services/hilogd/log_querier.cpp | 5 ++++- services/hilogtool/log_controller.cpp | 5 ++++- services/hilogtool/main.cpp | 4 +++- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index b8b4409..228ed22 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -101,18 +101,20 @@ typedef struct { typedef struct { MessageHeader header; - uint8_t nDomain : 4; + uint8_t exclude : 2; + uint8_t nDomain : 3; + uint8_t nNoDomain: 3; uint8_t nTag : 4; + uint8_t nNoTag: 4; uint8_t levels; uint16_t types; uint32_t domains[MAX_DOMAINS]; uint32_t timeBegin; uint32_t timeEnd; uint16_t logCount; - uint8_t exclude; uint8_t noLevels; uint16_t noTypes; - uint32_t noDomain; + uint32_t noDomains[MAX_DOMAINS]; char noTag[MAX_TAG_LEN]; } LogQueryRequest; @@ -324,8 +326,11 @@ typedef struct { typedef struct { uint16_t noBlockMode; - uint8_t nDomain : 4; + uint8_t exclude : 2; + uint8_t nDomain : 3; + uint8_t nNoDomain: 3; uint8_t nTag : 4; + uint8_t nNoTag: 4; uint16_t types; uint16_t levels; uint16_t headLines; @@ -334,10 +339,9 @@ typedef struct { time_t endTime; std::string domain; std::string tag; - uint8_t exclude; uint16_t noTypes; uint16_t noLevels; - std::string noDomain; + std::string noDomains[MAX_DOMAINS]; std::string noTag; std::string regexArgs; std::string buffSizeArgs; diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index bb1b072..d5d9dea 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -33,17 +33,19 @@ class HilogBuffer; #define TYPE_PERSISTER 2 using QueryCondition = struct QueryCondition { - uint8_t nDomain : 4; + uint8_t exclude : 2; + uint8_t nDomain : 3; + uint8_t nNoDomain: 3; uint8_t nTag : 4; + uint8_t nNoTag: 4; uint16_t levels = 0; uint16_t types = 0; uint32_t domains[MAX_DOMAINS]; uint32_t timeBegin = 0; uint32_t timeEnd = 0; - uint8_t exclude = 0; uint8_t noLevels = 0; uint16_t noTypes = 0; - uint32_t noDomain = 0; + uint32_t noDomains[MAX_DOMAINS]; std::string noTag; }; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 0efa26b..61fab3d 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -341,11 +341,13 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) // domain exclusion int ret = 0; - if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.noDomain != 0) && - ((reader->queryCondition.noDomain >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomain == reader->readPos->domain) || - (reader->queryCondition.noDomain <= DOMAIN_FUZZY_MASK && reader->queryCondition.noDomain == (reader->readPos->domain >> DOMAIN_MODULE_BITS))) - ) { - return false; + if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.nNoDomain != 0)) { + for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { + if (((reader->queryCondition.noDomains[i] >= 0xd000000 && reader->queryCondition.noDomains[i] == reader->readPos->domain) || + (reader->queryCondition.noDomains[i] <= 0xdffff && reader->queryCondition.noDomains[i] == (reader->readPos->domain >> 8)))) { + return false; + } + } } if (reader->queryCondition.nDomain > 0) { for (int i = 0; i < reader->queryCondition.nDomain; i++) { diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 1e0abd9..4c09405 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -407,7 +407,10 @@ inline void SetExclusion(std::shared_ptr logReader, const LogQueryReq logReader->queryCondition.exclude = 1; logReader->queryCondition.noLevels = qRstMsg->noLevels; logReader->queryCondition.noTypes = qRstMsg->noTypes; - logReader->queryCondition.noDomain = qRstMsg->noDomain; + logReader->queryCondition.nNoDomain = qRstMsg->nNoDomain; + for (int i = 0; i < qRstMsg->nNoDomain; i++) { + logReader->queryCondition.noDomains[i] = qRstMsg->noDomains[i]; + } logReader->queryCondition.noTag = qRstMsg->noTag; } diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index e348222..73b6d90 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -167,7 +167,10 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte if (context->exclude == 1) { logQueryRequest.noLevels = context->noLevels; logQueryRequest.noTypes = context->noTypes; - std::istringstream(context->noDomain) >> std::hex >> logQueryRequest.noDomain; + logQueryRequest.nNoDomain = context->nNoDomain; + for (int i = 0 ; i < context->nNoDomain; i++) { + std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; + } if (context->noTag.length() >= MAX_TAG_LEN) { strncpy_s(logQueryRequest.noTag, MAX_TAG_LEN, context->noTag.c_str(), MAX_TAG_LEN - 1); diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 757d766..5f2b9be 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -376,7 +376,7 @@ int HilogEntry(int argc, char* argv[]) std::vector v(std::sregex_token_iterator(domains.begin()+1, domains.end(), delimiter, -1), std::sregex_token_iterator()); for(auto&& s: v){ - context.noDomain = s; + context.noDomains[context.nNoDomain++] = s; } } else { context.domainArgs += (domains + " "); @@ -522,7 +522,9 @@ int HilogEntry(int argc, char* argv[]) } else { LogQueryRequestOp(controller, &context); context.nDomain = 0; + context.nNoDomain = 0; context.nTag = 0; + context.nNoTag = 0; } memset_s(recvBuffer, sizeof(recvBuffer), 0, sizeof(recvBuffer)); -- Gitee From 69bbe6fc834f8361ba1f0477f24ab2ac47ca4be2 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Fri, 25 Jun 2021 14:23:57 +0800 Subject: [PATCH 06/20] Support multiple tag exclusion; Bugfix Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 4 +-- services/hilogd/include/log_reader.h | 2 +- services/hilogd/log_buffer.cpp | 10 +++++-- services/hilogd/log_querier.cpp | 5 +++- services/hilogtool/log_controller.cpp | 14 +++++----- services/hilogtool/main.cpp | 32 ++++++++++++++++++----- 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index 228ed22..1acc8d8 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -115,7 +115,7 @@ typedef struct { uint8_t noLevels; uint16_t noTypes; uint32_t noDomains[MAX_DOMAINS]; - char noTag[MAX_TAG_LEN]; + char noTags[MAX_TAGS][MAX_TAG_LEN]; } LogQueryRequest; typedef struct { @@ -342,7 +342,7 @@ typedef struct { uint16_t noTypes; uint16_t noLevels; std::string noDomains[MAX_DOMAINS]; - std::string noTag; + std::string noTags[MAX_TAGS]; std::string regexArgs; std::string buffSizeArgs; std::string logFileCtrlArgs; diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index d5d9dea..d84e38d 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -46,7 +46,7 @@ using QueryCondition = struct QueryCondition { uint8_t noLevels = 0; uint16_t noTypes = 0; uint32_t noDomains[MAX_DOMAINS]; - std::string noTag; + std::string noTags[MAX_TAGS]; }; class LogReader : public std::enable_shared_from_this { diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 61fab3d..d30fea1 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -368,11 +368,17 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) // exclusion check first if ((reader->queryCondition.exclude == 1) && ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || - (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0) || - reader->readPos->tag == reader->queryCondition.noTag) + (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0)) ) { return false; } + + if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.nNoTag > 0)) { + for (int i = 0; i < reader->queryCondition.nNoTag; i++) { + if (reader->readPos->tag == reader->queryCondition.noTags[i]) return false; + } + } + if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) != 0) && (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) != 0)) { return true; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 4c09405..a3ab702 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -408,10 +408,13 @@ inline void SetExclusion(std::shared_ptr logReader, const LogQueryReq logReader->queryCondition.noLevels = qRstMsg->noLevels; logReader->queryCondition.noTypes = qRstMsg->noTypes; logReader->queryCondition.nNoDomain = qRstMsg->nNoDomain; + logReader->queryCondition.nNoTag = qRstMsg->nNoTag; for (int i = 0; i < qRstMsg->nNoDomain; i++) { logReader->queryCondition.noDomains[i] = qRstMsg->noDomains[i]; } - logReader->queryCondition.noTag = qRstMsg->noTag; + for (int i = 0; i < qRstMsg->nNoTag; i++) { + logReader->queryCondition.noTags[i] = qRstMsg->noTags[i]; + } } void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 73b6d90..abfe495 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -171,12 +171,14 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte for (int i = 0 ; i < context->nNoDomain; i++) { std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; } - if (context->noTag.length() >= MAX_TAG_LEN) { - strncpy_s(logQueryRequest.noTag, MAX_TAG_LEN, - context->noTag.c_str(), MAX_TAG_LEN - 1); - } else { - strncpy_s(logQueryRequest.noTag, context->noTag.length() + 1, - context->noTag.c_str(), context->noTag.length()); + for (int i = 0; i < context->nNoTag; i++) { + if (context->noTags[i].length() >= MAX_TAG_LEN) { + strncpy_s(logQueryRequest.noTags[i], MAX_TAG_LEN, + context->noTags[i].c_str(), MAX_TAG_LEN - 1); + } else { + strncpy_s(logQueryRequest.noTags[i], context->noTags[i].length() + 1, + context->noTags[i].c_str(), context->noTags[i].length()); + } } logQueryRequest.exclude = 1; } else { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 5f2b9be..3f40bc8 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -364,7 +364,7 @@ int HilogEntry(int argc, char* argv[]) case 'D': indexDomain = optind - 1; while (indexDomain < argc) { - if(context.nDomain++ >= MAX_DOMAINS) { + if(context.nDomain >= MAX_DOMAINS) { break; } std::string domains(argv[indexDomain]); @@ -380,6 +380,7 @@ int HilogEntry(int argc, char* argv[]) } } else { context.domainArgs += (domains + " "); + context.nDomain++; } } else { break; @@ -395,12 +396,29 @@ int HilogEntry(int argc, char* argv[]) noLogOption = true; break; case 'T': - if (optarg[0] == '^') { - context.exclude = 1; - context.tagArgs = ""; - context.noTag = &optarg[1]; - } else { - context.tagArgs = optarg; + indexTag = optind - 1; + while (indexTag < argc) { + if(context.nTag >= MAX_DOMAINS) { + break; + } + std::string tags(argv[indexTag]); + indexTag++; + if (!strstr(tags.c_str(), "-")) { + if (tags.front() == '^') { + context.exclude = 1; + std::regex delimiter(","); // whitespace + std::vector v(std::sregex_token_iterator(tags.begin()+1, tags.end(), delimiter, -1), + std::sregex_token_iterator()); + for(auto&& s: v){ + context.noTags[context.nNoTag++] = s; + } + } else { + context.tagArgs += (tags + " "); + context.nTag++; + } + } else { + break; + } } break; case 'b': -- Gitee From ed97ff8b12e2da84ce835f602e6fd0ab0f1d8999 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Fri, 25 Jun 2021 14:34:18 +0800 Subject: [PATCH 07/20] Bugfix and code format Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogd/log_buffer.cpp | 12 +++++++----- services/hilogtool/main.cpp | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index d30fea1..ba824cd 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -343,23 +343,25 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) int ret = 0; if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.nNoDomain != 0)) { for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { - if (((reader->queryCondition.noDomains[i] >= 0xd000000 && reader->queryCondition.noDomains[i] == reader->readPos->domain) || - (reader->queryCondition.noDomains[i] <= 0xdffff && reader->queryCondition.noDomains[i] == (reader->readPos->domain >> 8)))) { + if (((reader->queryCondition.noDomains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomains[i] == reader->readPos->domain) || + (reader->queryCondition.noDomains[i] <= DOMAIN_FUZZY_MASK && + reader->queryCondition.noDomains[i] == (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) { return false; } } } if (reader->queryCondition.nDomain > 0) { for (int i = 0; i < reader->queryCondition.nDomain; i++) { - if (!((reader->queryCondition.domains[i] >= 0xd000000 && reader->queryCondition.domains[i] != reader->readPos->domain) || - (reader->queryCondition.domains[i] <= 0xdffff && reader->queryCondition.domains[i] != (reader->readPos->domain >> 8)))) { + if (!((reader->queryCondition.domains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.domains[i] != reader->readPos->domain) || + (reader->queryCondition.domains[i] <= DOMAIN_FUZZY_MASK && + reader->queryCondition.domains[i] != (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) { ret = 1; break; } } if (ret == 0) return false; ret = 0; - + } // time condition if ((reader->queryCondition.timeBegin == 0 && reader->queryCondition.timeEnd == 0) || ((reader->readPos->tv_sec >= reader->queryCondition.timeBegin) && diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 3f40bc8..8cf2481 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -364,7 +364,7 @@ int HilogEntry(int argc, char* argv[]) case 'D': indexDomain = optind - 1; while (indexDomain < argc) { - if(context.nDomain >= MAX_DOMAINS) { + if((context.nDomain >= MAX_DOMAINS) || (context.nNoDomain >= MAX_DOMAINS)) { break; } std::string domains(argv[indexDomain]); @@ -398,7 +398,7 @@ int HilogEntry(int argc, char* argv[]) case 'T': indexTag = optind - 1; while (indexTag < argc) { - if(context.nTag >= MAX_DOMAINS) { + if((context.nTag >= MAX_TAGS) || (context.nNoTag >= MAX_TAGS)) { break; } std::string tags(argv[indexTag]); -- Gitee From e7e4592f6535b4f0a771d13992ac8736597cf89e Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Fri, 25 Jun 2021 16:34:11 +0800 Subject: [PATCH 08/20] Code format fix Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 4 ++-- services/hilogd/include/log_reader.h | 4 ++-- services/hilogtool/log_controller.cpp | 2 +- services/hilogtool/main.cpp | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index 1acc8d8..47817cc 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -103,9 +103,9 @@ typedef struct { MessageHeader header; uint8_t exclude : 2; uint8_t nDomain : 3; - uint8_t nNoDomain: 3; + uint8_t nNoDomain : 3; uint8_t nTag : 4; - uint8_t nNoTag: 4; + uint8_t nNoTag : 4; uint8_t levels; uint16_t types; uint32_t domains[MAX_DOMAINS]; diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index d84e38d..bd3cc65 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -35,9 +35,9 @@ class HilogBuffer; using QueryCondition = struct QueryCondition { uint8_t exclude : 2; uint8_t nDomain : 3; - uint8_t nNoDomain: 3; + uint8_t nNoDomain : 3; uint8_t nTag : 4; - uint8_t nNoTag: 4; + uint8_t nNoTag : 4; uint16_t levels = 0; uint16_t types = 0; uint32_t domains[MAX_DOMAINS]; diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index abfe495..8249aae 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -168,7 +168,7 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte logQueryRequest.noLevels = context->noLevels; logQueryRequest.noTypes = context->noTypes; logQueryRequest.nNoDomain = context->nNoDomain; - for (int i = 0 ; i < context->nNoDomain; i++) { + for (int i = 0; i < context->nNoDomain; i++) { std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; } for (int i = 0; i < context->nNoTag; i++) { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 8cf2481..be95e28 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -364,7 +364,7 @@ int HilogEntry(int argc, char* argv[]) case 'D': indexDomain = optind - 1; while (indexDomain < argc) { - if((context.nDomain >= MAX_DOMAINS) || (context.nNoDomain >= MAX_DOMAINS)) { + if ((context.nDomain >= MAX_DOMAINS) || (context.nNoDomain >= MAX_DOMAINS)) { break; } std::string domains(argv[indexDomain]); @@ -373,9 +373,9 @@ int HilogEntry(int argc, char* argv[]) if (domains.front() == '^') { context.exclude = 1; std::regex delimiter(","); // whitespace - std::vector v(std::sregex_token_iterator(domains.begin()+1, domains.end(), delimiter, -1), + std::vector v(std::sregex_token_iterator(domains.begin() + 1, domains.end(), delimiter, -1), std::sregex_token_iterator()); - for(auto&& s: v){ + for (auto&& s: v) { context.noDomains[context.nNoDomain++] = s; } } else { @@ -385,8 +385,8 @@ int HilogEntry(int argc, char* argv[]) } else { break; } - } - break; + } + break; case 's': context.statisticArgs = "query"; noLogOption = true; @@ -398,7 +398,7 @@ int HilogEntry(int argc, char* argv[]) case 'T': indexTag = optind - 1; while (indexTag < argc) { - if((context.nTag >= MAX_TAGS) || (context.nNoTag >= MAX_TAGS)) { + if ((context.nTag >= MAX_TAGS) || (context.nNoTag >= MAX_TAGS)) { break; } std::string tags(argv[indexTag]); @@ -407,9 +407,9 @@ int HilogEntry(int argc, char* argv[]) if (tags.front() == '^') { context.exclude = 1; std::regex delimiter(","); // whitespace - std::vector v(std::sregex_token_iterator(tags.begin()+1, tags.end(), delimiter, -1), + std::vector v(std::sregex_token_iterator(tags.begin() + 1, tags.end(), delimiter, -1), std::sregex_token_iterator()); - for(auto&& s: v){ + for (auto&& s: v) { context.noTags[context.nNoTag++] = s; } } else { -- Gitee From 39d454b967e81461f0d3090529de3ea11fae0e8c Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 16:43:55 +0800 Subject: [PATCH 09/20] Support multiple tags query Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 21 +++++++++++---------- services/hilogd/compressing_rotator.cpp | 2 +- services/hilogd/include/log_reader.h | 11 ++++++----- services/hilogd/log_buffer.cpp | 11 ++++++++++- services/hilogd/log_querier.cpp | 3 +++ services/hilogtool/log_controller.cpp | 10 ++++++++++ 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index 47817cc..48d200a 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -101,14 +101,15 @@ typedef struct { typedef struct { MessageHeader header; - uint8_t exclude : 2; - uint8_t nDomain : 3; - uint8_t nNoDomain : 3; - uint8_t nTag : 4; - uint8_t nNoTag : 4; + uint8_t exclude; + uint8_t nDomain; + uint8_t nNoDomain; + uint8_t nTag; + uint8_t nNoTag; uint8_t levels; uint16_t types; uint32_t domains[MAX_DOMAINS]; + char tags[MAX_TAGS][MAX_TAG_LEN]; uint32_t timeBegin; uint32_t timeEnd; uint16_t logCount; @@ -326,11 +327,11 @@ typedef struct { typedef struct { uint16_t noBlockMode; - uint8_t exclude : 2; - uint8_t nDomain : 3; - uint8_t nNoDomain: 3; - uint8_t nTag : 4; - uint8_t nNoTag: 4; + uint8_t exclude; + uint8_t nDomain; + uint8_t nNoDomain; + uint8_t nTag; + uint8_t nNoTag; uint16_t types; uint16_t levels; uint16_t headLines; diff --git a/services/hilogd/compressing_rotator.cpp b/services/hilogd/compressing_rotator.cpp index 3ec2fd0..c27d72a 100644 --- a/services/hilogd/compressing_rotator.cpp +++ b/services/hilogd/compressing_rotator.cpp @@ -17,7 +17,7 @@ #include #include - +#include #include #include namespace OHOS { diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index bd3cc65..8bc4afe 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -33,14 +33,15 @@ class HilogBuffer; #define TYPE_PERSISTER 2 using QueryCondition = struct QueryCondition { - uint8_t exclude : 2; - uint8_t nDomain : 3; - uint8_t nNoDomain : 3; - uint8_t nTag : 4; - uint8_t nNoTag : 4; + uint8_t exclude = 0; + uint8_t nDomain = 0; + uint8_t nNoDomain = 0; + uint8_t nTag = 0; + uint8_t nNoTag = 0; uint16_t levels = 0; uint16_t types = 0; uint32_t domains[MAX_DOMAINS]; + std::string tags[MAX_TAGS]; uint32_t timeBegin = 0; uint32_t timeEnd = 0; uint8_t noLevels = 0; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index ba824cd..5af192b 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -340,7 +340,6 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) const int DOMAIN_MODULE_BITS = 8; // domain exclusion - int ret = 0; if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.nNoDomain != 0)) { for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { if (((reader->queryCondition.noDomains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomains[i] == reader->readPos->domain) || @@ -350,6 +349,7 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) } } } + int ret = 0; if (reader->queryCondition.nDomain > 0) { for (int i = 0; i < reader->queryCondition.nDomain; i++) { if (!((reader->queryCondition.domains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.domains[i] != reader->readPos->domain) || @@ -383,6 +383,15 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) != 0) && (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) != 0)) { + if (reader->queryCondition.nTag > 0) { + for (int i = 0; i < reader->queryCondition.nTag; i++) { + if (reader->readPos->tag == reader->queryCondition.tags[i]) { + ret = 1; + break; + } + } + if (ret == 0) return false; + } return true; } } diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index a3ab702..c72b2e7 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -398,6 +398,9 @@ inline void SetCondition(std::shared_ptr logReader, const LogQueryReq for (int i = 0; i < qRstMsg->nDomain; i++) { logReader->queryCondition.domains[i] = qRstMsg->domains[i]; } + for (int i = 0; i < qRstMsg->nTag; i++) { + logReader->queryCondition.tags[i] = qRstMsg->tags[i]; + } logReader->queryCondition.timeBegin = qRstMsg->timeBegin; logReader->queryCondition.timeEnd = qRstMsg->timeEnd; } diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 8249aae..5f96a2c 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -153,6 +153,7 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte logQueryRequest.levels = context->levels; logQueryRequest.types = context->types; logQueryRequest.nDomain = context->nDomain; + logQueryRequest.nTag = context->nTag; if (context->domainArgs != "") { vector vecLogDomain; Split(context->domainArgs, " ", vecLogDomain); @@ -162,6 +163,15 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte std::istringstream(s) >> std::hex >> logQueryRequest.domains[nDomain++]; } } + if (context->tagArgs != "") { + vector vecTagDomain; + Split(context->tagArgs, " ", vecTagDomain); + int nTag = 0; + for (auto s : vecTagDomain) { + if (s == " ") continue; + std::istringstream(s) >> std::hex >> logQueryRequest.tags[nTag++]; + } + } logQueryRequest.timeBegin = context->beginTime; logQueryRequest.timeEnd = context->endTime; if (context->exclude == 1) { -- Gitee From 28a375587e9ac7d1aaf3d0f9a1b96b091fcfcc26 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 16:55:17 +0800 Subject: [PATCH 10/20] Remove unuseful exclude flag Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 2 -- services/hilogd/include/log_reader.h | 2 -- services/hilogd/log_buffer.cpp | 7 +++-- services/hilogd/log_querier.cpp | 12 +++------ services/hilogtool/log_controller.cpp | 31 ++++++++++------------- services/hilogtool/main.cpp | 4 --- 6 files changed, 19 insertions(+), 39 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index 48d200a..7c05e06 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -101,7 +101,6 @@ typedef struct { typedef struct { MessageHeader header; - uint8_t exclude; uint8_t nDomain; uint8_t nNoDomain; uint8_t nTag; @@ -327,7 +326,6 @@ typedef struct { typedef struct { uint16_t noBlockMode; - uint8_t exclude; uint8_t nDomain; uint8_t nNoDomain; uint8_t nTag; diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index 8bc4afe..c161a06 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -33,7 +33,6 @@ class HilogBuffer; #define TYPE_PERSISTER 2 using QueryCondition = struct QueryCondition { - uint8_t exclude = 0; uint8_t nDomain = 0; uint8_t nNoDomain = 0; uint8_t nTag = 0; @@ -56,7 +55,6 @@ public: std::list::iterator lastPos; std::list oldData; QueryCondition queryCondition; - bool exclude = false; std::unique_ptr hilogtoolConnectSocket; bool isNotified; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 5af192b..ca42494 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -340,7 +340,7 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) const int DOMAIN_MODULE_BITS = 8; // domain exclusion - if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.nNoDomain != 0)) { + if (reader->queryCondition.nNoDomain != 0) { for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { if (((reader->queryCondition.noDomains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomains[i] == reader->readPos->domain) || (reader->queryCondition.noDomains[i] <= DOMAIN_FUZZY_MASK && @@ -368,14 +368,13 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) (reader->readPos->tv_sec <= reader->queryCondition.timeEnd))) { // type and level condition // exclusion check first - if ((reader->queryCondition.exclude == 1) && - ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || + if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0)) ) { return false; } - if ((reader->queryCondition.exclude == 1) && (reader->queryCondition.nNoTag > 0)) { + if (reader->queryCondition.nNoTag > 0) { for (int i = 0; i < reader->queryCondition.nNoTag; i++) { if (reader->readPos->tag == reader->queryCondition.noTags[i]) return false; } diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index c72b2e7..8074427 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -94,10 +94,9 @@ LogPersisterRotator* MakeRotator(LogPersistStartMsg& pLogPersistStartMsg) }; } -void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer* buffer, bool exclude = false) +void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer* buffer) { logReader->SetCmd(LOG_QUERY_RESPONSE); - logReader->exclude = exclude; buffer->AddLogReader(logReader); buffer->Query(logReader); } @@ -407,7 +406,6 @@ inline void SetCondition(std::shared_ptr logReader, const LogQueryReq inline void SetExclusion(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) { - logReader->queryCondition.exclude = 1; logReader->queryCondition.noLevels = qRstMsg->noLevels; logReader->queryCondition.noTypes = qRstMsg->noTypes; logReader->queryCondition.nNoDomain = qRstMsg->nNoDomain; @@ -433,12 +431,8 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) case LOG_QUERY_REQUEST: qRstMsg = (LogQueryRequest*) g_tempBuffer; SetCondition(logReader, qRstMsg); - if (qRstMsg->exclude == 1) { - SetExclusion(logReader, qRstMsg); - } else { - logReader->queryCondition.exclude = 0; - } - HandleLogQueryRequest(logReader, hilogBuffer, logReader->queryCondition.exclude); + SetExclusion(logReader, qRstMsg); + HandleLogQueryRequest(logReader, hilogBuffer); break; case NEXT_REQUEST: nRstMsg = (NextRequest*) g_tempBuffer; diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 5f96a2c..2ee3566 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -174,25 +174,20 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte } logQueryRequest.timeBegin = context->beginTime; logQueryRequest.timeEnd = context->endTime; - if (context->exclude == 1) { - logQueryRequest.noLevels = context->noLevels; - logQueryRequest.noTypes = context->noTypes; - logQueryRequest.nNoDomain = context->nNoDomain; - for (int i = 0; i < context->nNoDomain; i++) { - std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; - } - for (int i = 0; i < context->nNoTag; i++) { - if (context->noTags[i].length() >= MAX_TAG_LEN) { - strncpy_s(logQueryRequest.noTags[i], MAX_TAG_LEN, - context->noTags[i].c_str(), MAX_TAG_LEN - 1); - } else { - strncpy_s(logQueryRequest.noTags[i], context->noTags[i].length() + 1, - context->noTags[i].c_str(), context->noTags[i].length()); - } + logQueryRequest.noLevels = context->noLevels; + logQueryRequest.noTypes = context->noTypes; + logQueryRequest.nNoDomain = context->nNoDomain; + for (int i = 0; i < context->nNoDomain; i++) { + std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; + } + for (int i = 0; i < context->nNoTag; i++) { + if (context->noTags[i].length() >= MAX_TAG_LEN) { + strncpy_s(logQueryRequest.noTags[i], MAX_TAG_LEN, + context->noTags[i].c_str(), MAX_TAG_LEN - 1); + } else { + strncpy_s(logQueryRequest.noTags[i], context->noTags[i].length() + 1, + context->noTags[i].c_str(), context->noTags[i].length()); } - logQueryRequest.exclude = 1; - } else { - logQueryRequest.exclude = 0; } SetMsgHead(&logQueryRequest.header, LOG_QUERY_REQUEST, sizeof(LogQueryRequest)-sizeof(MessageHeader)); logQueryRequest.header.version = 0; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index be95e28..88fead3 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -255,7 +255,6 @@ int HilogEntry(int argc, char* argv[]) indexType++; if (!strstr(types.c_str(), "-")) { if (types.front() == '^') { - context.exclude = 1; regex delimiter(","); // whitespace vector v(sregex_token_iterator(types.begin() + 1, types.end(), delimiter, -1), sregex_token_iterator()); @@ -278,7 +277,6 @@ int HilogEntry(int argc, char* argv[]) indexLevel++; if (!strstr(levels.c_str(), "-")) { if (levels.front() == '^') { - context.exclude = 1; regex delimiter(","); // whitespace vector v(sregex_token_iterator(levels.begin() + 1, levels.end(), delimiter, -1), sregex_token_iterator()); @@ -371,7 +369,6 @@ int HilogEntry(int argc, char* argv[]) indexDomain++; if (!strstr(domains.c_str(), "-")) { if (domains.front() == '^') { - context.exclude = 1; std::regex delimiter(","); // whitespace std::vector v(std::sregex_token_iterator(domains.begin() + 1, domains.end(), delimiter, -1), std::sregex_token_iterator()); @@ -405,7 +402,6 @@ int HilogEntry(int argc, char* argv[]) indexTag++; if (!strstr(tags.c_str(), "-")) { if (tags.front() == '^') { - context.exclude = 1; std::regex delimiter(","); // whitespace std::vector v(std::sregex_token_iterator(tags.begin() + 1, tags.end(), delimiter, -1), std::sregex_token_iterator()); -- Gitee From 7fe535c8848e5170d31e0c20290cb2777ca7c8c8 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 16:59:44 +0800 Subject: [PATCH 11/20] No string splitting on query Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 6 ++++-- services/hilogtool/log_controller.cpp | 20 ++++---------------- services/hilogtool/main.cpp | 4 ++-- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index 7c05e06..c8dd502 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -336,8 +336,10 @@ typedef struct { uint16_t tailLines; time_t beginTime; time_t endTime; - std::string domain; - std::string tag; + std::string domain; // domain recv + std::string tag; // tag recv + std::string domains[MAX_DOMAINS]; // domains send + std::string tags[MAX_TAGS]; // tags send uint16_t noTypes; uint16_t noLevels; std::string noDomains[MAX_DOMAINS]; diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 2ee3566..4d95ceb 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -154,23 +154,11 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte logQueryRequest.types = context->types; logQueryRequest.nDomain = context->nDomain; logQueryRequest.nTag = context->nTag; - if (context->domainArgs != "") { - vector vecLogDomain; - Split(context->domainArgs, " ", vecLogDomain); - int nDomain = 0; - for (auto s : vecLogDomain) { - if (s == " ") continue; - std::istringstream(s) >> std::hex >> logQueryRequest.domains[nDomain++]; - } + for (int i = 0; i < context->nDomain; i++) { + std::istringstream(context->domains[i]) >> std::hex >> logQueryRequest.domains[i]; } - if (context->tagArgs != "") { - vector vecTagDomain; - Split(context->tagArgs, " ", vecTagDomain); - int nTag = 0; - for (auto s : vecTagDomain) { - if (s == " ") continue; - std::istringstream(s) >> std::hex >> logQueryRequest.tags[nTag++]; - } + for (int i = 0; i < context->nTag; i++) { + std::istringstream(context->tags[i]) >> std::hex >> logQueryRequest.tags[i]; } logQueryRequest.timeBegin = context->beginTime; logQueryRequest.timeEnd = context->endTime; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 88fead3..9edec77 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -376,8 +376,8 @@ int HilogEntry(int argc, char* argv[]) context.noDomains[context.nNoDomain++] = s; } } else { + context.domains[context.nDomain++] = domains; context.domainArgs += (domains + " "); - context.nDomain++; } } else { break; @@ -409,8 +409,8 @@ int HilogEntry(int argc, char* argv[]) context.noTags[context.nNoTag++] = s; } } else { + context.tags[context.nTag++] = tags; context.tagArgs += (tags + " "); - context.nTag++; } } else { break; -- Gitee From 8ae8e761f7519e0f6f29c013168ddc3dc4cb2afe Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 17:00:34 +0800 Subject: [PATCH 12/20] Update hilogtool help message about exclusion Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogtool/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 9edec77..a84a020 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -105,6 +105,10 @@ static void Helper() " zone display the time zone.\n" " -b , --baselevel=\n" " set loggable level.\n" + " \n Types, levels, domains, tags support exclusion query.\n" + " Exclusion query can be done with parameters starting with \"^\" and delimiter \",\".\n" + " Example: \"-t ^core,app\" excludes logs with types core and app.\n" + " Could be used along with other parameters.\n" ); } -- Gitee From 16855aee614e52d4cb505c5b56be3cd6e9086c4c Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 17:06:30 +0800 Subject: [PATCH 13/20] Move hilogtool private HilogArgs into hilogtool.h Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 43 -------------- services/hilogtool/include/hilogtool.h | 66 +++++++++++++++++++++ services/hilogtool/include/log_controller.h | 1 + 3 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 services/hilogtool/include/hilogtool.h diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index c8dd502..d86fd62 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -323,47 +323,4 @@ typedef struct { std::string pidStr; } SetPropertyParam; - -typedef struct { - uint16_t noBlockMode; - uint8_t nDomain; - uint8_t nNoDomain; - uint8_t nTag; - uint8_t nNoTag; - uint16_t types; - uint16_t levels; - uint16_t headLines; - uint16_t tailLines; - time_t beginTime; - time_t endTime; - std::string domain; // domain recv - std::string tag; // tag recv - std::string domains[MAX_DOMAINS]; // domains send - std::string tags[MAX_TAGS]; // tags send - uint16_t noTypes; - uint16_t noLevels; - std::string noDomains[MAX_DOMAINS]; - std::string noTags[MAX_TAGS]; - std::string regexArgs; - std::string buffSizeArgs; - std::string logFileCtrlArgs; - std::string compressArgs; - std::string fileSizeArgs; - std::string fileNumArgs; - std::string filePathArgs; - std::string fileNameArgs; - std::string jobIdArgs; - std::string personalArgs; - std::string logClearArgs; - std::string logTypeArgs; - std::string domainArgs; - std::string statisticArgs; - std::string tagArgs; - std::string logLevelArgs; - std::string flowSwitchArgs; - std::string flowQuotaArgs; - std::string pidArgs; - std::string algorithmArgs; -} HilogArgs; - #endif /* HILOGTOOL_MSG_H */ diff --git a/services/hilogtool/include/hilogtool.h b/services/hilogtool/include/hilogtool.h new file mode 100644 index 0000000..0109bbb --- /dev/null +++ b/services/hilogtool/include/hilogtool.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HILOGTOOL_H +#define HILOGTOOL_H + +namespace OHOS { +namespace HiviewDFX { + +typedef struct { + uint16_t noBlockMode; + uint8_t nDomain; + uint8_t nNoDomain; + uint8_t nTag; + uint8_t nNoTag; + uint16_t types; + uint16_t levels; + uint16_t headLines; + uint16_t tailLines; + time_t beginTime; + time_t endTime; + std::string domain; // domain recv + std::string tag; // tag recv + std::string domains[MAX_DOMAINS]; // domains send + std::string tags[MAX_TAGS]; // tags send + uint16_t noTypes; + uint16_t noLevels; + std::string noDomains[MAX_DOMAINS]; + std::string noTags[MAX_TAGS]; + std::string regexArgs; + std::string buffSizeArgs; + std::string logFileCtrlArgs; + std::string compressArgs; + std::string fileSizeArgs; + std::string fileNumArgs; + std::string filePathArgs; + std::string fileNameArgs; + std::string jobIdArgs; + std::string personalArgs; + std::string logClearArgs; + std::string logTypeArgs; + std::string domainArgs; + std::string statisticArgs; + std::string tagArgs; + std::string logLevelArgs; + std::string flowSwitchArgs; + std::string flowQuotaArgs; + std::string pidArgs; + std::string algorithmArgs; +} HilogArgs; + +} // namespace HiviewDFX +} // namespace OHOS +#endif diff --git a/services/hilogtool/include/log_controller.h b/services/hilogtool/include/log_controller.h index 39dc381..2030eac 100644 --- a/services/hilogtool/include/log_controller.h +++ b/services/hilogtool/include/log_controller.h @@ -22,6 +22,7 @@ #include #include "hilogtool_msg.h" #include "seq_packet_socket_client.h" +#include "hilogtool.h" namespace OHOS { namespace HiviewDFX { -- Gitee From 87e67b0e4d6eabba7c9d320260885274cc80e1f7 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 17:11:32 +0800 Subject: [PATCH 14/20] Combine queryCondition set functions Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogd/log_querier.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 8074427..f776862 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -394,6 +394,11 @@ inline void SetCondition(std::shared_ptr logReader, const LogQueryReq logReader->queryCondition.levels = qRstMsg->levels; logReader->queryCondition.types = qRstMsg->types; logReader->queryCondition.nDomain = qRstMsg->nDomain; + logReader->queryCondition.nTag = qRstMsg->nTag; + logReader->queryCondition.noLevels = qRstMsg->noLevels; + logReader->queryCondition.noTypes = qRstMsg->noTypes; + logReader->queryCondition.nNoDomain = qRstMsg->nNoDomain; + logReader->queryCondition.nNoTag = qRstMsg->nNoTag; for (int i = 0; i < qRstMsg->nDomain; i++) { logReader->queryCondition.domains[i] = qRstMsg->domains[i]; } @@ -402,14 +407,6 @@ inline void SetCondition(std::shared_ptr logReader, const LogQueryReq } logReader->queryCondition.timeBegin = qRstMsg->timeBegin; logReader->queryCondition.timeEnd = qRstMsg->timeEnd; -} - -inline void SetExclusion(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) -{ - logReader->queryCondition.noLevels = qRstMsg->noLevels; - logReader->queryCondition.noTypes = qRstMsg->noTypes; - logReader->queryCondition.nNoDomain = qRstMsg->nNoDomain; - logReader->queryCondition.nNoTag = qRstMsg->nNoTag; for (int i = 0; i < qRstMsg->nNoDomain; i++) { logReader->queryCondition.noDomains[i] = qRstMsg->noDomains[i]; } @@ -431,7 +428,6 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) case LOG_QUERY_REQUEST: qRstMsg = (LogQueryRequest*) g_tempBuffer; SetCondition(logReader, qRstMsg); - SetExclusion(logReader, qRstMsg); HandleLogQueryRequest(logReader, hilogBuffer); break; case NEXT_REQUEST: -- Gitee From 908560138980583a996a03dc7c0b5296468baf42 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Sun, 27 Jun 2021 17:40:16 +0800 Subject: [PATCH 15/20] Code format Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogd/compressing_rotator.cpp | 2 +- services/hilogd/log_buffer.cpp | 24 +++++------ services/hilogd/log_querier.cpp | 54 ++++++++++++------------- services/hilogtool/include/hilogtool.h | 3 -- services/hilogtool/main.cpp | 25 ++++++------ 5 files changed, 52 insertions(+), 56 deletions(-) diff --git a/services/hilogd/compressing_rotator.cpp b/services/hilogd/compressing_rotator.cpp index c27d72a..3ec2fd0 100644 --- a/services/hilogd/compressing_rotator.cpp +++ b/services/hilogd/compressing_rotator.cpp @@ -17,7 +17,7 @@ #include #include -#include + #include #include namespace OHOS { diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index ca42494..bdc7836 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -35,6 +35,9 @@ using namespace std; const float DROP_RATIO = 0.05; static int g_maxBufferSize = 4194304; static int g_maxBufferSizeByType[LOG_TYPE_MAX] = {1048576, 1048576, 1048576, 1048576}; +const int DOMAIN_STRICT_MASK = 0xd000000; +const int DOMAIN_FUZZY_MASK = 0xdffff; +const int DOMAIN_MODULE_BITS = 8; HilogBuffer::HilogBuffer() { @@ -52,6 +55,7 @@ HilogBuffer::~HilogBuffer() {} size_t HilogBuffer::Insert(const HilogMsg& msg) { + printf("insert: %s\n", CONTENT_PTR((&msg))); size_t eleSize = CONTENT_LEN((&msg)); /* include '\0' */ if (unlikely(msg.tag_len > MAX_TAG_LEN || msg.tag_len == 0 || eleSize > MAX_LOG_LEN || eleSize <= 0)) { @@ -335,26 +339,22 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) * strict mode: 0xdxxxxxx (full) * fuzzy mode: 0xdxxxx (using last 2 digits of full domain as mask) */ - const int DOMAIN_STRICT_MASK = 0xd000000; - const int DOMAIN_FUZZY_MASK = 0xdffff; - const int DOMAIN_MODULE_BITS = 8; // domain exclusion if (reader->queryCondition.nNoDomain != 0) { for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { - if (((reader->queryCondition.noDomains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.noDomains[i] == reader->readPos->domain) || - (reader->queryCondition.noDomains[i] <= DOMAIN_FUZZY_MASK && - reader->queryCondition.noDomains[i] == (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) { + uint32_t noDomains = reader->queryCondition.noDomains[i]; + if (((noDomains >= DOMAIN_STRICT_MASK && noDomains == reader->readPos->domain) || + (noDomains <= DOMAIN_FUZZY_MASK && noDomains == (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) return false; - } } } int ret = 0; if (reader->queryCondition.nDomain > 0) { for (int i = 0; i < reader->queryCondition.nDomain; i++) { - if (!((reader->queryCondition.domains[i] >= DOMAIN_STRICT_MASK && reader->queryCondition.domains[i] != reader->readPos->domain) || - (reader->queryCondition.domains[i] <= DOMAIN_FUZZY_MASK && - reader->queryCondition.domains[i] != (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) { + uint32_t domains = reader->queryCondition.domains[i]; + if (!((domains >= DOMAIN_STRICT_MASK && domains != reader->readPos->domain) || + (domains <= DOMAIN_FUZZY_MASK && domains != (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) { ret = 1; break; } @@ -370,9 +370,7 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) // exclusion check first if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0)) - ) { - return false; - } + ) return false; if (reader->queryCondition.nNoTag > 0) { for (int i = 0; i < reader->queryCondition.nNoTag; i++) { diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index f776862..8d56315 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -94,17 +94,17 @@ LogPersisterRotator* MakeRotator(LogPersistStartMsg& pLogPersistStartMsg) }; } -void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer* buffer) +void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer& buffer) { logReader->SetCmd(LOG_QUERY_RESPONSE); - buffer->AddLogReader(logReader); - buffer->Query(logReader); + buffer.AddLogReader(logReader); + buffer.Query(logReader); } -void HandleNextRequest(std::shared_ptr logReader, HilogBuffer* buffer) +void HandleNextRequest(std::shared_ptr logReader, HilogBuffer& buffer) { logReader->SetCmd(NEXT_RESPONSE); - buffer->Query(logReader); + buffer.Query(logReader); } void HandlePersistStartRequest(char* reqMsg, std::shared_ptr logReader, HilogBuffer* buffer) @@ -389,29 +389,29 @@ void HandleBufferClearRequest(char* reqMsg, std::shared_ptr logReader logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); } -inline void SetCondition(std::shared_ptr logReader, const LogQueryRequest* qRstMsg) +void SetCondition(std::shared_ptr logReader, const LogQueryRequest& qRstMsg) { - logReader->queryCondition.levels = qRstMsg->levels; - logReader->queryCondition.types = qRstMsg->types; - logReader->queryCondition.nDomain = qRstMsg->nDomain; - logReader->queryCondition.nTag = qRstMsg->nTag; - logReader->queryCondition.noLevels = qRstMsg->noLevels; - logReader->queryCondition.noTypes = qRstMsg->noTypes; - logReader->queryCondition.nNoDomain = qRstMsg->nNoDomain; - logReader->queryCondition.nNoTag = qRstMsg->nNoTag; - for (int i = 0; i < qRstMsg->nDomain; i++) { - logReader->queryCondition.domains[i] = qRstMsg->domains[i]; + logReader->queryCondition.levels = qRstMsg.levels; + logReader->queryCondition.types = qRstMsg.types; + logReader->queryCondition.nDomain = qRstMsg.nDomain; + logReader->queryCondition.nTag = qRstMsg.nTag; + logReader->queryCondition.noLevels = qRstMsg.noLevels; + logReader->queryCondition.noTypes = qRstMsg.noTypes; + logReader->queryCondition.nNoDomain = qRstMsg.nNoDomain; + logReader->queryCondition.nNoTag = qRstMsg.nNoTag; + for (int i = 0; i < qRstMsg.nDomain; i++) { + logReader->queryCondition.domains[i] = qRstMsg.domains[i]; } - for (int i = 0; i < qRstMsg->nTag; i++) { - logReader->queryCondition.tags[i] = qRstMsg->tags[i]; + for (int i = 0; i < qRstMsg.nTag; i++) { + logReader->queryCondition.tags[i] = qRstMsg.tags[i]; } - logReader->queryCondition.timeBegin = qRstMsg->timeBegin; - logReader->queryCondition.timeEnd = qRstMsg->timeEnd; - for (int i = 0; i < qRstMsg->nNoDomain; i++) { - logReader->queryCondition.noDomains[i] = qRstMsg->noDomains[i]; + logReader->queryCondition.timeBegin = qRstMsg.timeBegin; + logReader->queryCondition.timeEnd = qRstMsg.timeEnd; + for (int i = 0; i < qRstMsg.nNoDomain; i++) { + logReader->queryCondition.noDomains[i] = qRstMsg.noDomains[i]; } - for (int i = 0; i < qRstMsg->nNoTag; i++) { - logReader->queryCondition.noTags[i] = qRstMsg->noTags[i]; + for (int i = 0; i < qRstMsg.nNoTag; i++) { + logReader->queryCondition.noTags[i] = qRstMsg.noTags[i]; } } @@ -427,13 +427,13 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) switch (header->msgType) { case LOG_QUERY_REQUEST: qRstMsg = (LogQueryRequest*) g_tempBuffer; - SetCondition(logReader, qRstMsg); - HandleLogQueryRequest(logReader, hilogBuffer); + SetCondition(logReader, *qRstMsg); + HandleLogQueryRequest(logReader, *hilogBuffer); break; case NEXT_REQUEST: nRstMsg = (NextRequest*) g_tempBuffer; if (nRstMsg->sendId == SENDIDA) { - HandleNextRequest(logReader, hilogBuffer); + HandleNextRequest(logReader, *hilogBuffer); } break; case MC_REQ_LOG_PERSIST_START: diff --git a/services/hilogtool/include/hilogtool.h b/services/hilogtool/include/hilogtool.h index 0109bbb..0b0ceb2 100644 --- a/services/hilogtool/include/hilogtool.h +++ b/services/hilogtool/include/hilogtool.h @@ -12,13 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifndef HILOGTOOL_H #define HILOGTOOL_H namespace OHOS { namespace HiviewDFX { - typedef struct { uint16_t noBlockMode; uint8_t nDomain; @@ -60,7 +58,6 @@ typedef struct { std::string pidArgs; std::string algorithmArgs; } HilogArgs; - } // namespace HiviewDFX } // namespace OHOS #endif diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index a84a020..49b35b5 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -25,6 +25,7 @@ #include #include #include + #include "hilog/log.h" #include "hilog_common.h" #include "hilogtool_msg.h" @@ -125,7 +126,7 @@ static std::time_t Str2Time(const std::string& str, bool isDst = false, return mktime(&t); } } -static int GetTypes(HilogArgs context, string typesArgs, bool exclude = false) +static int GetTypes(HilogArgs context, const string& typesArgs, bool exclude = false) { uint16_t types = 0; if (exclude) { @@ -146,7 +147,7 @@ static int GetTypes(HilogArgs context, string typesArgs, bool exclude = false) return types; } -static int GetLevels(HilogArgs context, string levelsArgs, bool exclude = false) +static int GetLevels(HilogArgs context, const string& levelsArgs, bool exclude = false) { uint16_t levels = 0; if (exclude) { @@ -262,7 +263,7 @@ int HilogEntry(int argc, char* argv[]) regex delimiter(","); // whitespace vector v(sregex_token_iterator(types.begin() + 1, types.end(), delimiter, -1), sregex_token_iterator()); - for (auto&& s : v) { + for (auto s : v) { context.noTypes = GetTypes(context, s, true); } } else { @@ -284,7 +285,7 @@ int HilogEntry(int argc, char* argv[]) regex delimiter(","); // whitespace vector v(sregex_token_iterator(levels.begin() + 1, levels.end(), delimiter, -1), sregex_token_iterator()); - for (auto&& s : v) { + for (auto s : v) { context.noLevels = GetLevels(context, s, true); } } else { @@ -373,10 +374,10 @@ int HilogEntry(int argc, char* argv[]) indexDomain++; if (!strstr(domains.c_str(), "-")) { if (domains.front() == '^') { - std::regex delimiter(","); // whitespace - std::vector v(std::sregex_token_iterator(domains.begin() + 1, domains.end(), delimiter, -1), - std::sregex_token_iterator()); - for (auto&& s: v) { + regex delimiter(","); // whitespace + vector v(sregex_token_iterator(domains.begin() + 1, domains.end(), delimiter, -1), + sregex_token_iterator()); + for (auto s: v) { context.noDomains[context.nNoDomain++] = s; } } else { @@ -406,10 +407,10 @@ int HilogEntry(int argc, char* argv[]) indexTag++; if (!strstr(tags.c_str(), "-")) { if (tags.front() == '^') { - std::regex delimiter(","); // whitespace - std::vector v(std::sregex_token_iterator(tags.begin() + 1, tags.end(), delimiter, -1), - std::sregex_token_iterator()); - for (auto&& s: v) { + regex delimiter(","); // whitespace + vector v(sregex_token_iterator(tags.begin() + 1, tags.end(), delimiter, -1), + sregex_token_iterator()); + for (auto s: v) { context.noTags[context.nNoTag++] = s; } } else { -- Gitee From ad27d2b7e61ddd4837528694e0ab7e2068b90328 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Mon, 28 Jun 2021 18:31:39 +0800 Subject: [PATCH 16/20] Hilogtool support forward query delimiter "," Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogtool/main.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 49b35b5..5a2a856 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -185,7 +185,7 @@ int HilogEntry(int argc, char* argv[]) int indexDomain = 0; int indexTag = 0; bool noLogOption = false; - + regex delimiter(","); context.noBlockMode = 0; int32_t ret = 0; HilogShowFormat showFormat = OFF_SHOWFORMAT; @@ -260,15 +260,18 @@ int HilogEntry(int argc, char* argv[]) indexType++; if (!strstr(types.c_str(), "-")) { if (types.front() == '^') { - regex delimiter(","); // whitespace vector v(sregex_token_iterator(types.begin() + 1, types.end(), delimiter, -1), sregex_token_iterator()); for (auto s : v) { context.noTypes = GetTypes(context, s, true); } } else { + vector v(sregex_token_iterator(types.begin(), types.end(), delimiter, -1), + sregex_token_iterator()); + for (auto s : v) { + context.types = GetTypes(context, s); + } typesArgs += types; - context.types = GetTypes(context, types); } } else { break; @@ -282,15 +285,18 @@ int HilogEntry(int argc, char* argv[]) indexLevel++; if (!strstr(levels.c_str(), "-")) { if (levels.front() == '^') { - regex delimiter(","); // whitespace vector v(sregex_token_iterator(levels.begin() + 1, levels.end(), delimiter, -1), sregex_token_iterator()); for (auto s : v) { context.noLevels = GetLevels(context, s, true); } } else { + vector v(sregex_token_iterator(levels.begin(), levels.end(), delimiter, -1), + sregex_token_iterator()); + for (auto s : v) { + context.levels = GetLevels(context, s); + } levelsArgs += levels; - context.levels = GetLevels(context, levels); } } else { break; @@ -374,15 +380,18 @@ int HilogEntry(int argc, char* argv[]) indexDomain++; if (!strstr(domains.c_str(), "-")) { if (domains.front() == '^') { - regex delimiter(","); // whitespace vector v(sregex_token_iterator(domains.begin() + 1, domains.end(), delimiter, -1), sregex_token_iterator()); for (auto s: v) { context.noDomains[context.nNoDomain++] = s; } } else { - context.domains[context.nDomain++] = domains; - context.domainArgs += (domains + " "); + vector v(sregex_token_iterator(domains.begin(), domains.end(), delimiter, -1), + sregex_token_iterator()); + for (auto s: v) { + context.domains[context.nDomain++] = s; + context.domainArgs += (s + " "); + } } } else { break; @@ -407,15 +416,18 @@ int HilogEntry(int argc, char* argv[]) indexTag++; if (!strstr(tags.c_str(), "-")) { if (tags.front() == '^') { - regex delimiter(","); // whitespace vector v(sregex_token_iterator(tags.begin() + 1, tags.end(), delimiter, -1), sregex_token_iterator()); for (auto s: v) { context.noTags[context.nNoTag++] = s; } } else { - context.tags[context.nTag++] = tags; - context.tagArgs += (tags + " "); + vector v(sregex_token_iterator(tags.begin(), tags.end(), delimiter, -1), + sregex_token_iterator()); + for (auto s: v) { + context.tags[context.nTag++] = s; + context.tagArgs += (s + " "); + } } } else { break; -- Gitee From 5df904b80194a7b68329c88506b666101f80c26a Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 29 Jun 2021 11:15:51 +0800 Subject: [PATCH 17/20] Remove begin/end time query; Remove -M Signed-off-by: Wu Shangwei <2826256824@qq.com> --- frameworks/native/include/hilogtool_msg.h | 2 - services/hilogd/include/log_reader.h | 2 - services/hilogd/log_buffer.cpp | 47 ++++++++++------------- services/hilogd/log_querier.cpp | 2 - services/hilogd/log_reader.cpp | 4 -- services/hilogtool/include/hilogtool.h | 2 - services/hilogtool/log_controller.cpp | 2 - services/hilogtool/main.cpp | 32 --------------- 8 files changed, 20 insertions(+), 73 deletions(-) diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index d86fd62..f3b3334 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -109,8 +109,6 @@ typedef struct { uint16_t types; uint32_t domains[MAX_DOMAINS]; char tags[MAX_TAGS][MAX_TAG_LEN]; - uint32_t timeBegin; - uint32_t timeEnd; uint16_t logCount; uint8_t noLevels; uint16_t noTypes; diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index c161a06..85f36b1 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -41,8 +41,6 @@ using QueryCondition = struct QueryCondition { uint16_t types = 0; uint32_t domains[MAX_DOMAINS]; std::string tags[MAX_TAGS]; - uint32_t timeBegin = 0; - uint32_t timeEnd = 0; uint8_t noLevels = 0; uint16_t noTypes = 0; uint32_t noDomains[MAX_DOMAINS]; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index bdc7836..49da250 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -332,7 +332,6 @@ int32_t HilogBuffer::ClearStatisticInfoByDomain(uint32_t domain) bool HilogBuffer::conditionMatch(std::shared_ptr reader) { - // domain, timeBegin & timeEnd are zero when not indicated // domain condition /* patterns: @@ -362,35 +361,29 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) if (ret == 0) return false; ret = 0; } - // time condition - if ((reader->queryCondition.timeBegin == 0 && reader->queryCondition.timeEnd == 0) || - ((reader->readPos->tv_sec >= reader->queryCondition.timeBegin) && - (reader->readPos->tv_sec <= reader->queryCondition.timeEnd))) { - // type and level condition - // exclusion check first - if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || - (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0)) - ) return false; - - if (reader->queryCondition.nNoTag > 0) { - for (int i = 0; i < reader->queryCondition.nNoTag; i++) { - if (reader->readPos->tag == reader->queryCondition.noTags[i]) return false; - } + + // type and level condition + // exclusion check first + if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || + (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0))) + return false; + if (reader->queryCondition.nNoTag > 0) { + for (int i = 0; i < reader->queryCondition.nNoTag; i++) { + if (reader->readPos->tag == reader->queryCondition.noTags[i]) return false; } - - if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) != 0) && - (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) != 0)) { - if (reader->queryCondition.nTag > 0) { - for (int i = 0; i < reader->queryCondition.nTag; i++) { - if (reader->readPos->tag == reader->queryCondition.tags[i]) { - ret = 1; - break; - } - } - if (ret == 0) return false; + } + if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) != 0) && + (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) != 0)) { + if (reader->queryCondition.nTag > 0) { + for (int i = 0; i < reader->queryCondition.nTag; i++) { + if (reader->readPos->tag == reader->queryCondition.tags[i]) { + ret = 1; + break; } - return true; } + if (ret == 0) return false; + } + return true; } return false; } diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 8d56315..b08a0b2 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -405,8 +405,6 @@ void SetCondition(std::shared_ptr logReader, const LogQueryRequest& q for (int i = 0; i < qRstMsg.nTag; i++) { logReader->queryCondition.tags[i] = qRstMsg.tags[i]; } - logReader->queryCondition.timeBegin = qRstMsg.timeBegin; - logReader->queryCondition.timeEnd = qRstMsg.timeEnd; for (int i = 0; i < qRstMsg.nNoDomain; i++) { logReader->queryCondition.noDomains[i] = qRstMsg.noDomains[i]; } diff --git a/services/hilogd/log_reader.cpp b/services/hilogd/log_reader.cpp index 0bb7b2f..cad3aa6 100644 --- a/services/hilogd/log_reader.cpp +++ b/services/hilogd/log_reader.cpp @@ -30,10 +30,6 @@ HilogBuffer* LogReader::hilogBuffer = nullptr; LogReader::LogReader() { oldData = {}; - queryCondition.levels = 0; - queryCondition.types = 0; - queryCondition.timeBegin = 0; - queryCondition.timeEnd = 0; isNotified = false; } diff --git a/services/hilogtool/include/hilogtool.h b/services/hilogtool/include/hilogtool.h index 0b0ceb2..a13cfdb 100644 --- a/services/hilogtool/include/hilogtool.h +++ b/services/hilogtool/include/hilogtool.h @@ -27,8 +27,6 @@ typedef struct { uint16_t levels; uint16_t headLines; uint16_t tailLines; - time_t beginTime; - time_t endTime; std::string domain; // domain recv std::string tag; // tag recv std::string domains[MAX_DOMAINS]; // domains send diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 4d95ceb..58b6e86 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -160,8 +160,6 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte for (int i = 0; i < context->nTag; i++) { std::istringstream(context->tags[i]) >> std::hex >> logQueryRequest.tags[i]; } - logQueryRequest.timeBegin = context->beginTime; - logQueryRequest.timeEnd = context->endTime; logQueryRequest.noLevels = context->noLevels; logQueryRequest.noTypes = context->noTypes; logQueryRequest.nNoDomain = context->nNoDomain; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 5a2a856..21bea47 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -91,8 +91,6 @@ static void Helper() " query log file writing task query.\n" " start start a log file writing task, see -F -l -n -c for to set more configs,\n" " stop stop a log file writing task.\n" - " -M begintime/endtime/domain/tag/level,--multi-query begintime/endtime/domain/tag/level\n" - " multiple conditions query\n" " -v , --format= options:\n" " time display local time.\n" " color display colorful logs by log level.i.e. \x1B[38;5;231mVERBOSE\n" @@ -208,7 +206,6 @@ int HilogEntry(int argc, char* argv[]) { "tail", required_argument, nullptr, 'z' }, { "format", required_argument, nullptr, 'v' }, { "buffer-size", required_argument, nullptr, 'G' }, - { "multi-query", required_argument, nullptr, 'M' }, { "jobid", required_argument, nullptr, 'j' }, { "flowctrl", required_argument, nullptr, 'Q' }, { "compress", required_argument, nullptr, 'c' }, @@ -306,35 +303,6 @@ int HilogEntry(int argc, char* argv[]) case 'v': showFormat = HilogFormat(optarg); break; - case 'M':{ - std::vector vecSrc; - std::vector vecSplit; - vecSplit.push_back(optarg); - for (auto src : vecSplit) { - vecSplit.clear(); - int iRet = MultiQuerySplit(src, '/', vecSplit); - if (iRet == 0) { - int idex = 0; - for (auto it : vecSplit) { - vecSrc.push_back(it.c_str()); - idex++; - } - } - if (vecSrc.size() > MULARGS) { - std::cout<<"Invalid parameter"< Date: Tue, 29 Jun 2021 11:56:27 +0800 Subject: [PATCH 18/20] HilogBuffer::conditionMatch simplify Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogd/log_buffer.cpp | 58 ++++++++++++++++------------------ services/hilogtool/main.cpp | 8 ++--- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 49da250..fadacda 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -332,22 +332,15 @@ int32_t HilogBuffer::ClearStatisticInfoByDomain(uint32_t domain) bool HilogBuffer::conditionMatch(std::shared_ptr reader) { - // domain condition - - /* patterns: + /* domain patterns: * strict mode: 0xdxxxxxx (full) * fuzzy mode: 0xdxxxx (using last 2 digits of full domain as mask) */ - // domain exclusion - if (reader->queryCondition.nNoDomain != 0) { - for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { - uint32_t noDomains = reader->queryCondition.noDomains[i]; - if (((noDomains >= DOMAIN_STRICT_MASK && noDomains == reader->readPos->domain) || - (noDomains <= DOMAIN_FUZZY_MASK && noDomains == (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) - return false; - } - } + if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) == 0) || + (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.types)) == 0))) + return false; + int ret = 0; if (reader->queryCondition.nDomain > 0) { for (int i = 0; i < reader->queryCondition.nDomain; i++) { @@ -361,31 +354,34 @@ bool HilogBuffer::conditionMatch(std::shared_ptr reader) if (ret == 0) return false; ret = 0; } - - // type and level condition - // exclusion check first - if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || - (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0))) - return false; + if (reader->queryCondition.nTag > 0) { + for (int i = 0; i < reader->queryCondition.nTag; i++) { + if (reader->readPos->tag == reader->queryCondition.tags[i]) { + ret = 1; + break; + } + } + if (ret == 0) return false; + } + // domain exclusion + if (reader->queryCondition.nNoDomain != 0) { + for (int i = 0; i < reader->queryCondition.nNoDomain; i++) { + uint32_t noDomains = reader->queryCondition.noDomains[i]; + if (((noDomains >= DOMAIN_STRICT_MASK && noDomains == reader->readPos->domain) || + (noDomains <= DOMAIN_FUZZY_MASK && noDomains == (reader->readPos->domain >> DOMAIN_MODULE_BITS)))) + return false; + } + } if (reader->queryCondition.nNoTag > 0) { for (int i = 0; i < reader->queryCondition.nNoTag; i++) { if (reader->readPos->tag == reader->queryCondition.noTags[i]) return false; } } - if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) != 0) && - (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) != 0)) { - if (reader->queryCondition.nTag > 0) { - for (int i = 0; i < reader->queryCondition.nTag; i++) { - if (reader->readPos->tag == reader->queryCondition.tags[i]) { - ret = 1; - break; - } - } - if (ret == 0) return false; - } - return true; + if ((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.noTypes)) != 0) || + (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.noLevels)) != 0)) { + return false; } - return false; + return true; } void HilogBuffer::ReturnNoLog(std::shared_ptr reader) diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 21bea47..147945f 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -174,8 +174,6 @@ int HilogEntry(int argc, char* argv[]) { std::vector args; HilogArgs context = {sizeof(HilogArgs), 0}; - string typesArgs; - string levelsArgs; char recvBuffer[RECV_BUF_LEN] = {0}; int optIndex = 0; int indexLevel = 0; @@ -268,7 +266,6 @@ int HilogEntry(int argc, char* argv[]) for (auto s : v) { context.types = GetTypes(context, s); } - typesArgs += types; } } else { break; @@ -293,7 +290,6 @@ int HilogEntry(int argc, char* argv[]) for (auto s : v) { context.levels = GetLevels(context, s); } - levelsArgs += levels; } } else { break; @@ -430,10 +426,10 @@ int HilogEntry(int argc, char* argv[]) exit(-1); } - if (typesArgs == "") { + if (context.types == 0) { context.types = DEFAULT_LOG_TYPE; } - if (levelsArgs == "") { + if (context.levels == 0) { context.levels = DEFAULT_LOG_LEVEL; } if (noLogOption) { -- Gitee From bf6eed590f76921e7a0fd5c3ed4d7676ca70fd63 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 29 Jun 2021 12:37:21 +0800 Subject: [PATCH 19/20] Remove unused function Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogtool/main.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 147945f..1c4d5be 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -111,19 +111,6 @@ static void Helper() ); } -static std::time_t Str2Time(const std::string& str, bool isDst = false, - const std::string& format = "%Y-%m-%d_%H:%M:%S") -{ - if (str == "") { - return 0; - } else { - std::tm t = {0}; - t.tm_isdst = isDst ? 1 : 0; - std::istringstream ss(str); - ss >> std::get_time(&t, format.c_str()); - return mktime(&t); - } -} static int GetTypes(HilogArgs context, const string& typesArgs, bool exclude = false) { uint16_t types = 0; -- Gitee From a9910a76310bebf79353ab94f275ae746260740d Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 29 Jun 2021 15:21:11 +0800 Subject: [PATCH 20/20] Exit when both forward/exclusive type/level/tag condition detected Signed-off-by: Wu Shangwei <2826256824@qq.com> --- services/hilogtool/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 1c4d5be..987c99c 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -258,6 +258,11 @@ int HilogEntry(int argc, char* argv[]) break; } } + if (context.types != 0 && context.noTypes != 0) { + std::cout << "Query condition on both types and excluded types is undefined." << std::endl; + std::cout << "Please remove types or excluded types condition, and try again." << std::endl; + exit(RET_FAIL); + } break; case 'L': indexLevel = optind - 1; @@ -282,6 +287,11 @@ int HilogEntry(int argc, char* argv[]) break; } } + if (context.levels != 0 && context.noLevels != 0) { + std::cout << "Query condition on both levels and excluded levels is undefined." << std::endl; + std::cout << "Please remove levels or excluded levels condition, and try again." << std::endl; + exit(RET_FAIL); + } break; case 'v': showFormat = HilogFormat(optarg); @@ -384,6 +394,11 @@ int HilogEntry(int argc, char* argv[]) break; } } + if (context.nTag != 0 && context.nNoTag != 0) { + std::cout << "Query condition on both tags and excluded tags is undefined." << std::endl; + std::cout << "Please remove tags or excluded tags condition, and try again." << std::endl; + exit(RET_FAIL); + } break; case 'b': context.logLevelArgs = optarg; -- Gitee