fix(monitors): 补齐联网权限并释放采样端口引用
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user