home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.7)
-
- import win32pdh
- import time
- error = win32pdh.error
- counter_english_map = { }
-
- def find_pdh_counter_localized_name(english_name, machine_name = None):
- if not counter_english_map:
- import win32api
- import win32con
- counter_reg_value = win32api.RegQueryValueEx(win32con.HKEY_PERFORMANCE_DATA, 'Counter 009')
- counter_list = counter_reg_value[0]
- for i in xrange(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))
- hq = win32pdh.OpenQuery()
-
- try:
- hc = win32pdh.AddCounter(hq, path)
-
- try:
- win32pdh.CollectQueryData(hq)
- (type, val) = win32pdh.GetFormattedCounterValue(hc, format)
- return val
- finally:
- win32pdh.RemoveCounter(hc)
-
- finally:
- win32pdh.CloseQuery(hq)
-
-
-
- def FindPerformanceAttributesByName(instanceName, object = None, counter = None, format = win32pdh.PDH_FMT_LONG, machine = None, bRefresh = 0):
- 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:
- win32pdh.EnumObjects(None, machine, 0, 1)
- instanceName = instanceName.lower()
- (items, instances) = win32pdh.EnumObjectItems(None, None, object, -1)
- instance_dict = { }
- for instance in instances:
-
- try:
- instance_dict[instance] = instance_dict[instance] + 1
- continue
- except KeyError:
- instance_dict[instance] = 0
- continue
-
-
-
- ret = []
- for instance, max_instances in instance_dict.iteritems():
- for inum in xrange(max_instances + 1):
- if instance.lower() == instanceName:
- ret.append(GetPerformanceAttributes(object, counter, instance, inum, format, machine))
- continue
-
- return ret
-
-
- def ShowAllProcesses():
- object = find_pdh_counter_localized_name('Process')
- (items, instances) = win32pdh.EnumObjectItems(None, None, object, win32pdh.PERF_DETAIL_WIZARD)
- instance_dict = { }
- for instance in instances:
-
- try:
- instance_dict[instance] = instance_dict[instance] + 1
- continue
- except KeyError:
- instance_dict[instance] = 0
- continue
-
-
-
- items = [
- find_pdh_counter_localized_name('ID Process')] + items[:5]
- print 'Process Name', ','.join(items)
- for instance, max_instances in instance_dict.iteritems():
- for inum in xrange(max_instances + 1):
- hq = win32pdh.OpenQuery()
- hcs = []
- for item in items:
- path = win32pdh.MakeCounterPath((None, object, instance, None, inum, item))
- hcs.append(win32pdh.AddCounter(hq, path))
-
- win32pdh.CollectQueryData(hq)
- time.sleep(0.01)
- win32pdh.CollectQueryData(hq)
- print '%-15s\t' % instance[:15],
- for hc in hcs:
- (type, val) = win32pdh.GetFormattedCounterValue(hc, win32pdh.PDH_FMT_LONG)
- print '%5d' % val,
- win32pdh.RemoveCounter(hc)
-
- print
- win32pdh.CloseQuery(hq)
-
-
-
-
- def BrowseCallBackDemo(counter):
- (machine, object, instance, parentInstance, index, counterName) = win32pdh.ParseCounterPath(counter)
- result = GetPerformanceAttributes(object, counterName, instance, index, win32pdh.PDH_FMT_DOUBLE, machine)
- print "Value of '%s' is" % counter, result
- print "Added '%s' on object '%s' (machine %s), instance %s(%d)-parent of %s" % (counterName, object, machine, instance, index, parentInstance)
-
-
- def browse(callback = BrowseCallBackDemo, title = 'Python Browser', level = win32pdh.PERF_DETAIL_WIZARD):
- win32pdh.BrowseCounters(None, 0, callback, level, title)
-
- if __name__ == '__main__':
- ShowAllProcesses()
- counter = find_pdh_counter_localized_name('Virtual Bytes')
- print 'Virtual Bytes = ', FindPerformanceAttributesByName('python', counter = counter)
- print 'Available Bytes = ', GetPerformanceAttributes(find_pdh_counter_localized_name('Memory'), find_pdh_counter_localized_name('Available Bytes'))
- print 'Browsing for counters...'
- browse()
-