fix(monitors): 补齐联网权限并释放采样端口引用

This commit is contained in:
2026-11-03 21:59:49 +08:00
parent cecd646376
commit ea4d0e7f23
7 changed files with 89 additions and 4 deletions
+4 -1
View File
@@ -5,10 +5,13 @@ nonisolated struct CPUMonitor {
private var previous: [[UInt32]]?
mutating func sample() -> CPUMetrics? {
// mach_host_self() returns a send right owned by this call, including failure paths.
let host = mach_host_self()
defer { mach_port_deallocate(mach_task_self_, host) }
var count: natural_t = 0
var info: processor_info_array_t?
var infoCount: mach_msg_type_number_t = 0
guard host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO,
guard host_processor_info(host, PROCESSOR_CPU_LOAD_INFO,
&count, &info, &infoCount) == KERN_SUCCESS,
let info else { previous = nil; return nil }
defer {