Repository navigation
feat(daemon): report resident memory in info/status (#1785) - #1786
Merged
Merged
Conversation
The daemon now measures its own resident set instead of leaving every leak
report to an external sampler taken after the fact.
- fbuild_core::platform::process::resident_memory(pid) returns
MemoryUsage { resident_bytes, peak_resident_bytes }; the implementations
live only in the platform tree (Linux /proc VmRSS/VmHWM, macOS
proc_pidinfo + getrusage for self, Windows GetProcessMemoryInfo).
- Absence is None, never 0: pid 0, a missing /proc entry, a denied task
port, or a failed OpenProcess.
- /api/daemon/info gains rss_bytes and peak_rss_bytes (skipped when None).
- daemon_status.json gains the same fields, refreshed by
StatusManager::refresh_memory() from the existing maintenance loop at a
10 s cadence, so the last sample survives a wedged daemon.
- fbuild daemon status prints "Memory: 97.0 MB (peak 188.1 MB)".
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
fbuild-daemonnow reports its own resident memory, so leak reports carry numbers instead of a screenshot from another tool (#1785, parent #1360).fbuild_core::platform::process::resident_memory(pid)— new neutral capability returningMemoryUsage { resident_bytes, peak_resident_bytes }. Implementations live only in the platform tree:VmRSS/VmHWMfrom/proc/<pid>/status(KiB, checked multiply).proc_pidinfo(PROC_PIDTASKINFO)for the resident size;getrusage(RUSAGE_SELF)for the peak of this process (macOS has no per-pid high-water mark, so a foreign pid reportspeak = None).GetProcessMemoryInfoviaPROCESS_QUERY_LIMITED_INFORMATION./procentry, a denied task port, or a failedOpenProcessall yieldNone— never0 B.GET /api/daemon/infogainsrss_bytesandpeak_rss_bytes(bothskip_serializing_if = None, so older clients see no change).daemon_status.jsongains the same two fields andStatusManager::refresh_memory(), called from the existing 1 s maintenance loop at a 10 s cadence. This is the half that survives a wedged daemon:/healthstops answering, the last good sample stays on disk.fbuild daemon statusprintsMemory: 84.2 MB (peak 181.8 MB). The peak suffix is only shown when it exceeds the current sample.Why the status file matters
#1360's evidence problem was that every existing sample was external (
tasklist,ps,/proc) taken after the fact. A daemon that has stopped answering HTTP still leaves its last memory sample on disk, and the nextfbuild daemon statusreads it.Tests
platform::process: current process reports a positive resident set withpeak >= rss; pid 0 reports nothing.platform::linux:/proc/<pid>/statusline parsing (KiB suffix required,""/MBrejected), missing pid →None, own process → positive rss +VmHWM.status_manager: memory round-trips through the status file; a legacydaemon_status.jsonwithout the fields still deserialises; the peak never moves backwards across refreshes.models:/api/daemon/infoserialises both fields.fbuild daemon status:memory_labelformatting with and without a released peak.Gates:
bash test,clippy --workspace --all-targets -- -D warnings,fmt,ci/run_dylintfor core/daemon/cli,ci/enforce_platform_boundary.py --print-totals(44/0),ci/check_test_layout.py.Not in this PR
No Windows/macOS runtime verification of the numbers (only cross-target
checkonx86_64-pc-windows-msvcandx86_64-apple-darwin); the Linux path was exercised against a live daemon. Nothing here changes what the daemon does with the numbers — sampling cadence and thresholds stay for #1360's follow-up.