Skip to content

feat(monitoring): robust macOS memory usage with TASK_VM_INFO fallback - #6

Merged
dev-harsh1998 merged 1 commit into
masterfrom
fix/memory-usage-fix
Aug 13, 2025
Merged

feat(monitoring): robust macOS memory usage with TASK_VM_INFO fallback#6
dev-harsh1998 merged 1 commit into
masterfrom
fix/memory-usage-fix

Conversation

@yogeshnimangre007

Copy link
Copy Markdown
Collaborator

feat(monitoring): robust macOS memory usage with TASK_VM_INFO fallback

Summary

Adds reliable process memory tracking on macOS (Intel & Apple Silicon). Previously the monitor endpoint sometimes returned:

"memory": { "available": false, ... }

due to a rigid struct definition or task_info flavor failure.

Changes

  • Correct mach_task_basic_info struct layout.
  • Compute flavor count using natural_t (u32) sizing.
  • Add fallback to TASK_VM_INFO when basic flavor fails.
  • Return first non‑zero resident size.
  • Add debug logs for each failure path.

Expected JSON

"memory": {
  "available": true,
  "current_bytes": <u64>,
  "peak_bytes": <u64>,
  "current_mb": <f64>,
  "peak_mb": <f64>
}

Verification (macOS)

RUST_LOG=debug cargo run -- --directory . --port 0
# note printed port
curl -s http://localhost:<PORT>/_irondrop/monitor?json=1 | jq '.memory'

Should show available: true. If not, debug logs will contain:

  • mach_task_basic_info failed
  • and possibly TASK_VM_INFO failed

Edge Cases

Case Result
Both flavors fail available:false (previous behavior)
Resident size 0 once Next poll (5s cache) retries
Sandbox restrictions Likely both fail, safe fallback

Performance

Negligible impact. Memory probe still cached for 5s.

Risks

  • Future macOS struct layout changes (unlikely for fields used).
  • If API changes, both flavors may fail (debug logs guide remediation).

Future Improvements (Optional)

  • Add proc_pid_rusage third fallback.
  • Percent of physical memory field.
  • Config flag to disable memory probing.
  • Clamp unrealistic ( > physical ) values.

Testing

  • Built on macOS (debug build).
  • Manual curl of monitor endpoint.
  • Verified no regression on Linux (code gated by #[cfg(target_os = "macos")]).

Notes

No external dependencies added; pure FFI approach. Safe failure path maintained.


Closes intermittent “memory tracking unavailable” observations on macOS.

@dev-harsh1998
dev-harsh1998 merged commit a8187e9 into master Aug 13, 2025
10 checks passed
@dev-harsh1998
dev-harsh1998 deleted the fix/memory-usage-fix branch August 13, 2025 14:55
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.

3 participants