1

Fix process entry struct, add demote logic, block protected processes, improve logging

This commit is contained in:
2026-06-21 15:11:15 +03:00
parent d4da33ca5e
commit b5885791fa
2 changed files with 176 additions and 65 deletions
+30 -2
View File
@@ -1,9 +1,24 @@
# autoPriority
Automatically sets high CPU priority for processes exceeding a memory threshold.
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+.
@@ -38,7 +53,20 @@ autopriority -mem=1073741824 -interval=30s
autopriority -dry-run
```
Log is always written to `%TEMP%\autopriority.log`.
## 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