fix: fix periodic freeze in print stack
This commit is contained in:
@@ -16,6 +16,12 @@ extern "C" {
|
||||
using namespace print;
|
||||
|
||||
static constexpr bool ENABLE_BACKGROUND_PROBE = false;
|
||||
static constexpr uint64_t DAEMON_STATE_HEARTBEAT_MS = 15000;
|
||||
|
||||
static char g_last_state_phase[32] = {};
|
||||
static char g_last_state_subject[128] = {};
|
||||
static char g_last_state_detail[256] = {};
|
||||
static uint64_t g_last_state_write_ms = 0;
|
||||
|
||||
enum class ClaimResult {
|
||||
None,
|
||||
@@ -25,6 +31,23 @@ enum class ClaimResult {
|
||||
|
||||
static void write_daemon_state(const char* phase, const char* subject = nullptr,
|
||||
const char* detail = nullptr) {
|
||||
const char* safe_phase = phase ? phase : "";
|
||||
const char* safe_subject = subject ? subject : "";
|
||||
const char* safe_detail = detail ? detail : "";
|
||||
uint64_t now_ms = montauk::get_milliseconds();
|
||||
|
||||
if (g_last_state_write_ms != 0
|
||||
&& strcmp(g_last_state_phase, safe_phase) == 0
|
||||
&& strcmp(g_last_state_subject, safe_subject) == 0
|
||||
&& strcmp(g_last_state_detail, safe_detail) == 0
|
||||
&& now_ms - g_last_state_write_ms < DAEMON_STATE_HEARTBEAT_MS)
|
||||
return;
|
||||
|
||||
safe_copy(g_last_state_phase, sizeof(g_last_state_phase), safe_phase);
|
||||
safe_copy(g_last_state_subject, sizeof(g_last_state_subject), safe_subject);
|
||||
safe_copy(g_last_state_detail, sizeof(g_last_state_detail), safe_detail);
|
||||
g_last_state_write_ms = now_ms;
|
||||
|
||||
char now[32] = {};
|
||||
now_string(now, sizeof(now));
|
||||
|
||||
@@ -33,9 +56,9 @@ static void write_daemon_state(const char* phase, const char* subject = nullptr,
|
||||
"time=%s\npid=%d\nphase=%s\nsubject=%s\ndetail=%s\n",
|
||||
now,
|
||||
montauk::getpid(),
|
||||
phase ? phase : "",
|
||||
subject ? subject : "",
|
||||
detail ? detail : "");
|
||||
safe_phase,
|
||||
safe_subject,
|
||||
safe_detail);
|
||||
if (n < 0) return;
|
||||
write_text_file_atomic(SPOOL_DAEMON_STATE_PATH, buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user