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.
34 lines
812 B
Go
34 lines
812 B
Go
//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))
|
|
}
|