Skip to content

Commit 10427a1

Browse files
committed
README: refactor readme to be simplier
Signed-off-by: Charalampos Mitrodimas <[email protected]>
1 parent a015f02 commit 10427a1

File tree

1 file changed

+186
-64
lines changed

1 file changed

+186
-64
lines changed

README.md

Lines changed: 186 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,87 @@
11
# peak-mem
22

3-
[![CI](https://github.com/peak-mem/peak-mem/actions/workflows/ci.yml/badge.svg)](https://github.com/peak-mem/peak-mem/actions/workflows/ci.yml)
4-
[![Security Audit](https://github.com/peak-mem/peak-mem/actions/workflows/security.yml/badge.svg)](https://github.com/peak-mem/peak-mem/actions/workflows/security.yml)
3+
A lightweight, cross-platform memory usage monitor for any process.
54

6-
A lightweight, cross-platform memory usage monitor for any process. Track peak memory consumption with minimal overhead.
5+
## Overview
6+
7+
peak-mem is a command-line utility that monitors and reports the peak memory usage of any program during its execution. It tracks both resident set size (RSS) and virtual memory size (VSZ) with minimal overhead, providing system administrators and developers with essential memory consumption metrics.
78

89
## Features
910

10-
- 🚀 **Minimal overhead** - Less than 1% CPU impact on monitored processes
11-
- 📊 **Multiple output formats** - Human-readable, JSON, CSV, or quiet mode
12-
- 👶 **Child process tracking** - Monitor entire process trees
13-
-**Real-time monitoring** - Watch memory usage as it happens
14-
- 🎯 **Threshold alerts** - Exit with error code when memory exceeds limits
15-
- 📈 **Timeline recording** - Export memory usage over time
16-
- 🔧 **Zero configuration** - Works immediately after installation
11+
- Low overhead monitoring
12+
- Multiple output formats (human-readable, JSON, CSV, quiet)
13+
- Child process tracking with process tree aggregation
14+
- Real-time memory usage display
15+
- Memory threshold monitoring with configurable alerts
16+
- Timeline recording for memory usage analysis
17+
- Cross-platform support (Linux, macOS, Windows & FreeBSD planned)
18+
- Zero configuration required
1719

1820
## Installation
1921

20-
### From source
22+
### From Source
2123

2224
```bash
2325
cargo install --path .
2426
```
2527

26-
### Pre-built binaries
28+
### Pre-built Binaries
2729

2830
Download the latest release for your platform from the [releases page](https://github.com/peak-mem/peak-mem/releases).
2931

3032
## Usage
3133

32-
### Basic usage
34+
### Basic Usage
3335

3436
Monitor a command and report its peak memory usage:
3537

3638
```bash
3739
peak-mem -- cargo build --release
3840
```
3941

40-
Output:
42+
Example output:
4143
```
4244
Command: cargo build --release
4345
Peak memory usage: 487.3 MB (RSS) / 892.1 MB (VSZ)
4446
Exit code: 0
4547
Duration: 14.2s
4648
```
4749

48-
### Command-line options
50+
### Command-line Options
4951

5052
```
51-
peak-mem [OPTIONS] -- <COMMAND> [ARGS...]
53+
USAGE:
54+
peak-mem [OPTIONS] -- <COMMAND> [ARGS...]
5255
5356
OPTIONS:
5457
-h, --help Print help information
5558
-V, --version Print version information
5659
-j, --json Output in JSON format
5760
-c, --csv Output in CSV format
58-
-q, --quiet Only output peak RSS value
59-
-v, --verbose Show detailed breakdown
60-
-w, --watch Show real-time memory usage
61+
-q, --quiet Only output peak RSS value in bytes
62+
-v, --verbose Show detailed process breakdown
63+
-w, --watch Display real-time memory usage
6164
-t, --threshold <SIZE> Set memory threshold (e.g., 512M, 1G)
6265
--no-children Don't track child processes
6366
--timeline <FILE> Record memory timeline to file
6467
--interval <MS> Sampling interval in milliseconds [default: 100]
68+
69+
ARGS:
70+
<COMMAND> Command to execute and monitor
71+
[ARGS...] Arguments to pass to the command
6572
```
6673

67-
### Examples
74+
## Examples
75+
76+
### JSON Output
6877

69-
#### JSON output for CI/CD integration
78+
For integration with CI/CD pipelines or automated tools:
7079

7180
```bash
7281
peak-mem --json -- ./my-app
7382
```
7483

84+
Output:
7585
```json
7686
{
7787
"command": "./my-app",
@@ -84,112 +94,224 @@ peak-mem --json -- ./my-app
8494
}
8595
```
8696

87-
#### Set memory threshold
97+
### Memory Threshold Monitoring
98+
99+
Exit with error code if memory exceeds threshold:
88100

89101
```bash
90102
peak-mem --threshold 1GB -- ./memory-intensive-app
91103
```
92104

93105
If the process exceeds 1GB of RSS, peak-mem will exit with code 1.
94106

95-
#### Real-time monitoring
107+
### Real-time Monitoring
108+
109+
Display live memory usage during execution:
96110

97111
```bash
98112
peak-mem --watch -- ./long-running-process
99113
```
100114

101-
Shows live memory usage updates during execution.
115+
### Exclude Child Processes
102116

103-
#### Monitor without child processes
117+
Monitor only the main process:
104118

105119
```bash
106120
peak-mem --no-children -- make -j8
107121
```
108122

109-
Only tracks the main make process, not the spawned compilation jobs.
123+
### Timeline Recording
110124

111-
#### Record memory timeline
125+
Save memory usage over time for analysis:
112126

113127
```bash
114128
peak-mem --timeline memory.json -- ./batch-job
115129
```
116130

117-
Saves detailed memory usage over time for later analysis.
131+
### CSV Output
132+
133+
For spreadsheet import or data analysis:
134+
135+
```bash
136+
peak-mem --csv -- ./data-processor
137+
```
138+
139+
Output:
140+
```csv
141+
command,peak_rss_bytes,peak_vsz_bytes,duration_ms,exit_code,threshold_exceeded,timestamp
142+
./data-processor,52428800,104857600,2150,0,false,2025-05-24T10:30:45+00:00
143+
```
118144

119145
## Platform Support
120146

121-
-**Linux** - Full support via `/proc` filesystem
122-
-**macOS** - Full support via system APIs
123-
- 🚧 **Windows** - Planned
124-
- 🚧 **FreeBSD** - Planned
147+
| Platform | Status | Implementation |
148+
|----------|--------|---------------|
149+
| Linux | Stable | `/proc` filesystem |
150+
| macOS | Stable | `proc_pidinfo` APIs |
151+
| Windows | Planned | Windows API |
152+
| FreeBSD | Planned | `sysctl` interface |
125153

126-
## How it works
154+
## How It Works
127155

128-
peak-mem spawns your process and monitors its memory usage by:
156+
peak-mem operates by:
129157

130-
1. Sampling memory statistics at regular intervals (default: 100ms)
131-
2. Tracking all child processes in the process tree
132-
3. Recording peak values throughout execution
133-
4. Reporting results after the process terminates
158+
1. Spawning the target process as a child
159+
2. Periodically sampling memory statistics (default: every 100ms)
160+
3. Tracking all descendant processes if enabled
161+
4. Recording peak values throughout execution
162+
5. Reporting results when the process terminates
134163

135-
The tool uses platform-specific APIs for minimal overhead:
136-
- Linux: `/proc/[pid]/status` for memory information
137-
- macOS: `proc_pidinfo` system calls
138-
- Windows: `GetProcessMemoryInfo` (planned)
164+
The monitoring is performed using platform-specific APIs to minimize overhead:
165+
- **Linux**: Reads from `/proc/[pid]/status` and `/proc/[pid]/stat`
166+
- **macOS**: Uses `proc_pidinfo` system calls
167+
- **Windows**: Will use `GetProcessMemoryInfo` (planned)
168+
- **FreeBSD**: Will use `sysctl` and `kvm` interfaces (planned)
139169

140-
## Performance
170+
## Performance Characteristics
141171

142-
- **Startup time**: < 10ms
143-
- **Memory overhead**: < 10MB
144-
- **CPU overhead**: < 1%
145-
- **Binary size**: ~1.1MB (stripped)
172+
- Startup time: < 10ms
173+
- Memory overhead: < 10MB
174+
- CPU overhead: < 1%
175+
- Binary size: ~1.1MB (release build, stripped)
176+
- Sampling rate: Configurable, default 10Hz
146177

147-
## Building from source
178+
## Building from Source
148179

149180
### Prerequisites
150181

151-
- Rust 1.70 or later
152-
- Cargo
182+
- Rust 1.74 or later (specified in `rust-version` in Cargo.toml)
183+
- Platform-specific development tools
153184

154-
### Build
185+
### Build Commands
155186

156187
```bash
157188
# Debug build
158189
cargo build
159190

160191
# Release build (optimized)
161192
cargo build --release
193+
194+
# Run tests
195+
cargo test
196+
197+
# Run with verbose output
198+
RUST_LOG=debug cargo run -- <command>
199+
```
200+
201+
### Cross-compilation
202+
203+
```bash
204+
# For Linux x86_64
205+
cargo build --target x86_64-unknown-linux-gnu
206+
207+
# For macOS x86_64
208+
cargo build --target x86_64-apple-darwin
209+
210+
# For macOS ARM64
211+
cargo build --target aarch64-apple-darwin
212+
```
213+
214+
## Development
215+
216+
### Project Structure
217+
218+
```
219+
src/
220+
├── main.rs # Application entry point
221+
├── cli.rs # Command-line argument parsing
222+
├── types.rs # Core data structures
223+
├── process/ # Process spawning and management
224+
├── monitor/ # Platform-specific memory monitoring
225+
│ ├── mod.rs # Platform abstraction layer
226+
│ ├── linux.rs # Linux implementation
227+
│ ├── macos.rs # macOS implementation
228+
│ ├── windows.rs # Windows implementation (stub)
229+
│ └── tracker.rs # Memory tracking logic
230+
└── output/ # Output formatting
162231
```
163232

164-
### Run tests
233+
### Testing
165234

166235
```bash
236+
# Run all tests
167237
cargo test
238+
239+
# Run tests with output
240+
cargo test -- --nocapture
241+
242+
# Run specific test
243+
cargo test test_memory_tracking
168244
```
169245

170-
## Contributing
246+
### Code Quality
247+
248+
```bash
249+
# Format code
250+
cargo fmt
251+
252+
# Run linter
253+
cargo clippy -- -D warnings
254+
255+
# Security audit
256+
cargo audit
257+
258+
# Check dependencies
259+
cargo deny check
260+
```
261+
262+
## Configuration
171263

172-
Contributions are welcome! Please feel free to submit a Pull Request.
264+
peak-mem requires no configuration files. All options are specified via command-line arguments.
173265

174-
### Development
266+
Environment variables:
267+
- `RUST_LOG`: Set to `debug` for verbose logging
175268

176-
The codebase is organized as follows:
269+
## Troubleshooting
177270

178-
- `src/cli.rs` - Command-line argument parsing
179-
- `src/monitor/` - Platform-specific memory monitoring
180-
- `src/process/` - Process spawning and management
181-
- `src/output/` - Output formatting
182-
- `src/types.rs` - Core data types
271+
### Permission Denied
272+
273+
On some systems, you may need elevated permissions to monitor certain processes:
274+
- Linux: No special permissions required for own processes
275+
- macOS: May require developer tools or sudo for system processes
276+
277+
### High Memory Usage Reported
278+
279+
Virtual memory size (VSZ) includes all mapped memory and is typically much larger than RSS. Focus on RSS for actual physical memory usage.
280+
281+
### Child Processes Not Tracked
282+
283+
Some programs may spawn processes in ways that break the parent-child relationship. Use system-specific tools like `pstree` to verify process relationships.
284+
285+
## Contributing
286+
287+
Contributions are welcome! Please:
288+
289+
1. Fork the repository
290+
2. Create a feature branch
291+
3. Make your changes
292+
4. Run tests and clippy
293+
5. Submit a pull request
294+
295+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
183296

184297
## License
185298

186-
This project is licensed under either of
299+
This project is dual-licensed under:
187300

188301
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
189302
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
190303

191-
at your option.
304+
You may choose either license for your use.
192305

193306
## Acknowledgments
194307

195-
Inspired by GNU time's memory reporting and the need for a simple, cross-platform memory monitoring tool.
308+
This project was inspired by:
309+
- GNU time's memory reporting capabilities
310+
- The need for a simple, cross-platform memory monitoring solution
311+
- The Rust ecosystem's excellent system programming capabilities
312+
313+
## Related Projects
314+
315+
- [GNU time](https://www.gnu.org/software/time/) - Classic UNIX time with memory reporting
316+
- [hyperfine](https://github.com/sharkdp/hyperfine) - Command-line benchmarking tool
317+
- [procs](https://github.com/dalance/procs) - Modern ps replacement written in Rust

0 commit comments

Comments
 (0)