mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
- fix disk read/write stats on Big Sur (#175)
This commit is contained in:
@@ -73,27 +73,6 @@ internal class CapacityReader: Reader<DiskList> {
|
||||
self.callback(self.disks)
|
||||
}
|
||||
|
||||
// https://opensource.apple.com/source/bless/bless-152/libbless/APFS/BLAPFSUtilities.c.auto.html
|
||||
public func getDeviceIOParent(_ obj: io_registry_entry_t) -> io_registry_entry_t? {
|
||||
var parent: io_registry_entry_t = 0
|
||||
|
||||
if IORegistryEntryGetParentEntry(obj, kIOServicePlane, &parent) != KERN_SUCCESS {
|
||||
return nil
|
||||
}
|
||||
|
||||
if IORegistryEntryGetParentEntry(parent, kIOServicePlane, &parent) != KERN_SUCCESS {
|
||||
IOObjectRelease(parent)
|
||||
return nil
|
||||
}
|
||||
|
||||
if IORegistryEntryGetParentEntry(parent, kIOServicePlane, &parent) != KERN_SUCCESS {
|
||||
IOObjectRelease(parent)
|
||||
return nil
|
||||
}
|
||||
|
||||
return parent
|
||||
}
|
||||
|
||||
private func driveDetails(_ disk: DADisk, removableState: Bool) -> drive? {
|
||||
var d: drive = drive()
|
||||
|
||||
@@ -160,7 +139,8 @@ internal class CapacityReader: Reader<DiskList> {
|
||||
d.free = freeDiskSpaceInBytes(d.path!.absoluteString)
|
||||
}
|
||||
|
||||
if let parent = self.getDeviceIOParent(DADiskCopyIOMedia(disk)) {
|
||||
let partitionLevel = d.BSDName.filter { "0"..."9" ~= $0 }.count
|
||||
if let parent = self.getDeviceIOParent(DADiskCopyIOMedia(disk), level: Int(partitionLevel)) {
|
||||
d.parent = parent
|
||||
self.driveStats(parent, &d.stats)
|
||||
}
|
||||
@@ -168,6 +148,24 @@ internal class CapacityReader: Reader<DiskList> {
|
||||
return d
|
||||
}
|
||||
|
||||
// https://opensource.apple.com/source/bless/bless-152/libbless/APFS/BLAPFSUtilities.c.auto.html
|
||||
public func getDeviceIOParent(_ obj: io_registry_entry_t, level: Int) -> io_registry_entry_t? {
|
||||
var parent: io_registry_entry_t = 0
|
||||
|
||||
if IORegistryEntryGetParentEntry(obj, kIOServicePlane, &parent) != KERN_SUCCESS {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _ in 1...level {
|
||||
if IORegistryEntryGetParentEntry(parent, kIOServicePlane, &parent) != KERN_SUCCESS {
|
||||
IOObjectRelease(parent)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return parent
|
||||
}
|
||||
|
||||
private func driveStats(_ entry: io_registry_entry_t, _ diskStats: UnsafeMutablePointer<stats?>) {
|
||||
guard let props = getIOProperties(entry) else {
|
||||
return
|
||||
|
||||
@@ -52,7 +52,7 @@ internal class Settings: NSView, Settings_v {
|
||||
self.subviews.forEach{ $0.removeFromSuperview() }
|
||||
|
||||
let rowHeight: CGFloat = 30
|
||||
let num: CGFloat = widget != .speed ? 3 : 1
|
||||
let num: CGFloat = widget != .speed ? 3 : 2
|
||||
|
||||
if widget != .speed {
|
||||
self.addSubview(SelectTitleRow(
|
||||
@@ -62,10 +62,10 @@ internal class Settings: NSView, Settings_v {
|
||||
items: ReaderUpdateIntervals.map{ "\($0) sec" },
|
||||
selected: "\(self.updateIntervalValue) sec"
|
||||
))
|
||||
|
||||
self.addDiskSelector()
|
||||
}
|
||||
|
||||
self.addDiskSelector()
|
||||
|
||||
self.addSubview(ToggleTitleRow(
|
||||
frame: NSRect(x: Constants.Settings.margin, y: Constants.Settings.margin + (rowHeight + Constants.Settings.margin) * 0, width: self.frame.width - (Constants.Settings.margin*2), height: rowHeight),
|
||||
title: LocalizedString("Show removable disks"),
|
||||
|
||||
Reference in New Issue
Block a user