[python-win32] Process monitor

Moray B. Grieve mbg@apama.com
Tue, 30 Apr 2002 09:12:52 +0100


Many thanks for the reply - and a reply to a previous posting. The link =
you sent solved the problem, and explains why I was getting valid cpu =
usage when using the win32pdhquery module which collects the data over a =
period of time.

The up shot was that I had to call CollectQueryData twice so that two =
data points in time were obtained in order to calculate the % processor =
time for the process (the calculation uses x1-x0/dT). Hence the below =
works;=20


import win32pdh, time

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

# open the query, and add the counter to the query
base =3D win32pdh.OpenQuery()
counter =3D 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=20
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]


This would mean that the value of this counter (and presumably "% User =
Time" and "% Privileged Time") would need to obtained in a different =
manner to the other Process counters in win32pdhutil, if the value of =
the counter is to be what the naive user (i.e. me!) expects.

Thanks again,
Moray =20






-----Original Message-----
From: Mark Hammond [mailto:mhammond@skippinet.com.au]
Sent: 30 April 2002 00:14
To: Moray B. Grieve; python-win32@python.org
Subject: RE: [python-win32] Process monitor


You may find =
http://support.microsoft.com/default.aspx?scid=3Dkb;EN-US;q262938
of interest.  I haven't tiem to digest it now, but please let me know =
what
the up-shot is :)  I will help making any necessary changes.

Mark.

> -----Original Message-----
> From: python-win32-admin@python.org
> [mailto:python-win32-admin@python.org]On Behalf Of Moray B. Grieve
> Sent: Tuesday, 30 April 2002 12:52 AM
> To: python-win32@python.org
> Subject: [python-win32] Process monitor
>
>
> I want to write a python script that monitors a process CPU and
> memory usage, and am basing it on the win32pdhutil wrapper
> module. However, I have noticed that in this module the function
> GetPerformanceAttributes always returns zero for the counter "%
> Processor Time" even when I know a process is using a large
> amount of CPU (as seen from the windows task manager). This is
> also the same for the counters "% User Time" and "% Privileged
> Time" and is easily demonstrated when running ShowAllProcesses,
> which gives zero for all these three counters and for all running
> processes.
>
> Has anyone noticed this before, or can help me as to how I can
> retrieve the CPU usage of a process?
>
> With many thanks for any help,
> Moray Grieve
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>