From 86f0b4bd20cdec86dfb5bdb7978d1f6ff4af111a Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Fri, 14 Aug 2026 22:41:54 +0800
Subject: [PATCH] [verified] feat: export performance diagnostics

---
 C1.source/Sources/Aligner/QuickSwitchSessionController.swift |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/C1.source/Sources/Aligner/QuickSwitchSessionController.swift b/C1.source/Sources/Aligner/QuickSwitchSessionController.swift
index 8122f9a..79515d9 100644
--- a/C1.source/Sources/Aligner/QuickSwitchSessionController.swift
+++ b/C1.source/Sources/Aligner/QuickSwitchSessionController.swift
@@ -426,6 +426,40 @@
         ]
     }
 
+    func performanceDiagnosticSummary() -> [String: Any] {
+        let applications = currentSnapshot?.appGroups.map { group in
+            [
+                "name": group.app.name,
+                "bundleIdentifier": group.app.bundleIdentifier,
+                "processIdentifier": group.app.processIdentifier ?? NSNull(),
+                "windowCount": group.windows.count,
+                "minimizedWindowCount": group.windows.filter { $0.window.isMinimized }.count,
+                "fullscreenWindowCount": group.windows.filter { $0.window.isFullscreen }.count
+            ] as [String: Any]
+        } ?? []
+
+        return [
+            "snapshotLoaded": currentSnapshot != nil,
+            "snapshotError": lastSnapshotError ?? NSNull(),
+            "quickSwitchVisible": isVisible,
+            "displayCount": currentSnapshot?.displays.count ?? 0,
+            "spaceCount": currentSnapshot?.displays.flatMap(\.spaces).count ?? 0,
+            "applicationCount": applications.count,
+            "windowCount": currentSnapshot?.appGroups.flatMap(\.windows).count ?? 0,
+            "applications": applications,
+            "timingsMilliseconds": [
+                "overlayOpen": overlayOpenElapsedMilliseconds ?? NSNull(),
+                "snapshotStart": snapshotStartElapsedMilliseconds ?? NSNull(),
+                "snapshot": snapshotDurationMilliseconds ?? NSNull(),
+                "lastActivation": lastActivationDurationMilliseconds ?? NSNull()
+            ] as [String: Any],
+            "snapshotRanOnMainThread": snapshotRanOnMainThread ?? NSNull(),
+            "lastActivationResult": lastActivationResult.map(Self.activationResultString) ?? NSNull(),
+            "lastActivationError": lastActivationError ?? NSNull(),
+            "lastDismissReason": lastDismissReason.map(Self.dismissReasonString) ?? NSNull()
+        ]
+    }
+
     func prepareLifecycleRun(targetCycles: Int) {
         lifecycleTargetCycles = max(0, targetCycles)
         lifecycleCompletedCycles = 0

--
Gitblit v1.9.3