• Print

Author Topic: Memory performance information (Windows)  (Read 250 times)

mcalkins

  • Hero Member
  • *****
  • Posts: 1279
    • qbasicmichael.com
    • Email
Memory performance information (Windows)
« on: November 30, 2012, 01:52:41 AM »
PERFORMANCE_INFORMATION might need manual padding on Win64.

Code: [Select]
'public domain

' http://msdn.microsoft.com/en-us/library/aa965225(v=vs.85).aspx

DECLARE DYNAMIC LIBRARY "kernel32"
 FUNCTION GetCurrentProcess~%& ()
 FUNCTION GetLastError~& ()
 FUNCTION GlobalMemoryStatusEx& (BYVAL lpBuffer~%&)
END DECLARE

DECLARE DYNAMIC LIBRARY "psapi"
 FUNCTION GetPerformanceInfo& (BYVAL pPerformanceInformation~%&, BYVAL cb~&)
 FUNCTION GetProcessMemoryInfo& (BYVAL Process~%&, BYVAL ppsmemCounters~%&, BYVAL cb~&)
END DECLARE

TYPE PROCESS_MEMORY_COUNTERS_EX ' http://msdn.microsoft.com/en-us/library/ms684874(v=vs.85).aspx
 cb AS _UNSIGNED LONG
 PageFaultCount AS _UNSIGNED LONG
 PeakWorkingSetSize AS _UNSIGNED _OFFSET
 WorkingSetSize AS _UNSIGNED _OFFSET
 QuotaPeakPagedPoolUsage AS _UNSIGNED _OFFSET
 QuotaPagedPoolUsage AS _UNSIGNED _OFFSET
 QuotaPeakNonPagedPoolUsage AS _UNSIGNED _OFFSET
 QuotaNonPagedPoolUsage AS _UNSIGNED _OFFSET
 PagefileUsage AS _UNSIGNED _OFFSET
 PeakPagefileUsage AS _UNSIGNED _OFFSET
 PrivateUsage AS _UNSIGNED _OFFSET
END TYPE

TYPE MEMORYSTATUSEX ' http://msdn.microsoft.com/en-us/library/aa366770(v=vs.85).aspx
 dwLength AS _UNSIGNED LONG
 dwMemoryLoad AS _UNSIGNED LONG
 ullTotalPhys AS _UNSIGNED _INTEGER64
 ullAvailPhys AS _UNSIGNED _INTEGER64
 ullTotalPageFile AS _UNSIGNED _INTEGER64
 ullAvailPageFile AS _UNSIGNED _INTEGER64
 ullTotalVirtual AS _UNSIGNED _INTEGER64
 ullAvailVirtual AS _UNSIGNED _INTEGER64
 ullAvailExtendedVirtual AS _UNSIGNED _INTEGER64
END TYPE

TYPE PERFORMANCE_INFORMATION ' http://msdn.microsoft.com/en-us/library/ms684824(v=vs.85).aspx
 cb AS _UNSIGNED LONG
 CommitTotal AS _UNSIGNED _OFFSET
 CommitLimit AS _UNSIGNED _OFFSET
 CommitPeak AS _UNSIGNED _OFFSET
 PhysicalTotal AS _UNSIGNED _OFFSET
 PhysicalAvailable AS _UNSIGNED _OFFSET
 SystemCache AS _UNSIGNED _OFFSET
 KernelTotal AS _UNSIGNED _OFFSET
 KernelPaged AS _UNSIGNED _OFFSET
 KernelNonpaged AS _UNSIGNED _OFFSET
 PageSize AS _UNSIGNED _OFFSET
 HandleCount AS _UNSIGNED LONG
 ProcessCount AS _UNSIGNED LONG
 ThreadCount AS _UNSIGNED LONG
END TYPE

DIM hMe AS _UNSIGNED _OFFSET
DIM pmc AS PROCESS_MEMORY_COUNTERS_EX
DIM ms AS MEMORYSTATUSEX
DIM pi AS PERFORMANCE_INFORMATION
pmc.cb = LEN(pmc) ' should be 44 on Win32
ms.dwLength = LEN(ms) ' should be 64 on Win32
pi.cb = LEN(pi) ' should be 56 on Win32
hMe = GetCurrentProcess ' should be -1 on current versions of Windows.

WIDTH 80, 43
DO UNTIL LEN(INKEY$)
 CLS
 PRINT "GetProcessMemoryInfo"
 IF 0 = GetProcessMemoryInfo(hMe, _OFFSET(pmc), pmc.cb) THEN
  PRINT "Failed. Error: 0x" + hexd(GetLastError)
 ELSE
  PRINT "PageFaultCount", "0x" + hexd(pmc.PageFaultCount), pmc.PageFaultCount
  PRINT "PeakWorkingSetSize", "0x" + hexp(pmc.PeakWorkingSetSize), pmc.PeakWorkingSetSize; "bytes"
  PRINT "WorkingSetSize", "0x" + hexp(pmc.WorkingSetSize), pmc.WorkingSetSize; "bytes"
  PRINT "QuotaPeakPagedPoolUsage", "0x" + hexp(pmc.QuotaPeakPagedPoolUsage), pmc.QuotaPeakPagedPoolUsage; "bytes"
  PRINT "QuotaPagedPoolUsage", "0x" + hexp(pmc.QuotaPagedPoolUsage), pmc.QuotaPagedPoolUsage; "bytes"
  PRINT "QuotaPeakNonPagedPoolUsage", "0x" + hexp(pmc.QuotaPeakNonPagedPoolUsage), pmc.QuotaPeakNonPagedPoolUsage; "bytes"
  PRINT "QuotaNonPagedPoolUsage", "0x" + hexp(pmc.QuotaNonPagedPoolUsage), pmc.QuotaNonPagedPoolUsage; "bytes"
  PRINT "PagefileUsage", , "0x" + hexp(pmc.PagefileUsage), pmc.PagefileUsage; "bytes"
  PRINT "PeakPagefileUsage", "0x" + hexp(pmc.PeakPagefileUsage), pmc.PeakPagefileUsage; "bytes"
  PRINT "PrivateUsage", , "0x" + hexp(pmc.PrivateUsage), pmc.PrivateUsage; "bytes"
 END IF
 PRINT
 PRINT "GlobalMemoryStatusEx"
 IF 0 = GlobalMemoryStatusEx(_OFFSET(ms)) THEN
  PRINT "Failed. Error: 0x" + hexd(GetLastError)
 ELSE
  PRINT "dwMemoryLoad", , STR$(ms.dwMemoryLoad); "%"
  PRINT "ullTotalPhys", , "0x" + hexq(ms.ullTotalPhys), ms.ullTotalPhys; "bytes"
  PRINT "ullAvailPhys", , "0x" + hexq(ms.ullAvailPhys), ms.ullAvailPhys; "bytes"
  PRINT "ullTotalPageFile", "0x" + hexq(ms.ullTotalPageFile), ms.ullTotalPageFile; "bytes"
  PRINT "ullAvailPageFile", "0x" + hexq(ms.ullAvailPageFile), ms.ullAvailPageFile; "bytes"
  PRINT "ullTotalVirtual", "0x" + hexq(ms.ullTotalVirtual), ms.ullTotalVirtual; "bytes"
  PRINT "ullAvailVirtual", "0x" + hexq(ms.ullAvailVirtual), ms.ullAvailVirtual; "bytes"
  PRINT "ullAvailExtendedVirtual", "0x" + hexq(ms.ullAvailExtendedVirtual), ms.ullAvailExtendedVirtual
 END IF
 PRINT
 PRINT "GetPerformanceInfo"
 IF 0 = GetPerformanceInfo(_OFFSET(pi), pi.cb) THEN
  PRINT "Failed. Error: 0x" + hexd(GetLastError)
 ELSE
  PRINT "CommitTotal", , "0x" + hexp(pi.CommitTotal), pi.CommitTotal; "pages"
  PRINT "CommitLimit", , "0x" + hexp(pi.CommitLimit), pi.CommitLimit; "pages"
  PRINT "CommitPeak", , "0x" + hexp(pi.CommitPeak), pi.CommitPeak; "pages"
  PRINT "PhysicalTotal", , "0x" + hexp(pi.PhysicalTotal), pi.PhysicalTotal; "pages"
  PRINT "PhysicalAvailable", "0x" + hexp(pi.PhysicalAvailable), pi.PhysicalAvailable; "pages"
  PRINT "SystemCache", , "0x" + hexp(pi.SystemCache), pi.SystemCache; "pages"
  PRINT "KernelTotal", , "0x" + hexp(pi.KernelTotal), pi.KernelTotal; "pages"
  PRINT "KernelPaged", , "0x" + hexp(pi.KernelPaged), pi.KernelPaged; "pages"
  PRINT "KernelNonpaged", "0x" + hexp(pi.KernelNonpaged), pi.KernelNonpaged; "pages"
  PRINT "PageSize", , "0x" + hexp(pi.PageSize), pi.PageSize; "bytes"
  PRINT "HandleCount", , "0x" + hexd(pi.HandleCount), pi.HandleCount
  PRINT "ProcessCount", , "0x" + hexd(pi.ProcessCount), pi.ProcessCount
  PRINT "ThreadCount", , "0x" + hexd(pi.ThreadCount), pi.ThreadCount
 END IF
 SLEEP 1
LOOP

'$include:'hexx.bi' ' http://www.qb64.net/forum/index.php?topic=4491.0

Regards,
Michael
« Last Edit: November 30, 2012, 01:57:48 AM by mcalkins »
The QBASIC Forum Community: http://www.network54.com/index/10167 Includes off-topic subforums.
QB64 Off-topic subforum: http://qb64offtopic.freeforums.org/

  • Print