Skip to content

Free, open-source macOS cleaner. CleanMyMac alternative with zero telemetry. Native SwiftUI, scheduled auto-cleaning, Xcode/Homebrew/system cache cleanup. MIT licensed.

fix(performance): tell protected processes apart from churn in the process notes

momenbasel4ffd9604b970
diff --git a/PureMac/Services/ProcessResourceMonitor.swift b/PureMac/Services/ProcessResourceMonitor.swift
index 53cd939..859564d 100644
--- a/PureMac/Services/ProcessResourceMonitor.swift
+++ b/PureMac/Services/ProcessResourceMonitor.swift
@@ -82,6 +82,16 @@ enum ProcessResourceMath {
return Array(groups.values)
}
+ /// Processes that started or stopped since the previous sample. The first
+ /// sample has no baseline, so nothing counts as changed yet.
+ static func changedProcessCount(readings: [ProcessResourceReading], previous: [String: ProcessResourceReading]) -> Int {
+ guard !previous.isEmpty else { return 0 }
+ let current = Set(readings.map(\.identity))
+ let started = current.subtracting(previous.keys).count
+ let stopped = previous.keys.filter { !current.contains($0) }.count
+ return started + stopped
+ }
+
static func sorted(_ consumers: [ProcessResourceConsumer], by sort: ProcessResourceSort, search: String = "") -> [ProcessResourceConsumer] {
let query = search.trimmingCharacters(in: .whitespacesAndNewlines)
return consumers.filter { query.isEmpty || $0.name.localizedStandardContains(query) }.sorted {
@@ -100,7 +110,8 @@ enum ProcessResourceMath {
private struct ProcessResourceSample: Sendable {
let consumers: [ProcessResourceConsumer]
- let unavailableProcessCount: Int
+ let protectedProcessCount: Int
+ let changedProcessCount: Int
let failed: Bool
let warmingUp: Bool
}
@@ -121,7 +132,7 @@ private actor ProcessResourceSampler {
let estimate = proc_listallpids(nil, 0)
guard estimate > 0 else {
previous.removeAll()
- return ProcessResourceSample(consumers: [], unavailableProcessCount: 0, failed: true, warmingUp: true)
+ return ProcessResourceSample(consumers: [], protectedProcessCount: 0, changedProcessCount: 0, failed: true, warmingUp: true)
}
// Headroom accommodates processes created between enumeration calls.
var pids = [Int32](repeating: 0, count: Int(estimate) + 256)
@@ -129,18 +140,20 @@ private actor ProcessResourceSampler {
let count = pids.withUnsafeMutableBytes { proc_listallpids($0.baseAddress, capacityBytes) }
guard count > 0 else {
previous.removeAll()
- return ProcessResourceSample(consumers: [], unavailableProcessCount: 0, failed: true, warmingUp: true)
+ return ProcessResourceSample(consumers: [], protectedProcessCount: 0, changedProcessCount: 0, failed: true, warmingUp: true)
}
var readings: [ProcessResourceReading] = []
- var unavailable = Int(count) >= pids.count ? 1 : 0
+ var protectedCount = 0
+ var churn = Int(count) >= pids.count ? 1 : 0
for pid in pids.prefix(min(Int(count), pids.count)) where pid > 0 {
if Task.isCancelled { break }
var info = proc_taskallinfo()
let size = Int32(MemoryLayout<proc_taskallinfo>.stride)
errno = 0
guard proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &info, size) == size else {
- // An exited process is normal churn, not a permission failure.
- if errno != ESRCH { unavailable += 1 }
+ // Another user's process is a permission limit; anything else is
+ // a process that exited or changed under us and is churn.
+ if errno == EPERM { protectedCount += 1 } else { churn += 1 }
continue
}
// Re-read the path: exec can change the executable without changing
@@ -161,16 +174,18 @@ private actor ProcessResourceSampler {
let consumers = ProcessResourceMath.consumers(readings: readings, previous: previous,
processorCount: ProcessInfo.processInfo.activeProcessorCount,
nanosecondsPerTick: nanosecondsPerTick)
+ let changed = warmingUp ? 0 : churn + ProcessResourceMath.changedProcessCount(readings: readings, previous: previous)
previous = Dictionary(uniqueKeysWithValues: readings.map { ($0.identity, $0) })
- return ProcessResourceSample(consumers: consumers, unavailableProcessCount: unavailable,
- failed: readings.isEmpty, warmingUp: warmingUp)
+ return ProcessResourceSample(consumers: consumers, protectedProcessCount: protectedCount,
+ changedProcessCount: changed, failed: readings.isEmpty, warmingUp: warmingUp)
}
}
@MainActor
final class ProcessResourceMonitor: ObservableObject {
@Published private(set) var consumers: [ProcessResourceConsumer] = []
- @Published private(set) var unavailableProcessCount = 0
+ @Published private(set) var protectedProcessCount = 0
+ @Published private(set) var changedProcessCount = 0
@Published private(set) var isWarmingUp = true
@Published private(set) var isSampling = false
@Published private(set) var samplingFailed = false
@@ -190,7 +205,8 @@ final class ProcessResourceMonitor: ObservableObject {
consumers = []
icons.removeAll()
names.removeAll()
- unavailableProcessCount = 0
+ protectedProcessCount = 0
+ changedProcessCount = 0
isWarmingUp = true
samplingFailed = false
guard active else { return }
@@ -230,7 +246,8 @@ final class ProcessResourceMonitor: ObservableObject {
}
return consumer
}
- unavailableProcessCount = sample.unavailableProcessCount
+ protectedProcessCount = sample.protectedProcessCount
+ changedProcessCount = sample.changedProcessCount
samplingFailed = sample.failed
isWarmingUp = sample.warmingUp
}
diff --git a/PureMac/Views/Tools/ProcessResourcesView.swift b/PureMac/Views/Tools/ProcessResourcesView.swift
index 7fec748..8b5bf61 100644
--- a/PureMac/Views/Tools/ProcessResourcesView.swift
+++ b/PureMac/Views/Tools/ProcessResourcesView.swift
@@ -103,9 +103,11 @@ struct ProcessResourcesView: View {
if isActive && monitor.isWarmingUp && !monitor.samplingFailed {
Text("CPU values appear after the next sample.")
}
- if monitor.unavailableProcessCount > 0 {
- Text("Some protected or changing processes could not be measured.")
- .foregroundStyle(Tint.orange)
+ if isActive && monitor.changedProcessCount > 0 {
+ Text("Some processes started or stopped since the last sample. Their values appear in the next one.")
+ }
+ if monitor.protectedProcessCount > 0 {
+ Text("System processes are not listed. Use Activity Monitor for those.")
}
}
.font(.system(size: 10.5))
diff --git a/PureMac/ar.lproj/Localizable.strings b/PureMac/ar.lproj/Localizable.strings
index f4367f9..7274c97 100644
--- a/PureMac/ar.lproj/Localizable.strings
+++ b/PureMac/ar.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/de.lproj/Localizable.strings b/PureMac/de.lproj/Localizable.strings
index 6030ffe..8148b5a 100644
--- a/PureMac/de.lproj/Localizable.strings
+++ b/PureMac/de.lproj/Localizable.strings
@@ -924,5 +924,6 @@
"Search apps and processes" = "Search apps and processes";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
diff --git a/PureMac/en.lproj/Localizable.strings b/PureMac/en.lproj/Localizable.strings
index 1a93a65..aa98b51 100644
--- a/PureMac/en.lproj/Localizable.strings
+++ b/PureMac/en.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/es.lproj/Localizable.strings b/PureMac/es.lproj/Localizable.strings
index 9ac8761..70f765a 100644
--- a/PureMac/es.lproj/Localizable.strings
+++ b/PureMac/es.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/fr.lproj/Localizable.strings b/PureMac/fr.lproj/Localizable.strings
index 41dfa6b..24ea2c5 100644
--- a/PureMac/fr.lproj/Localizable.strings
+++ b/PureMac/fr.lproj/Localizable.strings
@@ -910,8 +910,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/ja.lproj/Localizable.strings b/PureMac/ja.lproj/Localizable.strings
index 5f106af..1600b6a 100644
--- a/PureMac/ja.lproj/Localizable.strings
+++ b/PureMac/ja.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/pl.lproj/Localizable.strings b/PureMac/pl.lproj/Localizable.strings
index 10a967f..9770875 100644
--- a/PureMac/pl.lproj/Localizable.strings
+++ b/PureMac/pl.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/pt-BR.lproj/Localizable.strings b/PureMac/pt-BR.lproj/Localizable.strings
index 8942e76..14a8fc3 100644
--- a/PureMac/pt-BR.lproj/Localizable.strings
+++ b/PureMac/pt-BR.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/ru.lproj/Localizable.strings b/PureMac/ru.lproj/Localizable.strings
index da67f12..ec277fb 100644
--- a/PureMac/ru.lproj/Localizable.strings
+++ b/PureMac/ru.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/uk.lproj/Localizable.strings b/PureMac/uk.lproj/Localizable.strings
index 31f6232..18521cd 100644
--- a/PureMac/uk.lproj/Localizable.strings
+++ b/PureMac/uk.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/zh-Hans.lproj/Localizable.strings b/PureMac/zh-Hans.lproj/Localizable.strings
index 24af097..247ae14 100644
--- a/PureMac/zh-Hans.lproj/Localizable.strings
+++ b/PureMac/zh-Hans.lproj/Localizable.strings
@@ -913,8 +913,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMac/zh-Hant.lproj/Localizable.strings b/PureMac/zh-Hant.lproj/Localizable.strings
index b33e8c4..edaa872 100644
--- a/PureMac/zh-Hant.lproj/Localizable.strings
+++ b/PureMac/zh-Hant.lproj/Localizable.strings
@@ -914,8 +914,9 @@
"Settings to review" = "Settings to review";
"Show all apps and processes" = "Show all apps and processes";
"Show top 8" = "Show top 8";
-"Some protected or changing processes could not be measured." = "Some protected or changing processes could not be measured.";
+"Some processes started or stopped since the last sample. Their values appear in the next one." = "Some processes started or stopped since the last sample. Their values appear in the next one.";
"Sort by" = "Sort by";
+"System processes are not listed. Use Activity Monitor for those." = "System processes are not listed. Use Activity Monitor for those.";
"The release service is unavailable. Please try again later." = "The release service is unavailable. Please try again later.";
"This build has no readable version. Open the releases page to check manually." = "This build has no readable version. Open the releases page to check manually.";
"To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later." = "To update with Homebrew, run this command in Terminal. The cask may follow the GitHub release a little later.";
diff --git a/PureMacTests/ProcessResourceMonitorTests.swift b/PureMacTests/ProcessResourceMonitorTests.swift
index 60ae2f0..b68b90d 100644
--- a/PureMacTests/ProcessResourceMonitorTests.swift
+++ b/PureMacTests/ProcessResourceMonitorTests.swift
@@ -64,6 +64,15 @@ final class ProcessResourceMonitorTests: XCTestCase {
XCTAssertNil(try XCTUnwrap(result.first).cpuFraction)
}
+ func testChangedProcessCountSeesStartsAndStopsButNotTheFirstSample() {
+ let a = reading(pid: 1), b = reading(pid: 2), c = reading(pid: 3)
+ XCTAssertEqual(ProcessResourceMath.changedProcessCount(readings: [a, b], previous: [:]), 0)
+ let previous = [a.identity: a, b.identity: b]
+ XCTAssertEqual(ProcessResourceMath.changedProcessCount(readings: [a, b], previous: previous), 0)
+ XCTAssertEqual(ProcessResourceMath.changedProcessCount(readings: [a, c], previous: previous), 2)
+ XCTAssertEqual(ProcessResourceMath.changedProcessCount(readings: [reading(pid: 2, start: 101)], previous: previous), 3)
+ }
+
func testSortingAndSearchKeepMeasuredConsumersFirstAndUseStableTies() {
let a = ProcessResourceConsumer(id: "a", name: "Browser", applicationPath: nil, cpuFraction: 0.5, residentBytes: 100, processCount: 1)
let b = ProcessResourceConsumer(id: "b", name: "Editor", applicationPath: nil, cpuFraction: 0.1, residentBytes: 500, processCount: 1)