mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
- fix incorrect and duplicate top processes in Memory module (improve regex) (#169)
- remove logs from GPU reader
This commit is contained in:
@@ -74,7 +74,7 @@ internal class CapacityReader: Reader<DiskList> {
|
||||
}
|
||||
|
||||
// https://opensource.apple.com/source/bless/bless-152/libbless/APFS/BLAPFSUtilities.c.auto.html
|
||||
public func getDeviceIOParent(_ obj: io_registry_entry_t, fileSystem: String = "") -> io_registry_entry_t? {
|
||||
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 {
|
||||
@@ -160,7 +160,7 @@ internal class CapacityReader: Reader<DiskList> {
|
||||
d.free = freeDiskSpaceInBytes(d.path!.absoluteString)
|
||||
}
|
||||
|
||||
if let parent = self.getDeviceIOParent(DADiskCopyIOMedia(disk), fileSystem: d.fileSystem) {
|
||||
if let parent = self.getDeviceIOParent(DADiskCopyIOMedia(disk)) {
|
||||
d.parent = parent
|
||||
self.driveStats(parent, &d.stats)
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ internal class InfoReader: Reader<GPUs> {
|
||||
}
|
||||
let devices = PCIdevices.filter{ $0.object(forKey: "IOName") as? String == "display" }
|
||||
|
||||
print("Found \(devices.count) devices", to: &Log.log)
|
||||
|
||||
devices.forEach { (dict: NSDictionary) in
|
||||
guard let deviceID = dict["device-id"] as? Data, let vendorID = dict["vendor-id"] as? Data else {
|
||||
print("device-id or vendor-id not found", to: &Log.log)
|
||||
@@ -60,15 +58,11 @@ internal class InfoReader: Reader<GPUs> {
|
||||
self.devices[i].used = false
|
||||
}
|
||||
|
||||
print("------------", "read()", "------------", to: &Log.log)
|
||||
print("Found \(accelerators.count) accelerators", to: &Log.log)
|
||||
|
||||
accelerators.forEach { (accelerator: NSDictionary) in
|
||||
guard let IOClass = accelerator.object(forKey: "IOClass") as? String else {
|
||||
print("IOClass not found", to: &Log.log)
|
||||
return
|
||||
}
|
||||
print("Processing \(IOClass) accelerator", to: &Log.log)
|
||||
|
||||
guard let stats = accelerator["PerformanceStatistics"] as? [String:Any] else {
|
||||
print("PerformanceStatistics not found", to: &Log.log)
|
||||
@@ -127,12 +121,8 @@ internal class InfoReader: Reader<GPUs> {
|
||||
|
||||
self.gpus.list[idx].utilization = utilization == 0 ? 0 : Double(utilization)/100
|
||||
self.gpus.list[idx].temperature = temperature
|
||||
|
||||
print("\(model): utilization=\(utilization), temperature=\(temperature)", to: &Log.log)
|
||||
}
|
||||
|
||||
print("Callback \(self.gpus.list.count) GPUs", to: &Log.log)
|
||||
|
||||
self.gpus.list.sort{ !$0.state && $1.state }
|
||||
self.callback(self.gpus)
|
||||
}
|
||||
|
||||
@@ -128,20 +128,20 @@ public class ProcessReader: Reader<[TopProcess]> {
|
||||
|
||||
var processes: [TopProcess] = []
|
||||
output.enumerateLines { (line, _) -> () in
|
||||
if line.matches("^\\d+ + .+ +\\d+.\\d[M\\+\\-]+ *$") {
|
||||
var str = line.trimmingCharacters(in: .whitespaces)
|
||||
let pidString = str.findAndCrop(pattern: "^\\d+")
|
||||
let usageString = str.findAndCrop(pattern: " [0-9]+M(\\+|\\-)*$")
|
||||
var command = str.trimmingCharacters(in: .whitespaces)
|
||||
if line.matches("^\\d+ +.* +\\d+[A-Z]* *$") {
|
||||
let str = line.trimmingCharacters(in: .whitespaces)
|
||||
let pidString = str.prefix(6)
|
||||
let startIndex = str.index(str.startIndex, offsetBy: 6)
|
||||
let endIndex = str.index(str.startIndex, offsetBy: 22)
|
||||
var command = String(str[startIndex...endIndex])
|
||||
let usageString = str.suffix(5)
|
||||
|
||||
if let regex = try? NSRegularExpression(pattern: " (\\+|\\-)*$", options: .caseInsensitive) {
|
||||
command = regex.stringByReplacingMatches(in: command, options: [], range: NSRange(location: 0, length: command.count), withTemplate: "")
|
||||
}
|
||||
|
||||
let pid = Int(pidString) ?? 0
|
||||
guard let usage = Double(usageString.filter("01234567890.".contains)) else {
|
||||
return
|
||||
}
|
||||
let pid = Int(pidString.filter("01234567890.".contains)) ?? 0
|
||||
let usage = Double(usageString.filter("01234567890.".contains)) ?? 0
|
||||
|
||||
var name: String? = nil
|
||||
var icon: NSImage? = nil
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>164</string>
|
||||
<string>171</string>
|
||||
<key>Description</key>
|
||||
<string>Simple macOS system monitor in your menu bar</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
||||
Reference in New Issue
Block a user