# autoPriority Monitors process memory usage on Windows and automatically adjusts CPU priority: promotes memory-heavy processes to HIGH and demotes everything else to NORMAL. Optionally enters **Game Mode** when a process exceeds a higher threshold, boosting it to HIGH and setting all other processes to IDLE. **Windows only.** ## How it works ### Normal mode Every scan interval the program iterates over all running processes: | RSS vs `-mem` | 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 | ### Game mode (`-game-mem`) When any process reaches or exceeds the `-game-mem` threshold: 1. That process → **HIGH** (logged as `GAME`) 2. All other processes → **IDLE** (original priorities saved) 3. Log: `GAME MODE ON` When all such processes close: 1. All processes that were demoted during game mode are **restored to their original priority** (logged as `RESTORE`) 2. `GAME MODE OFF` logged 3. Normal mode resumes — priorities recalculated by `-mem` rules If `SetPriorityClass` or `OpenProcess` fails for a process (e.g., anti-cheat protection, system processes), the process is added to an in-memory exclusion list and never touched again (logged as `BLOCK`). Blocked processes are still measured for RSS each scan — if a blocked process exceeds `-game-mem`, it triggers game mode without attempting to change its priority. When the process exits, it is automatically removed from the list. On shutdown, all processes demoted during game mode are restored to their saved original priority. ## 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` | 512M | Memory threshold (e.g. 512M, 1G, 2048M) | | `-game-mem` | 2G | Game threshold (e.g. 2G, 4G). Must be > `-mem`. 0 = disabled | | `-interval` | 1 minute | Scan interval (min 10s) | | `-dry-run` | false | Log only, don't change priority | Examples: ``` # Run with 1 GB threshold, scanning every 30 seconds autopriority -mem=1G -interval=30s # Run with defaults (512M threshold, 2G game threshold) autopriority # Game mode: normal threshold 512M, game threshold 4G autopriority -mem=512M -game-mem=4G # 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 (normal mode) | | `DEMOTE` | Priority lowered to NORMAL (normal mode) | | `GAME DETECT` | Process first detected as exceeding game-mem threshold | | `GAME` | Process set to HIGH or IDLE (game mode) | | `GAME MODE ON` | Game mode activated | | `GAME MODE OFF` | Game mode deactivated — processes restored | | `BLOCK` | OpenProcess or SetPriorityClass failed; process added to exclusion list | | `RESTORE` | Process restored to original/saved priority (game mode exit or shutdown) | | `[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.