Skip to content

feat(cli): add /heapdump for process memory snapshots#152

Merged
emal-avala merged 5 commits intomainfrom
feat/cmd-heapdump
Apr 22, 2026
Merged

feat(cli): add /heapdump for process memory snapshots#152
emal-avala merged 5 commits intomainfrom
feat/cmd-heapdump

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Adds `/heapdump` — writes a best-effort process memory snapshot to a timestamped file under the user's data directory. Hidden from `/help` (diagnostic command, not daily-use).

  • Linux: parses `/proc/self/status` (VmPeak, VmSize, VmRSS, VmData, VmStk, VmExe, VmLib, VmPTE, VmSwap, Threads)
  • macOS: shells out to `ps -o rss,vsz` to avoid adding a mach binding dependency
  • Other platforms: prints "unsupported" notice

Writes to `{data_local}/agent-code/heapdumps/YYYYMMDD-HHMMSS.txt` with a header noting timestamp, PID, version, and platform.

Why

When investigating memory growth or leaks, users currently have no way to capture a snapshot from within the running session. A first-class heap profiler would require rebuilding with a profiling allocator — this OS-level snapshot is the 80% solution at 0 deps.

Test plan

  • `cargo check -p agent-code` passes
  • `cargo clippy -p agent-code --no-deps` clean
  • `cargo test --bin agent heapdump` (2 unit tests for `parse_proc_status`)
  • `cargo build -p agent-code` passes
  • Manual on Linux: `/heapdump` prints RSS/Size/Peak/Threads and writes a file
  • Manual on macOS: `/heapdump` prints RSS/Size and writes a file

Writes a best-effort memory snapshot (RSS, VSZ, peak, per-segment
sizes where available) to a timestamped file under the user's data
directory. Useful for attaching to bug reports when investigating
memory growth or leaks.

Linux: parses /proc/self/status for VmPeak/VmSize/VmRSS/VmData/etc.
macOS: shells out to `ps -o rss,vsz` to avoid a mach binding dep.
Other platforms: prints an "unsupported" notice.

Hidden from /help since it's a diagnostic command, not a daily-use one.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

The tests module only has Linux-specific tests; on Windows/macOS the
`use super::*` was unused and fails `-D warnings`. Moving the cfg
guard up to the mod itself avoids duplicating it per test and keeps
the file lint-clean on every platform.

Also: cargo fmt.
# Conflicts:
#	crates/cli/src/commands/mod.rs
# Conflicts:
#	crates/cli/src/commands/mod.rs
# Conflicts:
#	crates/cli/src/commands/mod.rs
@emal-avala emal-avala merged commit 466d57a into main Apr 22, 2026
13 of 14 checks passed
@emal-avala emal-avala deleted the feat/cmd-heapdump branch April 22, 2026 22:42
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.

1 participant