diff --git a/frameworks/native/hilog_input_socket_server.cpp b/frameworks/native/hilog_input_socket_server.cpp index c1ff936c8dd2f7077ef30e9dea1d3c1d67cb3d24..a4549dd22770737b6e92221733993c6d56bf12ea 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/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index e6e365f0c88870160a842d68021b93ecfd8a1bc6..e12a9193a7e40676159feff662595316bb790418 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/cmd_executor.cpp b/services/hilogd/cmd_executor.cpp index ddc72e4a66423b531037507834f0b1962a1827d1..86946fa825b9f5604506e370fa4c6548d90e6e61 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/include/log_compress.h b/services/hilogd/include/log_compress.h index 8dad94e7376ae51c8c615d36afbeeb1ce27aa567..7897845a1a66d9b6066d5f06be0212a6654a3bc4 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 695ee636a2a7409ba5883f45e9fac94dcf42b7f4..573920c56fcf9758bc5425587cc5d829f5855e70 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 d83606dc49e4aa44ddeb625b443675741d5932e4..0775b75ae2c87f2ec5f72f1c42f4a1cc89c0c1ad 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -114,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; @@ -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) { @@ -374,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 4865edd1a6cd579b10ba3026691a62a67019ce07..2405ed93cb755901bec5d8c3f1541b3a7efc81a9 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() diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 5e39e88ada5f2eb432c743059b8dabbfe91a12c2..167bf92b38485fba481670cf108e88b58fbe25e1 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/hilogd/main.cpp b/services/hilogd/main.cpp index df060f299a81f276d8ff1ad2b9bf4a7e5b0a7b65..0f4bad12ee778aed402be128947b73149bec2c34 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); }); diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index ac000494b02cdd4e402248eb977a60bef06d2fc2..a88aa4583fc0b46d80a89a5f02601a2837093efa 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"},