[New-bugs-announce] [issue47096] Use the PDH API in WindowsLoadTracker

Eryk Sun report at bugs.python.org
Tue Mar 22 15:51:28 EDT 2022

New submission from Eryk Sun <eryksun at gmail.com>:

In bpo-44336, a new version of WindowsLoadTracker was implemented in Lib/test/libregrtest/win_utils.py. This version resolves issues with the previous implementation that spawned typeperf.exe. The new implementation uses the registry API's HKEY_PERFORMANCE_DATA pseudohandle to access the performance counters. This requires hard-coding "2" as the key name of the system object, 44 as the index of the "Processor Queue Length" counter, and also several struct definitions. 

The HKEY_PERFORMANCE_DATA 'key' just wraps the API as an alternate way to consume counter data. Instead of taking this detour through a minimalist interface just to use the API in a roundabout way, it would be better to implement a few of the Performance Data Helper functions in _winapi. I've implemented a prototype in ctypes to demonstrate this, which I'm attaching as "loadtracker.py". The functions that would need to be implemented are PdhOpenQueryW(), PdhAddEnglishCounterW(), PdhCollectQueryData(), PdhGetRawCounterValue(), and PdhCloseQuery().

components: Windows
files: loadtracker.py
messages: 415808
nosy: eryksun, jkloth, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Use the PDH API in WindowsLoadTracker
type: enhancement
Added file: https://bugs.python.org/file50696/loadtracker.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list