Windows性能计数器应用(PART1)

Windows OS中使用计数器来提供有关操作系统或应用程序,服务或驱动程序执行情况的信息。计数器数据可以帮助确定系统资源瓶颈。操作系统,网络和设备提供应用程序可以消耗的计数器数据,以向用户提供系统运行状况的图形视图。

System.Diagnostics命名空间提供了允许您与性能计数器进行交互的类。PerformanceCounter类具有不同的构造函数。在我们的代码中,我们使用以下格式的构造函数:

public PerformanceCounter( string categoryName, string counterName, string instanceName )

参数:

  • categoryName:与此性能计数器关联的性能计数器类别(性能对象)的名称。

  • counterName:性能计数器的名称。

  • i nstanceName:性能计数器类别实例的名称,如果类别包含单个实例,则为空字符串(“”)

此构造函数初始化性能计数器,并将实例与本地计算机上的现有计数器关联。CategoryNameCounterNameInstanceName属性传递的值必须指向本地计算机上的现有性能计数器。

在一些性能计数器下面,以跟踪处理器利用率,磁盘I / O,内存和网络

PerformanceCounter("Processor", "% Processor Time", "_Total");

PerformanceCounter("Processor", "% Privileged Time", "_Total");

PerformanceCounter("Processor", "% Interrupt Time", "_Total");

PerformanceCounter("Processor", "% DPC Time", "_Total");

PerformanceCounter("Memory", "Available MBytes", null);

PerformanceCounter("Memory", "Committed Bytes", null);

PerformanceCounter("Memory", "Commit Limit", null);

PerformanceCounter("Memory", "% Committed Bytes In Use", null);

PerformanceCounter("Memory", "Pool Paged Bytes", null);

PerformanceCounter("Memory", "Pool Nonpaged Bytes", null);

PerformanceCounter("Memory", "Cache Bytes", null);

PerformanceCounter("Paging File", "% Usage", "_Total");

PerformanceCounter("PhysicalDisk", "Avg. Disk Queue Length", "_Total");

PerformanceCounter("PhysicalDisk", "Disk Read Bytes/sec", "_Total");

PerformanceCounter("PhysicalDisk", "Disk Write Bytes/sec", "_Total");

PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Read", "_Total");

PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Write", "_Total");

PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");

PerformanceCounter("Process", "Handle Count", "_Total");

PerformanceCounter("Process", "Thread Count", "_Total");

PerformanceCounter("System", "Context Switches/sec", null);

PerformanceCounter("System", "System Calls/sec", null);

PerformanceCounter("System", "Processor Queue Length", null);

2 性能计数器

2.1 CategoryName:Processor

PerformanceCounter("Processor", "% Processor Time", "_Total");

Processor\% Processor Time计数器确定的时间,所述处理器忙通过测量的空闲进程的线程运行时间的百分比,然后减去由100%的百分比。测算处理器利用率的数量

PerformanceCounter("Processor", "% Interrupt Time", "_Total");

每秒平均突发事件中断数的速率,处理器接收和处理硬件中断的速率。它不包括延迟过程调用,这些过程将单独计算。

PerformanceCounter("Processor", "% DPC Time", "_Total");

在采样间隔内,处理器花费在接收和服务延迟过程调用上的时间百分比。延迟过程调用是优先级低于标准中断的中断。

PerformanceCounter("Processor", "% Privileged Time", "_Total");

在特殊模式下花费的非空闲处理器时间的百分比。特殊模式是一种为操作系统组件和硬件操纵驱动程序设计的处理模式。它允许直接访问硬件和所有内存。替代的用户模式是为应用程序,环境子系统和集成子系统设计的受限处理模式。操作系统将应用程序线程切换到特权模式,以访问操作系统服务。这包括花在服务中断和延迟过程调用(DPC)上的时间。故障设备产生大量中断可能会导致较高的特权时间。此计数器将平均繁忙时间显示为采样时间的百分比。

猜你喜欢

转载自blog.51cto.com/djclouds/2475506
今日推荐