Problems with win32pdh
Eric Jensen
ericj at byu.edu
Thu Jun 12 17:00:49 EDT 2003
I am trying to get the cpu utilization on a XP box.My code looks like this:
> import win32pdh
>
> my_query = win32pdh.OpenQuery( None, 0 )
> my_counter = win32pdh.AddCounter( my_query, "\\Processor(_Total)\\% Processor Time", 0 )
> win32pdh.CollectQueryData( my_query )
> junk, percent = win32pdh.GetFormattedCounterValue( my_counter, win32pdh.PDH_FMT_LONG )
> win32pdh.CloseQuery( my_query )
>
> print "Junk:", junk
> print "Percent: " + str( percent ) + "%"
The problem is that this always returns 99 % utilization
I tried to use the processor idle time also, but that just returns a 0%
each time. Am I doing something wrong, or does someone have a better way
for getting processor utilization.
Thanks,
Eric
More information about the Python-list
mailing list