Finding SC_PAGE_SIZE using Python in Windows
Asked Answered
C

4

6

I'm working in this mixed environment where I'm on a Windows machine using Simics and Cygwin to run some code in a unix like environment. I've been coding in C but I'm interested in trying to do my solution in Python. In the unix environment to find the SC_PAGE_SIZE you can simply do:

#Python-2.7, unix environment
page_size = os.sysconf("SC_PAGE_SIZE")

If you're coding in c you can do:

#C, unix environment
size_t page_size = (size_t) sysconf (_SC_PAGESIZE);

However when using python in Windows os.sysconf doesn't exist and I've been unable to find a replacement. What can I use in python to find the PAGE_SIZE of the environment.

A side note, I know you may wonder why I'm using the setup as it is and it's not my choice. It's an homework assignment from work. The question I'm asking is for my own benefit it's not for the homework.

Coinage answered 12/1, 2012 at 20:30 Comment(0)
C
13

Try:

import mmap

print mmap.PAGESIZE
Coelenterate answered 7/12, 2012 at 1:32 Comment(0)
W
1

I am not a system expert so I don't what correspond to SC_PAGE_SIZE on windows. Hovever, you can use WMI to query the system performance.

Here is an example that should give a lot of things. May you find what you are looking for:

import win32com.client

import unicodedata
def _(text):
    if type(text) is unicode:
        return unicodedata.normalize('NFKD', text).encode('ascii','ignore')
    return text

def to_kb(x):
    if x:
        return int(x)/1024
    return x

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")


for objItem in colItems:
    print "------------------------------------------"
    print "Command Line: ", _(objItem.CommandLine)
    print "Process Id: ", objItem.ProcessId

    print "Handle: ", objItem.Handle
    print "Handle Count: ", objItem.HandleCount
    print "Maximum Working Set Size: ", to_kb(objItem.MaximumWorkingSetSize)
    print "Minimum Working Set Size: ", to_kb(objItem.MinimumWorkingSetSize)
    print "Page Faults: ", objItem.PageFaults
    print "PageFile Usage: ", objItem.PageFileUsage
    print "Peak PageFile Usage: ", objItem.PeakPageFileUsage
    print "Peak Virtual Size: ", objItem.PeakVirtualSize
    print "Peak Working Set Size: ", objItem.PeakWorkingSetSize
    print "Private Page Count: ", objItem.PrivatePageCount
    print "Quota NonPaged Pool Usage: ", objItem.QuotaNonPagedPoolUsage
    print "Quota Paged Pool Usage: ", objItem.QuotaPagedPoolUsage
    print "Quota Peak NonPaged Pool Usage: ", objItem.QuotaPeakNonPagedPoolUsage
    print "Quota Peak Paged Pool Usage: ", objItem.QuotaPeakPagedPoolUsage
    print "Virtual Size: ", objItem.VirtualSize
    print "Working Set Size: ", to_kb(objItem.WorkingSetSize)
    print "Write Operation Count: ", objItem.WriteOperationCount
    print "Write Transfer Count: ", objItem.WriteTransferCount
Whose answered 12/1, 2012 at 20:56 Comment(2)
Unfortunately this is finding a lot of information on all the processes currently running but not the operating systems paging size. Thanks for the try but I'll keep looking.Coinage
wmi is the way to access system perf. sorry that you don't get the right data. does it worth a downvote? :)Whose
C
1

The only equivalent I could find was in C but if I compile the code and then execute it from python I can get the result I was looking for. Unfortunately as of right now there doesn't seem to be a python command that works in Windows that is as simple as the unix version but this at least gives me a result.

int main(void) {
        SYSTEM_INFO si;
        GetSystemInfo(&si);

        printf("%u", si.dwPageSize);

        return 0;
}
Coinage answered 11/10, 2012 at 6:55 Comment(0)
S
0

It is possible to do it with ctypes module:

from ctypes import Structure, byref, windll
from ctypes.wintypes import WORD, DWORD, LPVOID


class SYSTEM_INFO(Structure):
    _fields_ = [
        ("wProcessorArchitecture", WORD),
        ("wReserved", WORD),
        ("dwPageSize", DWORD),
        ("lpMinimumApplicationAddress", LPVOID),
        ("lpMaximumApplicationAddress", LPVOID),
        ("dwActiveProcessorMask", DWORD),
        ("dwNumberOfProcessors", DWORD),
        ("dwProcessorType", DWORD),
        ("dwAllocationGranularity", DWORD),
        ("wProcessorLevel", WORD),
        ("wProcessorRevision", WORD),
    ]


si = SYSTEM_INFO()
windll.kernel32.GetSystemInfo(byref(si))
print(si.dwPageSize)
Sedimentology answered 15/1, 2018 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.