78 lines
2.4 KiB
Markdown
78 lines
2.4 KiB
Markdown
# autoPriority
|
|
|
|
Monitors process memory usage on Windows and automatically adjusts CPU priority: promotes memory-heavy processes to HIGH and demotes everything else to NORMAL.
|
|
|
|
**Windows only.**
|
|
|
|
## How it works
|
|
|
|
Every scan interval the program iterates over all running processes:
|
|
|
|
| RSS vs threshold | Current priority | Action |
|
|
|---|---|---|
|
|
| ≥ threshold | anything except HIGH | → HIGH (logged as `PROMOTE`) |
|
|
| ≥ threshold | already HIGH | skip |
|
|
| < threshold | ABOVE_NORMAL, HIGH, or REALTIME | → NORMAL (logged as `DEMOTE`) |
|
|
| < threshold | NORMAL, BELOW_NORMAL, or IDLE | skip |
|
|
|
|
If `SetPriorityClass` fails for a process (e.g., anti-cheat protection), the process is added to an in-memory exclusion list and never touched again (logged as `BLOCK`). When the process exits, it is automatically removed from the list.
|
|
|
|
On shutdown, all promoted processes are restored to NORMAL.
|
|
|
|
## Build
|
|
|
|
Requires Go 1.26+.
|
|
|
|
```
|
|
# Standard build (with console window)
|
|
go build -o autopriority.exe .
|
|
|
|
# Background build (no console, minimal size)
|
|
go build -ldflags="-H windowsgui -s -w" -o autopriority.exe .
|
|
```
|
|
|
|
## Usage
|
|
|
|
```
|
|
autopriority [flags]
|
|
```
|
|
|
|
| Flag | Default | Description |
|
|
|-------------|---------------|----------------------------------|
|
|
| `-mem` | 536870912 | Memory threshold in bytes (512 MB) |
|
|
| `-interval` | 1 minute | Scan interval (min 10s) |
|
|
| `-dry-run` | false | Log only, don't change priority |
|
|
|
|
Examples:
|
|
|
|
```
|
|
# Run with 1 GB memory threshold, scanning every 30 seconds
|
|
autopriority -mem=1073741824 -interval=30s
|
|
|
|
# Dry run — log decisions without changing anything
|
|
autopriority -dry-run
|
|
```
|
|
|
|
## Log
|
|
|
|
Log is always written to `%TEMP%\autopriority.log`. A new log file is created on each run (previous log is deleted).
|
|
|
|
Log entries:
|
|
|
|
| Prefix | Meaning |
|
|
|---|---|
|
|
| `PROMOTE` | Priority raised to HIGH |
|
|
| `DEMOTE` | Priority lowered to NORMAL |
|
|
| `BLOCK` | SetPriorityClass failed; process added to exclusion list |
|
|
| `RESTORE` | Promoted process restored to NORMAL on shutdown |
|
|
| `SKIP RESTORE` | PID reused by a different process; restore skipped |
|
|
| `[DRY-RUN]` | Would change priority (dry-run mode) |
|
|
|
|
## Auto-start
|
|
|
|
Open **Win+R**, type `shell:startup`, and press Enter. Then place a shortcut to `autopriority.exe` in the folder that opens.
|
|
|
|
## Dependencies
|
|
|
|
None. Uses only Windows API (kernel32, psapi) via raw syscall.
|