Ticket #12 (new enhancement)

Opened 4 years ago

Last modified 4 years ago

Windows: How To Get % Processor Time Correctly By Using the Performance Data Helper (PDH) API

Reported by: chris Owned by:
Priority: major Milestone:
Component: Win32 Version:
Keywords: Cc:

Description

See if we can improve the % Processor Time data collection on Win32 using this article.

"How To Get % Processor Time Correctly By Using the Performance Data Helper (PDH) API"

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q262938

Change History

Changed 4 years ago by chris

A suggested implementation I found on the python-win32 list is:

import win32pdh, time

path = win32pdh.MakeCounterPath( (None,"Process","Idle", None, -1, "% Processor Time") )

# open the query, and add the counter to the query
base = win32pdh.OpenQuery()
counter = win32pdh.AddCounter(base, path)

# collect the data for the query object. We need to collect the query data
# twice to be able to calculate the % Processor Time 
win32pdh.CollectQueryData(base)
time.sleep(0.1)
win32pdh.CollectQueryData(base)

# Get the formatted value of the counter
print win32pdh.GetFormattedCounterValue(counter, win32pdh.PDH_FMT_LONG)[1]
Note: See TracTickets for help on using tickets.