示例#1
0
def devstat():
    if sysctl.sysctl ('kern.devstat.version', 1) != 4:
        raise SystemError("devstat(9) version has changed")
    data = sysctl.sysctl ('kern.devstat.all', 0)
    devices = {}
    for i in range (0, len(data), devstat_size):
        sub = data[i:i + devstat_size]
        if len(sub) != devstat_size:
            # there are an extra four bytes tacked on to the end.
            # don't know what they're about.  padding?  They always
            # seem to be ' \000\000\000'
            break
        else:
            info = struct.unpack (devstat_format, sub)
            ds = devstat_struct()
            (ds.dev_links0, ds.dev_links1,
             device_number, ds.device_name, ds.unit_number,
             ds.bytes_read, ds.bytes_written, ds.bytes_freed,
             ds.num_reads, ds.num_writes, ds.num_frees, ds.num_other,
             ds.busy_count, ds.block_size,
             ds.tag_types0, ds.tag_types1, ds.tag_types2,
             ds.dev_creation_time0, ds.dev_creation_time1,
             ds.busy_time0, ds.busy_time1,
             ds.start_time0, ds.start_time1,
             ds.last_comp_time0, ds.last_comp_time1,
             enums
             ) = info
            ds.cleanup()
            devices[ds.device_name] = ds
    return devices
示例#2
0
def devstat():
    if sysctl.sysctl ('kern.devstat.version', 1) != 4:
        raise SystemError, "devstat(9) version has changed"
    data = sysctl.sysctl ('kern.devstat.all', 0)
    devices = {}
    for i in range (0, len(data), devstat_size):
        sub = data[i:i+devstat_size]
        if len(sub) != devstat_size:
            # there are an extra four bytes tacked on to the end.
            # don't know what they're about.  padding?  They always
            # seem to be ' \000\000\000'
            break
        else:
            info = struct.unpack (devstat_format, sub)
            ds = devstat_struct()
            (ds.dev_links0, ds.dev_links1,
             device_number, ds.device_name, ds.unit_number,
             ds.bytes_read, ds.bytes_written, ds.bytes_freed,
             ds.num_reads, ds.num_writes, ds.num_frees, ds.num_other,
             ds.busy_count, ds.block_size,
             ds.tag_types0, ds.tag_types1, ds.tag_types2,
             ds.dev_creation_time0, ds.dev_creation_time1,
             ds.busy_time0, ds.busy_time1,
             ds.start_time0, ds.start_time1,
             ds.last_comp_time0, ds.last_comp_time1,
             enums
             ) = info
            ds.cleanup()
            devices[ds.device_name] = ds
    return devices
示例#3
0
def get():
    (peak_mbufs, clusters, spare, clfree, drops, wait, drain, mcfail, mpfail,
     msize, mclbytes, minclsize, mlen,
     mhlen) = struct.unpack(14 * 'l', sysctl.sysctl('kern.ipc.mbstat'))
    (max_mbufs, ) = struct.unpack('l', sysctl.sysctl('kern.ipc.nmbufs'))
    (max_mbclusters, ) = struct.unpack('l',
                                       sysctl.sysctl('kern.ipc.nmbclusters'))
    free_mbufs, current_mbufs = get_current_mbufs()
    return locals()
示例#4
0
def get():
    (peak_mbufs, clusters, spare, clfree,
     drops, wait, drain, mcfail, mpfail,
     msize, mclbytes, minclsize, mlen, mhlen
     ) = struct.unpack (14 * 'l', sysctl.sysctl ('kern.ipc.mbstat'))
    (max_mbufs,) = struct.unpack ('l', sysctl.sysctl ('kern.ipc.nmbufs'))
    (max_mbclusters,) = struct.unpack ('l', sysctl.sysctl ('kern.ipc.nmbclusters'))
    free_mbufs, current_mbufs = get_current_mbufs()
    return locals()
示例#5
0
def verify_resource (name, minval):
    try:
        x = sysctl.sysctl (name, 1)
    except:
        raise SystemError("Failed to query sysctl MIB '%s': %s" % (name, tb.traceback_string()))
    else:
        if x < minval:
            raise SystemError(
                "The sysctl MIB '%s' has value '%d', which is less than the required minimum value of '%d'" %
                (name, x, minval))
示例#6
0
def verify_resource(name, minval):
    try:
        x = sysctl.sysctl(name, 1)
    except:
        raise SystemError, "Failed to query sysctl MIB '%s': %s" % (
            name, tb.traceback_string())
    else:
        if x < minval:
            raise SystemError, "The sysctl MIB '%s' has value '%d', which is less than the required minimum value of '%d'" % (
                name, x, minval)
示例#7
0
def get_current_mbufs():
    data = sysctl.sysctl('kern.ipc.mbtypes')
    nelems = len(data) / 4
    nums = struct.unpack(nelems * 'l', data)
    free = nums[0]
    return free, reduce(operator.add, nums[1:])
示例#8
0
BEWARE!  THIS WILL DESTROY ANYTHING ON THAT DEVICE OR FILE!
"""

USING_LISTIO = 0
MAX_LIO = 0

try:
    import lio_listio
except ImportError:
    if hasattr(coro, 'lio_read'):
        USING_LISTIO = 1
    else:
        USING_LISTIO = 0

if USING_LISTIO:
    MAX_LIO = sysctl.sysctl('p1003_1b.aio_listio_max', 1)
    if MAX_LIO:
        USING_LISTIO = 1
    else:
        USING_LISTIO = 0

# 512 bytes
DISK_BLOCK_SIZE = (1<<9)
DISK_BLOCK_MASK = ((1<<9)-1)

# fall 512 bytes shy of a full 64K, this will avoid wasting an entire
# 32K malloc block to hold the extra 24 bytes of Python object
# overhead.
MAX_LIO_SIZE = ((64 * 1024) - DISK_BLOCK_SIZE)

assert ((MAX_LIO_SIZE % DISK_BLOCK_SIZE) == 0)
示例#9
0
def get_current_mbufs():
    data = sysctl.sysctl ('kern.ipc.mbtypes')
    nelems = len(data) / 4
    nums = struct.unpack (nelems * 'l', data)
    free = nums[0]
    return free, reduce (operator.add, nums[1:])