29.1 Recording Execution
Starting a DAP Server with Recording
The pmat debug serve command starts a Debug Adapter Protocol (DAP) server that debuggers can connect to. When you enable recording, all execution traces are saved to .pmat files.
Basic Usage
# Start DAP server without recording
pmat debug serve --port 5678
# Start DAP server WITH recording
pmat debug serve --port 5678 --record-dir ./recordings
Example Output
π Starting DAP server...
Host: 127.0.0.1
Port: 5678
Recording: enabled
Record directory: ./recordings
Connect your debugger to: 127.0.0.1:5678
Press Ctrl+C to stop the server
Recording Structure
When recording is enabled, PMAT saves execution traces in the specified directory:
recordings/
βββ program-2025-10-30T14-23-45.pmat # Timestamped recording
βββ program-2025-10-30T14-24-12.pmat
βββ bugfix-test-2025-10-30T15-00-00.pmat
TDD Example: Recording a Simple Program
Letβs record execution of a Rust program that calculates Fibonacci numbers.
Step 1: Write the Program
Create fibonacci.rs:
fn fibonacci(n: u32) -> u64 { match n { 0 => 0, 1 => 1, _ => fibonacci(n - 1) + fibonacci(n - 2), } } fn main() { println!("Fibonacci sequence:"); for i in 0..10 { println!("F({}) = {}", i, fibonacci(i)); } }
Step 2: Start Recording Server
# Terminal 1: Start PMAT DAP server with recording
pmat debug serve --port 5678 --record-dir ./fib-recordings
Step 3: Debug with VSCode
Add .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug Fibonacci",
"program": "${workspaceFolder}/target/debug/fibonacci",
"args": [],
"cwd": "${workspaceFolder}",
"debugServer": 5678
}
]
}
Step 4: Run Debugger
- Set breakpoints in
fibonacci()function - Start debugging (F5 in VSCode)
- Step through execution
- PMAT records every state transition
Step 5: Verify Recording
$ ls -lh fib-recordings/
-rw-r--r-- 1 user user 45K Oct 30 14:23 fibonacci-2025-10-30T14-23-45.pmat
What Gets Recorded?
Each .pmat file contains:
-
Metadata
- Program name
- Command-line arguments
- Timestamp
- Environment variables
-
Snapshots (one per execution step)
- Variable values (locals and globals)
- Stack frames with source location
- Instruction pointer
- Relative timestamp
-
Optional
- Memory snapshots (configurable)
- Register states
- Heap allocations
Compression
.pmat files use MessagePack binary format with optional compression:
# Check recording size
$ ls -lh fibonacci.pmat
-rw-r--r-- 1 user user 45K Oct 30 14:23 fibonacci.pmat
# Extract metadata
$ pmat debug replay fibonacci.pmat --metadata-only
π Recording Metadata:
Program: fibonacci
Arguments: []
Recorded: 2025-10-30T14:23:45Z
Snapshots: 127
Best Practices
β DO:
- Use descriptive
--record-dirnames (./bug-123-recordings) - Record short, focused debugging sessions
- Clean up old recordings regularly
β DONβT:
- Record long-running applications (large .pmat files)
- Record in production environments (performance impact)
- Share recordings with sensitive data (contains variable values)
Performance Impact
Recording has minimal overhead:
| Metric | Without Recording | With Recording |
|---|---|---|
| Execution Time | 1.0x | 1.05x - 1.15x |
| Memory Usage | 1.0x | 1.2x - 1.5x |
| Disk I/O | None | 1-5 MB/min |
Next Steps
Now that you have recordings, learn how to: