本文整理汇总了Python中win32pdh.RemoveCounter方法的典型用法代码示例。如果您正苦于以下问题:Python win32pdh.RemoveCounter方法的具体用法?Python win32pdh.RemoveCounter怎么用?Python win32pdh.RemoveCounter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32pdh
的用法示例。
在下文中一共展示了win32pdh.RemoveCounter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetPerformanceAttributes
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def GetPerformanceAttributes(object, counter, instance=None,
inum=-1, format=None, machine=None):
# NOTE: Many counters require 2 samples to give accurate results,
# including "% Processor Time" (as by definition, at any instant, a
# thread's CPU usage is either 0 or 100). To read counters like this,
# you should copy this function, but keep the counter open, and call
# CollectQueryData() each time you need to know.
# See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp (dead link)
# My older explanation for this was that the "AddCounter" process forced
# the CPU to 100%, but the above makes more sense :)
import win32pdh
if format is None:
format = win32pdh.PDH_FMT_LONG
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)
示例2: GetPerformanceAttributes
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def GetPerformanceAttributes(object, counter, instance=None,
inum=-1, format=None, machine=None):
# NOTE: Many counters require 2 samples to give accurate results,
# including "% Processor Time" (as by definition, at any instant, a
# thread's CPU usage is either 0 or 100). To read counters like this,
# you should copy this function, but keep the counter open, and call
# CollectQueryData() each time you need to know.
# See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
# My older explanation for this was that the "AddCounter" process forced
# the CPU to 100%, but the above makes more sense :)
import win32pdh
if format is None:
format = win32pdh.PDH_FMT_LONG
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)
示例3: GetPerformanceAttributes
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def GetPerformanceAttributes(object, counter, instance = None, inum=-1,
format = win32pdh.PDH_FMT_LONG, machine=None):
# NOTE: Many counters require 2 samples to give accurate results,
# including "% Processor Time" (as by definition, at any instant, a
# thread's CPU usage is either 0 or 100). To read counters like this,
# you should copy this function, but keep the counter open, and call
# CollectQueryData() each time you need to know.
# See http://support.microsoft.com/default.aspx?scid=kb;EN-US;q262938
# and http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
# My older explanation for this was that the "AddCounter" process forced
# the CPU to 100%, but the above makes more sense :)
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)
示例4: GetPerformanceAttributes
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def GetPerformanceAttributes(object, counter, instance = None,
inum=-1, format = None, machine=None):
# NOTE: Many counters require 2 samples to give accurate results,
# including "% Processor Time" (as by definition, at any instant, a
# thread's CPU usage is either 0 or 100). To read counters like this,
# you should copy this function, but keep the counter open, and call
# CollectQueryData() each time you need to know.
# See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
# My older explanation for this was that the "AddCounter" process forced
# the CPU to 100%, but the above makes more sense :)
import win32pdh
if format is None: format = win32pdh.PDH_FMT_LONG
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)
示例5: close
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def close(self):
for hc in self.hcs:
if not hc:
continue
try:
win32pdh.RemoveCounter(hc)
except:
pass
self.hcs = []
for hq in self.hqs:
if not hq:
continue
try:
win32pdh.CloseQuery(hq)
except:
pass
self.hqs = []
示例6: killbase
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def killbase(self,base=None):
'''
### This is not a public method
Mission critical function to kill the win32pdh objects held
by this object. User's should generally use the close method
instead of this method, in case a sub-class has overridden
close to provide some special functionality.
'''
# Kill Pythonic references to the objects in this object's namespace
self._base = None
counters = self.counters
self.counters = []
# we don't kill the curpaths for convenience, this allows the
# user to close a query and still access the last paths
self.active = 0
# Now call the delete functions on all of the objects
try:
map(win32pdh.RemoveCounter,counters)
except:
pass
try:
win32pdh.CloseQuery(base)
except:
pass
del(counters)
del(base)
示例7: ShowAllProcesses
# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import RemoveCounter [as 别名]
def ShowAllProcesses():
object = find_pdh_counter_localized_name("Process")
items, instances = win32pdh.EnumObjectItems(None,None,object,
win32pdh.PERF_DETAIL_WIZARD)
# Need to track multiple instances of the same name.
instance_dict = {}
for instance in instances:
try:
instance_dict[instance] = instance_dict[instance] + 1
except KeyError:
instance_dict[instance] = 0
# Bit of a hack to get useful info.
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)
# as per http://support.microsoft.com/default.aspx?scid=kb;EN-US;q262938, some "%" based
# counters need two collections
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)
# NOTE: This BrowseCallback doesn't seem to work on Vista for markh.
# XXX - look at why!?