Dolphin3.0-CoreML / examples /ios /DolphinCoreMLTestApp /Sources /SystemTools /SystemResourceSnapshotProvider.swift
| import Darwin | |
| import Foundation | |
| struct SystemResourceSnapshotProvider: Sendable { | |
| func snapshot() -> AssistantResourceSnapshot { | |
| let processInfo = ProcessInfo.processInfo | |
| return AssistantResourceSnapshot( | |
| thermalLevel: thermalLevel(processInfo.thermalState), | |
| lowPowerModeEnabled: processInfo.isLowPowerModeEnabled, | |
| availableMemoryBytes: UInt64(os_proc_available_memory()) | |
| ) | |
| } | |
| private func thermalLevel( | |
| _ state: ProcessInfo.ThermalState | |
| ) -> AssistantThermalLevel { | |
| switch state { | |
| case .nominal: | |
| return .nominal | |
| case .fair: | |
| return .fair | |
| case .serious: | |
| return .serious | |
| case .critical: | |
| return .critical | |
| @unknown default: | |
| return .unknown | |
| } | |
| } | |
| } | |