An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:loud_sound: Add runtime information timing diagnostics https://github.com/siyuan-note/siyuan/issues/20003
Daniel5aa34f66a210
diff --git a/app/src/config/tabs/aboutTab.ts b/app/src/config/tabs/aboutTab.tsindex 58a8e242d9..e824aba10c 100644--- a/app/src/config/tabs/aboutTab.ts+++ b/app/src/config/tabs/aboutTab.ts@@ -9,6 +9,9 @@ import {openChangelog} from "../../boot/openChangelog";import {writeClipboardData} from "../../protyle/util/compatibility";import {showMessage} from "../../dialog/message";import {Dialog} from "../../dialog";+/// #if !BROWSER+import {ipcRenderer} from "electron";+/// #endifconst registerAboutVersionGroup = (tab: SettingTabBuilder) => {const group = tab.group("version", "");@@ -104,8 +107,25 @@ const genAboutVersionActions = (showCheckUpdate: boolean) => `<div class="fn__fl</div>`;const mountAboutVersionSlot = (root: HTMLElement) => {+ let runtimeInfoClicks = 0;root.querySelector("#viewRuntimeInfoBtn")?.addEventListener("click", () => {+ const started = performance.now();+ const click = ++runtimeInfoClicks;+ const request = Date.now();+ const logStage = (stage: string) => {+ const msg = `runtime info frontend [request=${request}, click=${click}, stage=${stage}, ` ++ `total=${Math.round(performance.now() - started)}ms, visibility=${document.visibilityState}]`;+ /// #if !BROWSER+ ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "writeLog", msg});+ /// #else+ console.info(msg);+ /// #endif+ };+ logStage("start");+ let received = false;fetchPost("/api/system/getRuntimeInfo", {}, (response) => {+ received = true;+ logStage("response");const lines = [response.data.text, `Frontend: ${Constants.SIYUAN_VERSION}`, `User agent: ${navigator.userAgent}`];/// #if !BROWSERif (typeof process !== "undefined" && process.versions?.electron) {@@ -133,6 +153,13 @@ const mountAboutVersionSlot = (root: HTMLElement) => {showMessage(window.siyuan.languages.copied);dialog.destroy();});+ logStage("dialog_created");+ // 等待弹窗开启延时后的绘制帧,区分接口等待与渲染线程的调度延迟。+ setTimeout(() => {+ requestAnimationFrame(() => logStage("animation_frame"));+ }, Constants.TIMEOUT_OPENDIALOG);+ }).finally(() => {+ if (!received) logStage("request_failed");});});root.querySelector("#viewChangelogBtn")?.addEventListener("click", () => {diff --git a/kernel/util/runtime_info.go b/kernel/util/runtime_info.goindex 72d8c50fd8..34741eae99 100644--- a/kernel/util/runtime_info.go+++ b/kernel/util/runtime_info.go@@ -7,14 +7,30 @@ import ("runtime""runtime/debug""strings"+ "time""github.com/shirou/gopsutil/v4/host""github.com/shirou/gopsutil/v4/mem""github.com/shirou/gopsutil/v4/process"+ "github.com/siyuan-note/logging")// RuntimeInfo 采集当前内核的运行信息,使用统一诊断字段,避免包含路径、主机名和账户信息。func RuntimeInfo(ctx context.Context) string {+ started := time.Now()+ requestID := started.UnixNano()+ stageStarted := started+ logStage := func(stage string) {+ now := time.Now()+ logging.LogInfof("runtime info [request=%d, stage=%s, elapsed=%dms, total=%dms]",+ requestID, stage, now.Sub(stageStarted).Milliseconds(), now.Sub(started).Milliseconds())+ stageStarted = time.Now()+ }+ logging.LogInfof("runtime info [request=%d, stage=start]", requestID)+ defer func() {+ logging.LogInfof("runtime info [request=%d, stage=complete, total=%dms, canceled=%t]",+ requestID, time.Since(started).Milliseconds(), ctx.Err() != nil)+ }()var result strings.Builderfmt.Fprintf(&result, "SiYuan %s\nKernel: %s %s/%s\n", Ver, runtime.Version(), runtime.GOOS, runtime.GOARCH)if info, ok := debug.ReadBuildInfo(); ok {@@ -29,6 +45,7 @@ func RuntimeInfo(ctx context.Context) string {}}}+ logStage("build_info")platform := MobileOSVerif platform == "" {name, _, version, err := host.PlatformInformationWithContext(ctx)@@ -39,6 +56,7 @@ func RuntimeInfo(ctx context.Context) string {if platform == "" {platform = runtime.GOOS}+ logStage("platform")fmt.Fprintf(&result, "Kernel OS: %s\nContainer: %s\nRuntime mode: %s\nRead only: %t\nDatabase version: %s\nCPU logical cores: %d\n",platform, Container, Mode, ReadOnly, DatabaseVer, runtime.NumCPU())if memory, err := mem.VirtualMemoryWithContext(ctx); err == nil {@@ -46,6 +64,7 @@ func RuntimeInfo(ctx context.Context) string {} else {result.WriteString("System memory: unknown\n")}+ logStage("system_memory")if proc, err := process.NewProcessWithContext(ctx, int32(os.Getpid())); err == nil {if memory, err := proc.MemoryInfoWithContext(ctx); err == nil {fmt.Fprintf(&result, "Kernel memory (RSS): %.1f MiB\n", float64(memory.RSS)/(1<<20))@@ -55,13 +74,16 @@ func RuntimeInfo(ctx context.Context) string {} else {result.WriteString("Kernel memory (RSS): unknown\n")}+ logStage("process_memory")var memory runtime.MemStatsruntime.ReadMemStats(&memory)fmt.Fprintf(&result, "Kernel Go heap: %.1f MiB in use, %.1f MiB reserved\n", float64(memory.HeapAlloc)/(1<<20), float64(memory.HeapSys)/(1<<20))+ logStage("go_heap")driveType := ""if !IsMobileContainer() {driveType = detectWorkspaceDriveType()}+ logStage("workspace_storage")if driveType == "" {driveType = "unknown"}