Add GPU_FOREIGN_UTIL_PCT: game detection via per-process GPU 3D-engine usage
Reads the same PDH counters as Task Manager (\GPU Engine(*)\Utilization Percentage, locale-independent via PdhAddEnglishCounterW), which cover graphics work under WDDM — games are caught without an exe list and the offender is named. Windows-only; a missing or failing counter disables the path with one log line. dwm (the desktop compositor) joins the default ignore list.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
//go:build windows
|
||||
|
||||
package game
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestGPUEngineSamplerLive opens the real PDH query and takes two samples;
|
||||
// the first only primes the rate counters. Skipped (not failed) when the
|
||||
// machine has no GPU counters.
|
||||
func TestGPUEngineSamplerLive(t *testing.T) {
|
||||
s, err := openGPUEngineSampler()
|
||||
if err != nil {
|
||||
t.Skipf("no GPU engine counters: %v", err)
|
||||
}
|
||||
if _, err := s.sample(); !errors.Is(err, errNotPrimed) {
|
||||
t.Fatalf("first sample: err = %v, want errNotPrimed", err)
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
utils, err := s.sample()
|
||||
if err != nil {
|
||||
t.Fatalf("second sample: %v", err)
|
||||
}
|
||||
for pid, util := range utils {
|
||||
if pid < 0 || util < 0 {
|
||||
t.Errorf("pid %d: util %.2f", pid, util)
|
||||
}
|
||||
}
|
||||
t.Logf("%d processes with 3D-engine usage", len(utils))
|
||||
}
|
||||
Reference in New Issue
Block a user