Skip to content

fix: improve RAM usage calculation and top processes#3160

Open
agentHits wants to merge 2 commits intoexelban:masterfrom
agentHits:fix/ram-usage-top-processes
Open

fix: improve RAM usage calculation and top processes#3160
agentHits wants to merge 2 commits intoexelban:masterfrom
agentHits:fix/ram-usage-top-processes

Conversation

@agentHits
Copy link
Copy Markdown

@agentHits agentHits commented Apr 21, 2026

image

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:
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=''

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=''
Comment thread Modules/RAM/main.swift Outdated

self.settingsView.callback = { [weak self] in
self?.usageReader?.read()
self?.processReader?.read()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why open settings trigger process read?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Modules/RAM/readers.swift Outdated
import Darwin
import Kit

@_silgen_name("proc_pid_rusage")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid using @_silgen_name

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I'll remove @_silgen_name from this PR.

@exelban
Copy link
Copy Markdown
Owner

exelban commented Apr 26, 2026

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.
@agentHits
Copy link
Copy Markdown
Author

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.

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.

@agentHits agentHits requested a review from exelban April 27, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants