GetSystemFileCacheSize

GetSystemFileCacheSize

本文介绍了如何在 Windows 上找到当前的系统缓存大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索了高低,但无法找到 API 调用来检索 Windows 上(文件)系统缓存的当前大小.

GlobalMemoryStatusEx - 检索 Total、Free、Used 和 Swap 统计数据.

GetSystemFileCacheSize - 返回它可能的最小值和最大值,不是很有帮助.

我还尝试了 Windows 扩展,它返回了下面的无用数字.看起来它可能是 1mb 到 2gb 的任何地方?

>>>导入 win32api>>>win32api.GetSystemFileCacheSize()(1048576L, 2143289344L, 0L)

获取此信息的正确 API 调用是什么?我在任务管理器中看到它可用,所以它必须在某个地方?这是屏幕截图和我要查找的数字:

更喜欢 python 解决方案,但 C/C++ 会有很大帮助.

解决方案

我终于弄明白了:

import ctypespsapi = ctypes.WinDLL('psapi')类 PERFORMANCE_INFORMATION(ctypes.Structure):''' Windows 结构体 .GetPerformanceInfo().http://msdn.microsoft.com/en-us/library/ms683210'''_DWORD = ctypes.c_ulong_SIZE_T = ctypes.c_size_t_字段_ = [('cb', _DWORD),('CommitTotal', _SIZE_T),('CommitLimit', _SIZE_T),('CommitPeak', _SIZE_T),('PhysicalTotal', _SIZE_T),('PhysicalAvailable', _SIZE_T),('系统缓存', _SIZE_T),('内核总数', _SIZE_T),('KernelPaged', _SIZE_T),('KernelNonpaged', _SIZE_T),('页面大小', _SIZE_T),('句柄计数', _DWORD),('ProcessCount', _DWORD),('线程计数', _DWORD),]def __init__(self, getinfo=True, *args, **kwds):super(PERFORMANCE_INFORMATION, self).__init__(ctypes.sizeof(self), *args, **kwds)如果(获取信息而不是psapi.GetPerformanceInfo(ctypes.byref(self),self.cb)):引发 WinError()@财产def cache_info(self):返回 self.SystemCache * self.PageSizedef get_cache_info():返回 PERFORMANCE_INFORMATION().cache_info如果 __name__ == '__main__':打印(get_cache_info())

Searched high and low but haven't been able to find an API call to retrieve the current size of the (File) System Cache on Windows.

GlobalMemoryStatusEx - retrieves the Total, Free, Used, and Swap stats.

GetSystemFileCacheSize - returns the Minimum and Maximum it could be, not very helpful.

I also tried the Windows extensions, which returned the unhelpful numbers below. Looks like it could be anywhere from 1mb to 2gb?

>>> import win32api
>>> win32api.GetSystemFileCacheSize()
(1048576L, 2143289344L, 0L)

What is the correct API call to get this information? I see it available in the task manager, so it must be in there somewhere? Here's a screen shot and the numbers I'm looking for:

Would prefer a python solution, but C/C++ would help a lot.

解决方案

I did finally figure it out:

import ctypes
psapi = ctypes.WinDLL('psapi')

class PERFORMANCE_INFORMATION(ctypes.Structure):
    ''' Struct for Windows .GetPerformanceInfo().
        http://msdn.microsoft.com/en-us/library/ms683210
    '''

    _DWORD = ctypes.c_ulong
    _SIZE_T = ctypes.c_size_t

    _fields_ = [
        ('cb', _DWORD),
        ('CommitTotal', _SIZE_T),
        ('CommitLimit', _SIZE_T),
        ('CommitPeak', _SIZE_T),
        ('PhysicalTotal', _SIZE_T),
        ('PhysicalAvailable', _SIZE_T),
        ('SystemCache', _SIZE_T),
        ('KernelTotal', _SIZE_T),
        ('KernelPaged', _SIZE_T),
        ('KernelNonpaged', _SIZE_T),
        ('PageSize', _SIZE_T),
        ('HandleCount', _DWORD),
        ('ProcessCount', _DWORD),
        ('ThreadCount', _DWORD),
    ]

    def __init__(self, getinfo=True, *args, **kwds):
        super(PERFORMANCE_INFORMATION, self).__init__(
              ctypes.sizeof(self), *args, **kwds)
        if (getinfo and not
            psapi.GetPerformanceInfo(ctypes.byref(self),
                                     self.cb)):
            raise WinError()

    @property
    def cache_info(self):
        return self.SystemCache * self.PageSize

def get_cache_info():
    return PERFORMANCE_INFORMATION().cache_info

if __name__ == '__main__':
    print(get_cache_info())

这篇关于如何在 Windows 上找到当前的系统缓存大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:58