diff --git a/services/hilogd/include/log_buffer.h b/services/hilogd/include/log_buffer.h index 725507465e4022085cf9655fcaad58ee51cd76f1..6fd71d97feb4d3aa10badeb09e3b46a49491dc09 100644 --- a/services/hilogd/include/log_buffer.h +++ b/services/hilogd/include/log_buffer.h @@ -48,6 +48,7 @@ public: int32_t ClearStatisticInfoByDomain(uint32_t domain); void GetBufferLock(); void ReleaseBufferLock(); + void RemoveLogReader(std::shared_ptr reader); private: size_t size; size_t sizeByType[LOG_TYPE_MAX]; diff --git a/services/hilogd/include/log_persister.h b/services/hilogd/include/log_persister.h index 74dd580a493fa2077979a442afdf3a5c6b51784f..f2a15ba827e8b1680cab8a20f358409157bb37af 100644 --- a/services/hilogd/include/log_persister.h +++ b/services/hilogd/include/log_persister.h @@ -56,7 +56,7 @@ public: void FillInfo(LogPersistQueryResult *response); int MkDirPath(const char *p_cMkdir); bool writeUnCompressedBuffer(HilogData *data); - uint8_t getType() const; + uint8_t GetType() const; std::string getPath(); LogPersisterBuffer *buffer; diff --git a/services/hilogd/include/log_querier.h b/services/hilogd/include/log_querier.h index e5f804e4d8fd82613d149494734b356105adf633..5f89d8f86bfd55d540d1d6c5fc9cdcb4b457143b 100644 --- a/services/hilogd/include/log_querier.h +++ b/services/hilogd/include/log_querier.h @@ -27,7 +27,7 @@ public: int WriteData(LogQueryResponse& rsp, HilogData* data); int WriteData(HilogData* data); void NotifyForNewData(); - uint8_t getType() const; + uint8_t GetType() const; ~LogQuerier() = default; }; } // namespace HiviewDFX diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index acdfe5fa32127684052d0012c352044e75e0f833..0b767a5b5e99f59f896a3d3bf2528f42e1c843d2 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -31,6 +31,7 @@ class HilogBuffer; #define TYPE_QUERIER 1 #define TYPE_PERSISTER 2 +#define TYPE_CONTROL 3 using QueryCondition = struct QueryCondition { uint8_t nPid = 0; @@ -61,7 +62,7 @@ public: bool isNotified; LogReader(); - virtual ~LogReader(); + virtual ~LogReader() = default; bool GetReload() const; void SetReload(bool); virtual void NotifyForNewData() = 0; @@ -70,7 +71,7 @@ public: virtual int WriteData(HilogData* data) =0; void SetSendId(unsigned int value); void SetCmd(uint8_t value); - virtual uint8_t getType() const = 0; + virtual uint8_t GetType() const = 0; protected: unsigned int sendId = 1; uint8_t cmd = 0; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 7b63f57bfce99b5be14d2c631bb98fe0dead35a0..a3a12fd387c5e6d1c81cdd98e1eedf6aeccf5b87 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -415,5 +415,18 @@ void HilogBuffer::ReleaseBufferLock() { hilogBufferMutex.unlock(); } + +void HilogBuffer::RemoveLogReader(std::shared_ptr reader) +{ + logReaderListMutex.lock(); + const auto findIter = std::find_if(logReaderList.begin(), logReaderList.end(), + [reader](const std::weak_ptr& ptr0) { + return ptr0.lock() == reader; + }); + if (findIter != logReaderList.end()) { + logReaderList.erase(findIter); + } + logReaderListMutex.unlock(); +} } // namespace HiviewDFX } // namespace OHOS diff --git a/services/hilogd/log_collector.cpp b/services/hilogd/log_collector.cpp index 24290013a5b772112b7016b93e0b06817a071544..1a6531fbb88dad92b15e254aabb4c5823a80474c 100644 --- a/services/hilogd/log_collector.cpp +++ b/services/hilogd/log_collector.cpp @@ -87,7 +87,9 @@ size_t LogCollector::InsertLogToBuffer(const HilogMsg& msg) hilogBuffer->logReaderListMutex.lock_shared(); auto it = hilogBuffer->logReaderList.begin(); while (it != hilogBuffer->logReaderList.end()) { - (*it).lock()->NotifyForNewData(); + if ((*it).lock()->GetType() != TYPE_CONTROL) { + (*it).lock()->NotifyForNewData(); + } ++it; } hilogBuffer->logReaderListMutex.unlock_shared(); diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index be8a76013db79817a3375a4d2f1ad1c0c6260ab3..441fc3cd1447b2c2fc51024e7fd36a85dd7631d7 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -327,6 +327,7 @@ int LogPersister::ThreadFunc() hasExited = true; } cvhasExited.notify_all(); + hilogBuffer->RemoveLogReader(shared_from_this()); return 0; } @@ -408,7 +409,7 @@ string LogPersister::getPath() return path; } -uint8_t LogPersister::getType() const +uint8_t LogPersister::GetType() const { return TYPE_PERSISTER; } diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 70251cec56c02512c4c6b6c54061919f3de7a6b1..ea6d7eeb0430c9003bd72f9d8c6c320e4e70cf3e 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -488,6 +488,7 @@ void LogQuerier::LogQuerierThreadFunc(std::shared_ptr logReader) break; } } + hilogBuffer->RemoveLogReader(logReader); } LogQuerier::LogQuerier(std::unique_ptr handler, HilogBuffer* buffer) @@ -552,9 +553,16 @@ void LogQuerier::NotifyForNewData() } } -uint8_t LogQuerier::getType() const +uint8_t LogQuerier::GetType() const { - return TYPE_QUERIER; + switch (cmd) { + case LOG_QUERY_RESPONSE: + return TYPE_QUERIER; + case NEXT_RESPONSE: + return TYPE_QUERIER; + default: + return TYPE_CONTROL; + } } } // namespace HiviewDFX } // namespace OHOS diff --git a/services/hilogd/log_reader.cpp b/services/hilogd/log_reader.cpp index cad3aa62d69c829ab4d90934231c1f11533d658c..aa801c650d700e819474cac355545b7cd7144798 100644 --- a/services/hilogd/log_reader.cpp +++ b/services/hilogd/log_reader.cpp @@ -33,19 +33,6 @@ LogReader::LogReader() isNotified = false; } -LogReader::~LogReader() -{ - hilogBuffer->logReaderListMutex.lock(); - const auto findIter = std::find_if(hilogBuffer->logReaderList.begin(), hilogBuffer->logReaderList.end(), - [this](const std::weak_ptr& ptr0) { - return ptr0.lock() == weak_from_this().lock(); - }); - if (findIter != hilogBuffer->logReaderList.end()) { - hilogBuffer->logReaderList.erase(findIter); - } - hilogBuffer->logReaderListMutex.unlock(); -} - void LogReader::NotifyReload() { isReload = true; diff --git a/services/hilogtool/include/hilogtool.h b/services/hilogtool/include/hilogtool.h index b9138c43974d3919ca5c15ed9110d3308c2cf692..e2e8abfbf11242d13ce8a0401db82fe2ee7ce15c 100644 --- a/services/hilogtool/include/hilogtool.h +++ b/services/hilogtool/include/hilogtool.h @@ -31,12 +31,12 @@ typedef struct { uint16_t tailLines; std::string domain; // domain recv std::string tag; // tag recv - uint32_t pids[MAX_PIDS]; + std::string pids[MAX_PIDS]; std::string domains[MAX_DOMAINS]; // domains send std::string tags[MAX_TAGS]; // tags send uint16_t noTypes; uint16_t noLevels; - uint32_t noPids[MAX_PIDS]; + std::string noPids[MAX_PIDS]; std::string noDomains[MAX_DOMAINS]; std::string noTags[MAX_TAGS]; std::string regexArgs; diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 0f5415e01bb8a15c49ac56b1ec69f89fee330fba..eb585a965b64fb792cb7df835873c63513301a3e 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -160,10 +160,10 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte logQueryRequest.nDomain = context->nDomain; logQueryRequest.nTag = context->nTag; for (int i = 0; i < context->nPid; i++) { - logQueryRequest.pids[i] = context->pids[i]; + std::istringstream(context->pids[i]) >> std::dec >> logQueryRequest.pids[i]; } for (int i = 0; i < context->nDomain; i++) { - logQueryRequest.domains[i] = stoul(context->domains[i]); + std::istringstream(context->domains[i]) >> std::hex >> logQueryRequest.domains[i]; } for (int i = 0; i < context->nTag; i++) { if (context->tags[i].length() >= MAX_TAG_LEN) { @@ -180,7 +180,7 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte logQueryRequest.nNoDomain = context->nNoDomain; logQueryRequest.nNoTag = context->nNoTag; for (int i = 0; i < context->nNoPid; i++) { - logQueryRequest.noPids[i] = context->noPids[i]; + std::istringstream(context->noPids[i]) >> std::dec >> logQueryRequest.noPids[i]; } for (int i = 0; i < context->nNoDomain; i++) { std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index b2095c6810332784d7f591fb8a419ef453edf407..39de63e863c9562c12777bccf417546bfc0231f7 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -423,13 +423,13 @@ int HilogEntry(int argc, char* argv[]) vector v(sregex_token_iterator(pids.begin() + 1, pids.end(), delimiter, -1), sregex_token_iterator()); for (auto s: v) { - context.noPids[context.nNoPid++] = stoul(s); + context.noPids[context.nNoPid++] = s; } } else { vector v(sregex_token_iterator(pids.begin(), pids.end(), delimiter, -1), sregex_token_iterator()); for (auto s: v) { - context.pids[context.nPid++] = stoul(s); + context.pids[context.nPid++] = s; context.pidArgs += s + " "; } }