【问题标题】:C# - Differentiate between hard and soft page faults by using the WMIC# - 使用 WMI 区分硬页错误和软页错误
【发布时间】:2016-04-28 15:10:26
【问题描述】:

我已经构建了一个监控服务器的 C# 程序。监控包括捕获有关服务器的详细信息,例如内存空间、磁盘空间等。

这是使用 WMI 完成的。

我也在监控每台服务器的页面错误。

我想知道是否可以区分 C# 中的硬页面错误和软页面错误?

这是我正在使用的代码片段:

        var machine = "machine";

        // get the scope of the remote server
        var scope = new ManagementScope(@"\\" + machine + @"\root\cimv2");

        // the query as a string
        var queryString = "Select Name, ProcessId, PageFaults from win32_Process";

        // the query as an object
        var query = new ObjectQuery(queryString);

        // Run the query
        var worker = new ManagementObjectSearcher(scope, query);
        var results = worker.Get();

        pageFaults.WriteLine(machine);

        // Enumerate around each item in the results query
        foreach (ManagementObject item in results)
        {
            totalPages = totalPages + (int)(UInt32)item["PageFaults"];
        }
        Console.WriteLine("Total pages = {0}", totalPages);
        pageFaults.WriteLine("*{0}*",totalPages);

【问题讨论】:

  • 你能解释一下你对软页面错误的含义吗?它的术语往往具有多种含义,具体取决于您询问的对象。我会假设您的意思类似于 TLB 未命中?
  • 您无法为特定进程获取硬故障。接下来最好的是the Memory performance counters。页面错误是软+硬,页面读取是硬。
  • 感谢您的回复。硬页错误:“当页不在物理内存或进程创建的内存映射文件中时,会发生硬页错误。”软页面错误“当页面驻留在内存中的其他位置时会发生软页面错误。”我将继续使用我拥有的代码,因为我想要整个服务器的页面错误。我的硬/软定义来源是:blogs.technet.microsoft.com/askperf/2008/06/10/…

标签: windows c#-4.0 wmi-query get-wmiobject


【解决方案1】:

如果您正在尝试单个处理页面错误/秒,您可以使用下面提到的查询。正如汉斯之前指出的那样,这个页面错误是硬+软的。但是这些表会经常更新,如果我没记错的话,perfmon 也会显示相同的数据。

select * from Win32_PerfFormattedData_PerfProc_Process where NOT name = '_Total'

对于累积

select * from Win32_PerfFormattedData_PerfProc_Process where name = '_Total'

【讨论】:

    猜你喜欢
    • 2012-07-19
    • 2012-09-07
    • 2016-11-13
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 2014-03-29
    相关资源
    最近更新 更多