Python exposes the ability to read
Performance Monitor information from the
win32pdhutil modules. These modules use a
Microsoft API to access the Performance Monitor known as the
Performance Data Helper, or PDH, hence the name of the Python
To get a feel for these Python modules, let’s start with a demonstration of displaying a dialog for the user to browse and select the counters on this or any machine.
module provides a function
browse() that displays such a dialog. As the user
selects the Add button in the dialog, a function you provide is
called with the selected counter. This callback function is supplied
as a parameter to
. The first step is to provide the
callback function, which takes a single parameter—the name of
the counter. Our example simply prints this name.
Thus, the callback function can be defined as follows:
>>> def CounterCallback( counter ): ... print "Counter is", counter ... >>>
You can display the dialog by importing the
win32pdhutil module and calling the
browse() function passing the callback:
>>> import win32pdhutil >>> win32pdhutil.browse(CounterCallback)
A dialog is presented that allows you to select all the counters available on the system and even other systems! Select the Add button and your function is called, printing the selected counter. Figure 18.1 shows the code running under Python-Win, just after selecting the Add button. ...