From a141d1719a51a05f66714162e2feda697bf51bb1 Mon Sep 17 00:00:00 2001 From: aajwy <13051180828@163.com> Date: Wed, 27 Oct 2021 01:28:30 +0000 Subject: [PATCH 1/3] set name of threads Signed-off-by: aajwy <13051180828@163.com> --- frameworks/native/hilog_input_socket_server.cpp | 3 ++- services/hilogd/cmd_executor.cpp | 3 +++ services/hilogd/log_persister.cpp | 2 ++ services/hilogd/main.cpp | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frameworks/native/hilog_input_socket_server.cpp b/frameworks/native/hilog_input_socket_server.cpp index c1ff936..a4549dd 100644 --- a/frameworks/native/hilog_input_socket_server.cpp +++ b/frameworks/native/hilog_input_socket_server.cpp @@ -14,7 +14,7 @@ */ #include "hilog_input_socket_server.h" - +#include #include namespace OHOS { @@ -28,6 +28,7 @@ int HilogInputSocketServer::RunServingThread() int HilogInputSocketServer::ServingThread() { + prctl(PR_SET_NAME, "hilogd.server"); int ret; int length; char *data = nullptr; diff --git a/services/hilogd/cmd_executor.cpp b/services/hilogd/cmd_executor.cpp index ddc72e4..86946fa 100644 --- a/services/hilogd/cmd_executor.cpp +++ b/services/hilogd/cmd_executor.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace OHOS { namespace HiviewDFX { @@ -28,8 +29,10 @@ const int MAX_WRITE_LOG_TASK = 100; using namespace std; HilogBuffer* CmdExecutor::hilogBuffer = nullptr; + void LogQuerierMonitor(std::unique_ptr handler) { + prctl(PR_SET_NAME, "hilogd.query"); std::shared_ptr logQuerier = std::make_shared(std::move(handler), CmdExecutor::getHilogBuffer()); logQuerier->LogQuerierThreadFunc(logQuerier); diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index d83606d..9b3413a 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -286,6 +287,7 @@ inline void LogPersister::WriteFile() int LogPersister::ThreadFunc() { + prctl(PR_SET_NAME, "hilogd.pst"); std::thread::id tid = std::this_thread::get_id(); cout << __func__ << " " << tid << endl; while (true) { diff --git a/services/hilogd/main.cpp b/services/hilogd/main.cpp index df060f2..0f4bad1 100644 --- a/services/hilogd/main.cpp +++ b/services/hilogd/main.cpp @@ -14,6 +14,7 @@ */ #include #include +#include #include #include #include @@ -84,6 +85,7 @@ int HilogdEntry(int argc, char* argv[]) } std::thread startupCheckThread([&hilogBuffer]() { + prctl(PR_SET_NAME, "hilogd.pst_res"); std::shared_ptr logQuerier = std::make_shared(nullptr, &hilogBuffer); logQuerier->RestorePersistJobs(hilogBuffer); }); -- Gitee From ae9fb36029bd583c56e0368de879a05b28c0cad5 Mon Sep 17 00:00:00 2001 From: aajwy <13051180828@163.com> Date: Thu, 28 Oct 2021 06:07:29 +0000 Subject: [PATCH 2/3] persist multiple Signed-off-by: aajwy <13051180828@163.com> --- frameworks/native/include/hilog_common.h | 1 + services/hilogd/log_persister.cpp | 2 +- services/hilogd/log_querier.cpp | 6 ++++++ services/hilogtool/log_display.cpp | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index e6e365f..e12a919 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -122,5 +122,6 @@ typedef enum { ERR_FLOWCTRL_SWITCH_VALUE_INVALID = -29, ERR_BUFF_SIZE_INVALID = -30, ERR_COMMAND_INVALID = -31, + ERR_LOG_PERSIST_TASK_FAIL = -32, } ErrorCode; #endif /* HILOG_COMMON_H */ diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index 9b3413a..5f9f1eb 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -115,7 +115,7 @@ int LogPersister::Init() } } if (hit) { - return ERR_LOG_PERSIST_FILE_PATH_INVALID; + return ERR_LOG_PERSIST_TASK_FAIL; } if (InitCompress() == RET_FAIL) { return ERR_LOG_PERSIST_COMPRESS_INIT_FAIL; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 5e39e88..167bf92 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -100,11 +100,17 @@ int JobLauncher(const LogPersistStartMsg& pMsg, const HilogBuffer& buffer, bool int rotatorRes = rotator->Init(); int saveInfoRes = rotator->SaveInfo(pMsg, persister->queryCondition); int persistRes = persister->Init(); + if (persistRes == ERR_LOG_PERSIST_TASK_FAIL) { + cout << "Log persist task is existed!" << endl; + persister.reset(); + return persistRes; + } if (persistRes != 0) { cout << "LogPersister failed to initialize!" << endl; persister.reset(); return persistRes; } + if (rotatorRes != 0) { cout << "Failed to open info file!" << endl; persister.reset(); diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index ac00049..a88aa45 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -55,6 +55,7 @@ unordered_map errorMsg {ERR_LOG_PERSIST_FILE_OPEN_FAIL, "Log persist open file failed"}, {ERR_LOG_PERSIST_MMAP_FAIL, "Log persist mmap failed"}, {ERR_LOG_PERSIST_JOBID_FAIL, "Log persist jobid not exist"}, + {ERR_LOG_PERSIST_TASK_FAIL, "Log persist task is existed"}, {ERR_DOMAIN_INVALID, "Invalid domain, domain should not be more than 0 and less than " + to_string(DOMAIN_MAX_SCOPE)}, {ERR_MEM_ALLOC_FAIL, "Alloc memory failed"}, -- Gitee From 8cfbb6f9cf416c93428b9794158d714e0cf059a9 Mon Sep 17 00:00:00 2001 From: aajwy <13051180828@163.com> Date: Thu, 11 Nov 2021 07:44:09 +0000 Subject: [PATCH 3/3] Avoid file operation in destructor Signed-off-by: aajwy <13051180828@163.com> --- services/hilogd/include/log_compress.h | 2 +- services/hilogd/include/log_persister_rotator.h | 1 + services/hilogd/log_persister.cpp | 1 + services/hilogd/log_persister_rotator.cpp | 6 +++++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/hilogd/include/log_compress.h b/services/hilogd/include/log_compress.h index 8dad94e..7897845 100644 --- a/services/hilogd/include/log_compress.h +++ b/services/hilogd/include/log_compress.h @@ -27,8 +27,8 @@ namespace OHOS { namespace HiviewDFX { typedef struct { - uint32_t offset; char content[MAX_PERSISTER_BUFFER_SIZE]; + uint32_t offset; } LogPersisterBuffer; const uint16_t CHUNK = 16384; diff --git a/services/hilogd/include/log_persister_rotator.h b/services/hilogd/include/log_persister_rotator.h index 695ee63..573920c 100644 --- a/services/hilogd/include/log_persister_rotator.h +++ b/services/hilogd/include/log_persister_rotator.h @@ -47,6 +47,7 @@ public: void WriteRecoveryInfo(); void SetRestore(bool flag); bool GetRestore(); + void RemoveInfo(); protected: void InternalRotate(); uint32_t fileNum; diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index 5f9f1eb..0775b75 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -376,6 +376,7 @@ void LogPersister::Exit() if (!isExited()) { cvhasExited.wait(lk); } + rotator->RemoveInfo(); delete rotator; this->rotator = nullptr; munmap(buffer, MAX_PERSISTER_BUFFER_SIZE); diff --git a/services/hilogd/log_persister_rotator.cpp b/services/hilogd/log_persister_rotator.cpp index 4865edd..2405ed9 100644 --- a/services/hilogd/log_persister_rotator.cpp +++ b/services/hilogd/log_persister_rotator.cpp @@ -48,12 +48,16 @@ LogPersisterRotator::LogPersisterRotator(string path, uint32_t fileSize, uint32_ memset_s(&info, sizeof(info), 0, sizeof(info)); } +void LogPersisterRotator::RemoveInfo() +{ + remove(infoPath.c_str()); +} + LogPersisterRotator::~LogPersisterRotator() { if (fdinfo != nullptr) { fclose(fdinfo); } - remove(infoPath.c_str()); } int LogPersisterRotator::Init() -- Gitee