代码之家  ›  专栏  ›  技术社区  ›  One Developer

性能计数器?

  •  2
  • One Developer  · 技术社区  · 15 年前

    我想监视内存(RAM)和物理磁盘的性能,Perfmon中我必须监视的所有计数器是什么?

    2 回复  |  直到 15 年前
        1
  •  2
  •   John Knoeller    15 年前
        2
  •  0
  •   Joshua Hayes    14 年前

    您没有说明您使用的是托管代码还是非托管代码。如果是后者,可以使用 像这样初始化它。

    Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
    PerformanceCounter pc = new PerformanceCounter();
    pc.CategoryName = "Process";
    pc.CounterName = "Working Set - Private";
    pc.InstanceName = currentProcess.ProcessName;
    var myProcessMemoryUsage = (long)pc.NextValue();
    

    PerformanceCounter pcRam = new PerformanceCounter();
    pcRam.CategoryName = "Memory";
    pcRam.CounterName = "Available MBytes";
    int mem = (int)pcRam.NextValue();
    

    此计数器将以兆字节为单位显示计算机上可用的RAM数量。

    您可以查看性能监视器本身中的所有性能计数器。您应该能够同时看到类别和计数器名称。