|
@@ -7,6 +7,8 @@
|
|
|
#include <map>
|
|
|
#include "log_define.h"
|
|
|
#include <SpBase.h>
|
|
|
+#include <chrono>
|
|
|
+#include <thread>
|
|
|
|
|
|
class StartupLog {
|
|
|
public:
|
|
@@ -55,6 +57,17 @@ private:
|
|
|
StartupLogManager();
|
|
|
~StartupLogManager();
|
|
|
std::map<int, StartupLog> logs_;
|
|
|
+ std::chrono::steady_clock::time_point m_lastUpdateTime;
|
|
|
+
|
|
|
+ void recordStartTime() {
|
|
|
+ m_lastUpdateTime = std::chrono::steady_clock::now();
|
|
|
+ }
|
|
|
+
|
|
|
+ bool isTimeExceeded() {
|
|
|
+ auto current_time = std::chrono::steady_clock::now();
|
|
|
+ auto duration = std::chrono::duration_cast<std::chrono::minutes>(current_time - m_lastUpdateTime);
|
|
|
+ return duration.count() >= 2;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
std::string GetCurrentTimeStr();
|
|
@@ -150,11 +163,35 @@ std::string StartupLog::toJSON() const {
|
|
|
return jsonReq;
|
|
|
}
|
|
|
|
|
|
-StartupLogManager::StartupLogManager() {}
|
|
|
+StartupLogManager::StartupLogManager()
|
|
|
+{
|
|
|
+ static std::thread checkTimeThread;
|
|
|
+ recordStartTime();
|
|
|
+ auto checkStartupEnd = [this] {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::seconds(5));
|
|
|
+ if (isTimeExceeded())
|
|
|
+ {
|
|
|
+ for (auto current : logs_)
|
|
|
+ {
|
|
|
+ std::string resultMsg = current.second.toJSON();
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)(resultMsg.c_str());
|
|
|
+ }
|
|
|
+ logs_.clear();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ if (!checkTimeThread.joinable()) {
|
|
|
+ checkTimeThread = std::thread(checkStartupEnd);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
StartupLogManager::~StartupLogManager() {}
|
|
|
|
|
|
void StartupLogManager::addLog(const std::string& module_entity, int idx) {
|
|
|
+ recordStartTime();
|
|
|
if (logs_.find(idx) == logs_.end()) {
|
|
|
logs_[idx] = StartupLog(module_entity, idx); // 直接拷贝 log 对象
|
|
|
} // 如果已存在,则忽略
|
|
@@ -176,6 +213,7 @@ bool StartupLogManager::checkLogExist(int idx)
|
|
|
}
|
|
|
|
|
|
void StartupLogManager::addStep(int idx, const StartupLog::Step& step) {
|
|
|
+ recordStartTime();
|
|
|
if (checkLogExist(idx))
|
|
|
{
|
|
|
StartupLog ¤t = getLog(idx);
|