Jump to content

ProcessLogger

From MindAttic Docs
Revision as of 17:56, 1 December 2026 by Docs Sync (talk | contribs) (md2wiki: sync from MindAttic.Docs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ProcessLogger

Catch whatever stole focus from your game: ProcessLogger records every Windows process start and exit, even sub-second ones, with memory peaks and every foreground-window change, in a filterable viewer.

.NET-10-512BD4.svg Platform-Windows-0078D6.svg Capture-ETW%20%2B%20WMI-5c2d91.svg SQLite-EF%20Core-003B57.svg Status-working-2f7a4f.svg

The viewer's Processes tab: include and exclude filters, match mode, row count, and columns from Name to Source

A window flashes up and your full-screen game drops to the desktop. Task Manager shows nothing, because whatever did it lived for half a second. ProcessLogger is a pair of small Windows apps that answer that question: a background logger that writes every process lifecycle and focus change to a local SQLite database, and a viewer to search it.

Scope

The complete product, built or not, is written down in SPEC.md: every epic, feature and story, each marked built or with the milestone that delivers it, plus what is never in the product. The current finish line is RELEASE.md.

Why

  • Find the process that launched and exited before you could see it; the kernel trace catches processes that live only a fraction of a second.
  • See what actually took the foreground, and when, next to what was running at that moment.
  • Know who started it: each row carries the parent process name, the executable path and the command line.
  • See how heavy it was: peak working set, peak private bytes and the last working set before exit.
  • Trust the record: two independent capture sources are reconciled, and each row says which of them saw it.
  • Keep it all local: one SQLite file under your own profile, nothing sent anywhere.

Features

Logger (ProcessLogger.Cli):

  • ETW kernel process trace (the NT Kernel Logger session, via TraceEvent). The kernel raises these events as part of process creation and exit, so nothing is missed between polls.
  • WMI process trace (Win32_ProcessStartTrace and Win32_ProcessStopTrace) as a redundant cross-check and as the fallback when another tool already owns the kernel session.
  • Reconciler: if both sources report the same PID within the reconcile window (250 ms by default) they are merged into one row (preferring ETW's richer path and command line), and the Source column reads Both; otherwise it reads Etw or Wmi. A second source that confirms the same process later (WMI runs 1-2 s behind ETW) still upgrades its row to Both, while the process runs or up to 5 s after its start once it has exited. Names are stored with .exe whichever source reported first (ETW alone omits it); name filters match either spelling, so older rows without .exe still match.
  • Memory sampling every 50 ms while a process is alive (up to 200 samples): peak working set, peak private bytes, final working set and the sample count.
  • Window title of the process's main window, sampled shortly after start (best effort).
  • Focus log: a SetWinEventHook foreground hook records each window that takes focus, with its process, title, and focused and lost times.

Viewer (ProcessLogger.Frontend):

  • Processes and Focus tabs over the same database.
  • Include and exclude text filters with Partial text, Exact string or Regex matching, and the last 50 to 1000 rows on Processes (50 to 500 on Focus).
  • Per-column value filters, sortable columns (newest first by default, with Reset sort) and resizable column widths that are remembered across restarts.
  • Export CSV on either tab writes exactly the filtered, sorted rows on screen to a file you choose.
  • Auto-refresh every 1 second to 20 minutes, and a System, Light or Dark theme. Both are settings in MindAttic Vault: the cog opens ProcessLogger's tab in MindAttic.Vault.Desktop, and a saved change applies when you switch back to the viewer and on every later start.

Quick start

Prerequisites: Windows, the .NET 10 SDK, the Microsoft Edge WebView2 runtime, and an administrator account (the logger needs elevation for ETW and WMI tracing).

git clone https://github.com/mindattic/ProcessLogger.git
cd ProcessLogger
powershell -ExecutionPolicy Bypass -File .\run.ps1 -Redeploy -RunRelease

run.bat (or run.ps1) opens the MindAttic standard run menu (the shared deploy-lib.ps1): 1) Redeploy publishes both apps to R:\MindAttic\Apps\ProcessLogger\Debug (framework-dependent) and R:\MindAttic\Apps\ProcessLogger\Release (self-contained single-file exes), 2) Run Debug and 3) Run Release open the viewer (ProcessLogger.Frontend.exe) from that folder, and 13 is Deploy & Run. Switches skip the menu: -Redeploy, -RunDebug, -RunRelease, -DryRun. Point a desktop shortcut at the repo's run.bat.

Start the logger from the same folder: ProcessLogger.Cli.exe. Windows shows a UAC prompt for it, because it is marked requireAdministrator in its manifest. When it is running, the logger console shows:

ProcessLogger is watching. Press Ctrl+C to stop.

Leave the logger running, reproduce the problem, then switch to the viewer and filter.

Configuration

Settings live in MindAttic Vault, per machine, in %LOCALAPPDATA%\MindAttic\ProcessLogger\settings.json, and are edited on ProcessLogger's tab in MindAttic.Vault.Desktop (the viewer's cog opens it). The first start writes the defaults and a settings.manifest.json beside them so the tab can render; ProcessLogger.Cli.exe --write-settings-manifest does the same and exits.

Setting Default Meaning Takes effect
Capture sources (enabledSources) Both None, Etw, Wmi or Both; None records nothing next logger start
Database file (databasePath) empty SQLite file the logger writes and the viewer reads; empty means %LOCALAPPDATA%\MindAttic\ProcessLogger\processlogger.db next start of each app
Reconcile window (ms) (reconcileWindowMs) 250 0 to 10000; how long to wait for the second source to confirm a PID before writing a single-source row next logger start
Auto-refresh (seconds) (refreshIntervalSeconds) 3 1 to 1200; how often the viewer re-reads the database when you switch back to the viewer
Theme (theme) System System, Light or Dark for the viewer when you switch back to the viewer

appsettings.json next to ProcessLogger.Cli.exe now holds only log levels. A ProcessLogger section left in it from before the Vault move is imported once, on the first start that finds no Vault settings file, and ignored after that.

The database runs in SQLite WAL mode, so the viewer can read while the logger writes.

How it works

 ProcessLogger.Cli (elevated)                                   ProcessLogger.Frontend
 ┌──────────────────────────────────────────────┐               ┌──────────────────────────┐
 │ EtwProcessCaptureSource ──┐                  │               │ WPF + WebView2           │
 │                           ├─> ProcessWatcher │               │ wwwroot/index.html       │
 │ WmiProcessCaptureSource ──┘    reconcile by  │               │   Processes | Focus      │
 │                                PID (250 ms)  │               │   filters, sort, columns │
 │                                  │           │               └────────────┬─────────────┘
 │                    MemorySampler (50 ms)     │                            │ query services
 │ FocusWatcher (foreground hook)   │           │                            │
 └──────────────┬───────────────────┴───────────┘                            │
                └──────────> processlogger.db (SQLite, WAL) <────────────────┘
                             ProcessEvents, FocusEvents

Notes on the data:

  • Windows does not expose "how much memory a process gave back" for a foreign process. FinalWorkingSetBytes, the last sample before exit, is the closest observable proxy.
  • A sample count of 0 means the process lived shorter than one sampler tick.
  • Path and command line are only reliably supplied by the ETW source.
  • A stop for a process that was already running when the logger started is ignored; there is no row to close.
  • Operational logging (every ILogger<T> call site in Core, the Cli and the viewer) goes through MindAttic.Log into one SQLite database, %APPDATA%\MindAttic\Logging\ProcessLogger\MindAttic.Log.db, not into processlogger.db; the viewer's rows carry a ProcessLogger.Frontend category. Both follow one level policy: lifecycle lines, warnings and errors; EF Core and framework categories log Warning and above, and the per-process start and exit lines are Debug, so they are not stored. There is nothing to configure, and rows from the older, shared-file layout migrate across automatically the first time the new version runs.

Building and testing

dotnet build ProcessLogger.slnx
dotnet test ProcessLogger.Tests

The NUnit tests cover the reconciling watcher and its edge cases (with a fake capture source), the process and focus query services against SQLite, every Vault setting (LampSettingsTests, one test per setting), and the MindAttic.Log integration (logging lands in its own database, Phase 1 rows migrate across, and a captured process writes no Information row). The build treats warnings as errors (Directory.Build.props).

Project layout

Project Role
ProcessLogger.Core Capture sources, reconciler, memory sampler, focus watcher, EF Core model and migrations, query services
ProcessLogger.Cli Elevated generic host that runs the watchers and applies migrations at start
ProcessLogger.Frontend WPF + WebView2 viewer; vanilla HTML, CSS and JS in wwwroot
ProcessLogger.Tests NUnit tests

Limitations

  • Windows only, and the logger must run elevated.
  • Only one NT Kernel Logger session can exist system-wide. If another tool owns it, the ETW source logs an error and stays off, and WMI carries on alone (WMI has about 1 to 2 seconds of startup latency and can drop rapid bursts).
  • The logger reads its settings once at start, and the viewer reads the database file once at start: change either, and restart that app for it to apply.
  • Window titles are best effort: background and console processes have none, and a GUI window may not exist yet when it is sampled.

Documentation

  • docs/USER_STORIES.md: this repo's ticket log and story index.
  • AGENTS.md: entry point for AI agents working in this repo; it points at the shared MindAttic agent standard.

License

This repository has no LICENSE file; all rights are reserved.

Part of MindAttic — see more projects at github.com/mindattic. Related: JobHunt, which uses the same WPF + WebView2 hosting pattern.

Pages in this repository

  • ProcessLogger — Project Bible — Catch whatever stole focus: record every Windows process start and exit, even sub-second ones, and every foreground change, then search it…
  • Code ledger: ProcessLogger — Every tracked source file and the ticket in this repo's tree that accounts for it (MAT-T484; method:…
  • ProcessLogger — Release charter — A pair of small Windows apps that catch whatever stole focus: an elevated logger records every process start and exit (ETW + WMI,…
  • ProcessLogger — Product specification — In docs/ECOSYSTEM.md ProcessLogger is a product (an app): it uses the platform for settings, logging, scheduling and shipping and owns…
From ProcessLogger/docs/overview.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.