Re: Getting Peak Commit from NtQuerySystemInformation
Thomas Heller <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Mike Driscoll schrieb:
> Hi,
>
> I was tasked with finding a way to query our workstations for their Peak
> Commit Charge. According to the sysinternals forum:
>
> "The only way I'm aware of that one can get this detail is from the
> uMmPeakCommitLimit member of the SYSTEM_PERFORMANCE_INFORMATION
> structure one passes to NtQuerySystemInformation when calling it with
> the SystemPerformanceInformation type." (see
> http://forum.sysinternals.com/forum_posts.asp?TID=15540&PID=75852)
>
> I started with this question on the PyWin32 mailing list, but it turns
> out that they don't expose the functionality inside
> NtQuerySystemInformation so that's why I came here. Unfortunately, I'm a
> complete newb when it comes to ctypes. While I did find that this worked
> "ctypes.windll.ntdll.NtQuerySystemInformation", I don't know how to go
> on and actually query the object. Can someone give me a clue?
>
> I'm running Python 2.5 on Windows XP. Thanks!
Not really tested, but seems to work:
<snip>
from ctypes import *
SystemBasicInformation = 0
SystemPerformanceInformation = 2
class SYSTEM_BASIC_INFORMATION(Structure):
_fields_ = [("Reserved1", c_long * 10),
("NumberOfProcessors", c_byte),
("bUnknown2", c_byte),
("bUnknown3", c_short)
]
class SYSTEM_PERFORMANCE_INFORMATION(Structure):
_fields_ = [("IdleTime", c_int64),
("ReadTransferCount", c_int64),
("WriteTransferCount", c_int64),
("OtherTransferCount", c_int64),
("ReadOperationCount", c_ulong),
("WriteOperationCount", c_ulong),
("OtherOperationCount", c_ulong),
("AvailablePages", c_ulong),
("TotalCommittedPages", c_ulong),
("TotalCommitLimit", c_ulong),
("PeakCommitment", c_ulong),
("PageFaults", c_ulong),
("WriteCopyFaults", c_ulong),
("TransitionFaults", c_ulong),
("Reserved1", c_ulong),
("DemandZeroFaults", c_ulong),
("PagesRead", c_ulong),
("PageReadIos", c_ulong),
("Reserved2", c_ulong * 2),
("PagefilePagesWritten", c_ulong),
("PagefilePageWriteIos", c_ulong),
("MappedFilePagesWritten", c_ulong),
("MappedFilePageWriteIos", c_ulong),
("PagedPoolUsage", c_ulong),
("NonPagedPoolUsage", c_ulong),
("PagedPoolAllocs", c_ulong),
("PagedPoolFrees", c_ulong),
("NonPagedPoolAllocs", c_ulong),
("NonPagedPoolFrees", c_ulong),
("TotalFreeSystemPtes", c_ulong),
("SystemCodePage", c_ulong),
("TotalSystemDriverPages", c_ulong),
("TotalSystemCodePages", c_ulong),
("SmallNonPagedLookasideListAllocateHits", c_ulong),
("SmallPagedLookasideListAllocateHits", c_ulong),
("Reserved3", c_ulong),
("MmSystemCachePage", c_ulong),
("PagedPoolPage", c_ulong),
("SystemDriverPage", c_ulong),
("FastReadNoWait", c_ulong),
("FastReadWait", c_ulong),
("FastReadResourceMiss", c_ulong),
("FastReadNotPossible", c_ulong),
("FastMdlReadNoWait", c_ulong),
("FastMdlReadWait", c_ulong),
("FastMdlReadResourceMiss", c_ulong),
("FastMdlReadNotPossible", c_ulong),
("MapDataNoWait", c_ulong),
("MapDataWait", c_ulong),
("MapDataNoWaitMiss", c_ulong),
("MapDataWaitMiss", c_ulong),
("PinMappedDataCount", c_ulong),
("PinReadNoWait", c_ulong),
("PinReadWait", c_ulong),
("PinReadNoWaitMiss", c_ulong),
("PinReadWaitMiss", c_ulong),
("CopyReadNoWait", c_ulong),
("CopyReadWait", c_ulong),
("CopyReadNoWaitMiss", c_ulong),
("CopyReadWaitMiss", c_ulong),
("MdlReadNoWait", c_ulong),
("MdlReadWait", c_ulong),
("MdlReadNoWaitMiss", c_ulong),
("MdlReadWaitMiss", c_ulong),
("ReadAheadIos", c_ulong),
("LazyWriteIos", c_ulong),
("LazyWritePages", c_ulong),
("DataFlushes", c_ulong),
("DataPages", c_ulong),
("ContextSwitches", c_ulong),
("FirstLevelTbFills", c_ulong),
("SecondLevelTbFills", c_ulong),
("SystemCalls", c_ulong)]
sbi = SYSTEM_BASIC_INFORMATION()
retlen = c_ulong()
res = windll.ntdll.NtQuerySystemInformation(SystemBasicInformation,
byref(sbi),
sizeof(sbi),
byref(retlen))
print res, retlen
print sbi.NumberOfProcessors
spi = SYSTEM_PERFORMANCE_INFORMATION()
retlen = c_ulong()
res = windll.ntdll.NtQuerySystemInformation(SystemPerformanceInformation,
byref(spi),
sizeof(spi),
byref(retlen))
print res, retlen
print spi.PeakCommitment
</snip>
--
Thanks,
Thomas
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev