fix: improve RAM usage calculation and top processes#3160
fix: improve RAM usage calculation and top processes#3160agentHits wants to merge 2 commits intoexelban:masterfrom
Conversation
This PR fixes two RAM-related issues: - the used memory value is now closer to Activity Monitor - the top processes list now uses more accurate RAM data and preserves real process names in non-combined mode ### Changes - adjusted RAM breakdown calculation in `Modules/RAM/readers.swift` - switched top process memory usage to `proc_pid_rusage(..., ri_phys_footprint)` - improved process name resolution for helper/web content processes - refreshed the RAM process list immediately after RAM settings changes ### Tests - updated `Tests/RAM.swift` - verified with: ```bash xcodebuild test \ -project Stats.xcodeproj \ -scheme Stats \ -destination 'platform=macOS' \ -only-testing:Tests/RAM \ CODE_SIGNING_ALLOWED=NO \ CODE_SIGNING_REQUIRED=NO \ CODE_SIGN_IDENTITY=''
|
|
||
| self.settingsView.callback = { [weak self] in | ||
| self?.usageReader?.read() | ||
| self?.processReader?.read() |
There was a problem hiding this comment.
why open settings trigger process read?
There was a problem hiding this comment.
The intent there was to refresh the top process list immediately after toggling RAM-related settings, especially the combined processes option.
You're right though: settingsView.callback is too broad for that and can also be triggered when opening/settings refresh. I'll remove the process read from this callback and keep it scoped only to the setting that actually affects the process list.
| import Darwin | ||
| import Kit | ||
|
|
||
| @_silgen_name("proc_pid_rusage") |
There was a problem hiding this comment.
please avoid using @_silgen_name
There was a problem hiding this comment.
Understood. I'll remove @_silgen_name from this PR.
|
too many changes in one PR. You not only trying to improve RAM usage calculation, but also rewrite the whole top process logic. Too much in one PR. |
Updated the PR to keep it focused on RAM usage calculation only. Changes in this update: - removed processReader read from the generic settings callback - removed @_silgen_name / proc_pid_rusage usage - reverted the top processes rewrite from this PR - kept only the RAM memory breakdown calculation fix and its test I will move the top processes improvement into a separate PR if needed.
Understood. I mixed separate concerns in this PR. The process read from settings was only meant to refresh the top processes immediately after changing process-related settings, but I agree it should not be triggered from opening/settings callback. I removed that. I also removed the proc_pid_rusage / @_silgen_name based top-process rewrite and the process tree changes from this PR. This PR is now scoped to the RAM usage calculation only. I wrote the entire code using Codex. I don't know Swift. I saw a bug and decided to try to solve it using AI. Yes, that partially solved the problem. Thanks for your comments. I think I've completely fixed it with your answers. Please check. |
This PR fixes two RAM-related issues:
Changes
Modules/RAM/readers.swiftproc_pid_rusage(..., ri_phys_footprint)Tests
Tests/RAM.swift