Add performance logging and background diagnostics

Performance Logging (Developer settings) logs a resource sample every 5s
in the foreground and background: CPU by area and thread, wakeups, GPU,
memory, disk, activity counters as rates (mpv property updates, player
time publishes, renders, saves, network, images, CloudKit events, log
entries, main run-loop wakeups), SwiftUI body evaluations of the player
views, and app/player/battery context. Each foreground/background
transition logs a summary of the period. MetricKit metrics and
diagnostics (CPU exceptions, hangs) are logged whenever logging is on.

Background diagnostics (iOS) log lifecycle, audio session and power
events with an app/player/render snapshot and a heartbeat that detects
suspension gaps and main-thread stalls. Logs are persisted per session
in Caches/Logs and the previous session is included in exports, so logs
survive the app being swiped away.
This commit is contained in:
Arkadiusz Fal
2026-10-24 19:36:51 +02:00
parent 21a6238a16
commit 9412ca916c
28 changed files with 1354 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ struct DeveloperSettingsView: View {
@Environment(\.appEnvironment) private var appEnvironment
@Bindable private var loggingService = LoggingService.shared
@State private var loggingEnabled = LoggingService.shared.isEnabled
@State private var performanceLoggingEnabled = PerformanceMonitor.shared.isEnabled
// Data management state
@State private var showingDeduplicateConfirmation = false
@@ -137,6 +138,13 @@ struct DeveloperSettingsView: View {
)) {
Label(String(localized: "settings.advanced.debug.verboseRemote"), systemImage: "antenna.radiowaves.left.and.right")
}
Toggle(isOn: $performanceLoggingEnabled) {
Label(String(localized: "settings.advanced.debug.performanceLogging"), systemImage: "gauge.with.dots.needle.67percent")
}
.onChange(of: performanceLoggingEnabled) { _, newValue in
PerformanceMonitor.shared.setEnabled(newValue)
}
}
}
}