[python-win32] win32pdhutil Processor Time always returns 99
Martin Richard
Richard.Martin at thomson.net
Mon Dec 15 13:11:53 EST 2003
I found a solution by searching the archives. Here some code cut out of some other performance collecting code I put together.
Rick
import os
import time
import win32pdh
import win32pdhquery
import win32pdhutil
class HostCPU:
#
def __init__(self):
path = win32pdh.MakeCounterPath((None,"Processor","_Total",
None, -1, "% Processor Time"))
self.base = win32pdh.OpenQuery()
self.counter = win32pdh.AddCounter(self.base, path)
self.reset()
#
def reset(self):
''' Need to do this to initialize first data point. The win32
internals will calculate the CPU usage that occurs between a reset
and getUsage or between successive getUsage calls.
'''
win32pdh.CollectQueryData(self.base)
#
def getUsage(self):
''' see HostCPU.reset.__doc_ '''
win32pdh.CollectQueryData(self.base)
# Get the formatted value of the counter
return win32pdh.GetFormattedCounterValue(self.counter,
win32pdh.PDH_FMT_LONG)[1]
-----Original Message-----
From: Martin Beckett [mailto:martin at datactics.co.uk]
Sent: Friday, December 12, 2003 11:24 AM
To: python-win32 at python.org
Subject: [python-win32] win32pdhutil Processor Time always returns 99
I am trying to get the % CPU load in python on win32
win32pdhutil.GetPerformanceAttributes("Processor(_Total)","% Processor
Time")
only ever returns 99 whatever the machine load ?
Running on Windows XP-pro + ActivePython 2.3.2 Build 231
Any ideas ?
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
More information about the Python-win32
mailing list