Update of /cvsroot/pywin32/pywin32/win32/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv28108
Modified Files:
win32pdhutil.py
Log Message:
Handle translating counter names to/from native language and English.
Index: win32pdhutil.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32pdhutil.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** win32pdhutil.py 9 May 2002 05:56:32 -0000 1.5
--- win32pdhutil.py 1 Sep 2003 08:09:50 -0000 1.6
***************
*** 23,26 ****
--- 23,44 ----
error = win32pdh.error
+ # Handle some localization issues.
+ # see http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q287/1/59.asp&NoWebContent=1
+ # Build a map of english_counter_name: counter_id
+ counter_english_map = {}
+
+ def find_pdh_counter_localized_name(english_name, machine_name = None):
+ if not counter_english_map:
+ import win32api, win32con
+ counter_reg_value = win32api.RegQueryValueEx(win32con.HKEY_PERFORMANCE_DATA, "Counter 009")
+ counter_list = counter_reg_value[0]
+ for i in range(0, len(counter_list) - 1, 2):
+ try:
+ counter_id = int(counter_list[i])
+ except ValueError:
+ continue
+ counter_english_map[counter_list[i+1].lower()] = counter_id
+ return win32pdh.LookupPerfNameByIndex(machine_name, counter_english_map[english_name.lower()])
+
def GetPerformanceAttributes(object, counter, instance = None, inum=-1, format = win32pdh.PDH_FMT_LONG, machine=None):
path = win32pdh.MakeCounterPath( (machine,object,instance, None, inum,counter) )
***************
*** 37,41 ****
win32pdh.CloseQuery(hq)
! def FindPerformanceAttributesByName(instanceName, object = "Process", counter = "ID Process", format = win32pdh.PDH_FMT_LONG, machine = None, bRefresh=0):
"""Find peformance attributes by (case insensitive) instance name.
--- 55,59 ----
win32pdh.CloseQuery(hq)
! def FindPerformanceAttributesByName(instanceName, object = None, counter = None, format = win32pdh.PDH_FMT_LONG, machine = None, bRefresh=0):
"""Find peformance attributes by (case insensitive) instance name.
***************
*** 43,47 ****
Most useful for returning a tuple of PIDs given a process name.
"""
!
if bRefresh: # PDH docs say this is how you do a refresh.
win32pdh.EnumObjects(None, machine, 0, 1)
--- 61,66 ----
Most useful for returning a tuple of PIDs given a process name.
"""
! if object is None: object = find_pdh_counter_localized_name("Process", machine)
! if counter is None: counter = find_pdh_counter_localized_name("ID Process", machine)
if bRefresh: # PDH docs say this is how you do a refresh.
win32pdh.EnumObjects(None, machine, 0, 1)
***************
*** 106,121 ****
def browse( callback = BrowseCallBackDemo, title="Python Browser", level=win32pdh.PERF_DETAIL_WIZARD):
- win32pdh.BrowseCounters(None,0, callback, level, title)
-
- def test():
print "Virtual Bytes = ", FindPerformanceAttributesByName("python", counter="Virtual Bytes")
print "Available Bytes = ", GetPerformanceAttributes("Memory", "Available Bytes")
! print win32pdh.EnumObjectItems(None,None,"Memory", -1)
!
!
!
if __name__=='__main__':
ShowAllProcesses()
- # test()
print "Browsing for counters..."
browse()
--- 125,133 ----
def browse( callback = BrowseCallBackDemo, title="Python Browser", level=win32pdh.PERF_DETAIL_WIZARD):
print "Virtual Bytes = ", FindPerformanceAttributesByName("python", counter="Virtual Bytes")
print "Available Bytes = ", GetPerformanceAttributes("Memory", "Available Bytes")
!
if __name__=='__main__':
ShowAllProcesses()
print "Browsing for counters..."
browse()
|