mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: adjusted RAM top process parser (#1029)
This commit is contained in:
@@ -156,8 +156,19 @@ public class ProcessReader: Reader<[TopProcess]> {
|
||||
static public func parseProcess(_ raw: String) -> TopProcess {
|
||||
let str = raw.trimmingCharacters(in: .whitespaces)
|
||||
let pidString = str.find(pattern: "^\\d+")
|
||||
let usageString = str.suffix(6)
|
||||
var command = str.replacingOccurrences(of: usageString, with: "")
|
||||
|
||||
var arr = str.replacingOccurrences(of: pidString, with: "").split(separator: " ")
|
||||
if arr.first == "*" {
|
||||
arr.removeFirst()
|
||||
}
|
||||
|
||||
var usageString = str.suffix(6)
|
||||
if let lastElement = arr.last {
|
||||
usageString = lastElement
|
||||
arr.removeLast()
|
||||
}
|
||||
|
||||
var command = arr.joined(separator: " ")
|
||||
.replacingOccurrences(of: pidString, with: "")
|
||||
.trimmingCharacters(in: .whitespaces)
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class RAM: XCTestCase {
|
||||
|
||||
process = ProcessReader.parseProcess("359 NotificationCent 62M")
|
||||
XCTAssertEqual(process.pid, 359)
|
||||
XCTAssertEqual(process.command, "NotificationCe")
|
||||
XCTAssertEqual(process.command, "NotificationCent")
|
||||
XCTAssertEqual(process.usage, 62 * Double(1024 * 1024))
|
||||
|
||||
process = ProcessReader.parseProcess("623 SafariCloudHisto 1608K")
|
||||
@@ -48,6 +48,11 @@ class RAM: XCTestCase {
|
||||
XCTAssertEqual(process.pid, 329)
|
||||
XCTAssertEqual(process.command, "Finder")
|
||||
XCTAssertEqual(process.usage, 488 * Double(1024 * 1024))
|
||||
|
||||
process = ProcessReader.parseProcess("7163* AutoCAD LT 2023 11G ")
|
||||
XCTAssertEqual(process.pid, 7163)
|
||||
XCTAssertEqual(process.command, "AutoCAD LT 2023")
|
||||
XCTAssertEqual(process.usage, 11 * Double(1024 * 1024 * 1024))
|
||||
}
|
||||
|
||||
func testReplacePID() throws {
|
||||
|
||||
Reference in New Issue
Block a user