Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:mute: Remove verbose kernel exit stage logs https://github.com/siyuan-note/siyuan/issues/20191

Daniel0a81cb6fab3b
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 0371897d09..17486f7446 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -749,7 +749,7 @@ func markPendingWorkspaceExit() {
}
func closeKernel(force, setCurrentWorkspace bool, execInstallPkg int, recovery *util.WorkspaceExitState) (exitCode int, installPkgPath string) {
- diagnostic := util.WatchOperationWithTiming("exit kernel", "wait for exit lock")
+ diagnostic := util.WatchOperation("exit kernel", "wait for exit lock")
defer diagnostic.Finish()
exitLock.Lock()
defer exitLock.Unlock()
@@ -904,7 +904,7 @@ func ExitKernel() {
}
go func() {
- diagnostic := util.WatchOperationWithTiming("exit kernel servers", "wait for frontend exit event")
+ diagnostic := util.WatchOperation("exit kernel servers", "wait for frontend exit event")
time.Sleep(500 * time.Millisecond)
diagnostic.Stage("close HTTP servers")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
diff --git a/kernel/sql/database.go b/kernel/sql/database.go
index a8aa54e7f8..3385e7830f 100644
--- a/kernel/sql/database.go
+++ b/kernel/sql/database.go
@@ -1505,7 +1505,7 @@ func cleanupInvalidRefs(database *sql.DB) (err error) {
}
func CloseDatabase() {
- diagnostic := util.WatchOperationWithTiming("close databases", "close index queue")
+ diagnostic := util.WatchOperation("close databases", "close index queue")
defer diagnostic.Finish()
closeIndexQueue()
// 退出时删除所有已打开的加密 db 文件:加密索引可由 box.Index() 全量重建,
diff --git a/kernel/util/operation_watchdog.go b/kernel/util/operation_watchdog.go
index c159e6fc38..3f13a28886 100644
--- a/kernel/util/operation_watchdog.go
+++ b/kernel/util/operation_watchdog.go
@@ -17,14 +17,12 @@ const operationStallThreshold = 10 * time.Second
// OperationWatchdog 在操作仍未返回时记录阶段和调用栈,不取消操作、不改变数据写入顺序。
type OperationWatchdog struct {
- mu sync.Mutex
- name string
- stage string
- started time.Time
- stageStarted time.Time
- logTiming bool
- done bool
- timer *time.Timer
+ mu sync.Mutex
+ name string
+ stage string
+ started time.Time
+ done bool
+ timer *time.Timer
}
type operationStall struct {
@@ -41,19 +39,8 @@ func WatchOperation(name, stage string) *OperationWatchdog {
})
}
-// WatchOperationWithTiming 记录每个阶段的开始、耗时和操作总耗时,并保留慢操作调用栈。
-func WatchOperationWithTiming(name, stage string) *OperationWatchdog {
- w := WatchOperation(name, stage)
- w.mu.Lock()
- w.logTiming = true
- w.mu.Unlock()
- logging.LogInfof("operation [%s], stage [%s] started", name, stage)
- return w
-}
-
func watchOperation(name, stage string, threshold time.Duration, report func(operationStall)) *OperationWatchdog {
- now := time.Now()
- w := &OperationWatchdog{name: name, stage: stage, started: now, stageStarted: now}
+ w := &OperationWatchdog{name: name, stage: stage, started: time.Now()}
w.timer = time.AfterFunc(threshold, func() {
w.mu.Lock()
if w.done {
@@ -69,15 +56,8 @@ func watchOperation(name, stage string, threshold time.Duration, report func(ope
func (w *OperationWatchdog) Stage(stage string) {
w.mu.Lock()
- previous, elapsed, total := w.stage, time.Since(w.stageStarted), time.Since(w.started)
- logTiming := w.logTiming
w.stage = stage
- w.stageStarted = time.Now()
w.mu.Unlock()
- if logTiming {
- logging.LogInfof("operation [%s], stage [%s] finished, elapsed [%s], total [%s]", w.name, previous, elapsed, total)
- logging.LogInfof("operation [%s], stage [%s] started", w.name, stage)
- }
}
func (w *OperationWatchdog) Finish() {
@@ -85,12 +65,7 @@ func (w *OperationWatchdog) Finish() {
w.done = true
w.timer.Stop()
elapsed, stage := time.Since(w.started), w.stage
- stageElapsed, logTiming := time.Since(w.stageStarted), w.logTiming
w.mu.Unlock()
- if logTiming {
- logging.LogInfof("operation [%s], stage [%s] finished, elapsed [%s], total [%s]", w.name, stage, stageElapsed, elapsed)
- return
- }
if elapsed >= operationStallThreshold {
logging.LogInfof("slow operation finished [%s], stage [%s], elapsed [%s]", w.name, stage, elapsed)
}