<<返回目录

Performance Counters(性能计数器)

性能计数器是监视应用程序和系统性能的最简单的方法之一。它有几十个类别数百个计数器在,包括一些.net特有的计数器。要访问这些可以通过系统自带的 性能监控程序(perfmon.exe)来实现。

图1-2。是PerfMon的主要窗口,它显示一个小的时间段内处理器计数器。垂直线表示当前实例,默认情况下100秒钟后图形将换行。

图1-3。这是很多类别里的其中一个计数器,还显示了适用这个计数器的应用实例。

每个计数器都有一个类别和一个名称。 很多计数器还可以选择对应的进程。 例如,对于Process类别中的%Processor Time计数器,实例可以是各种进程。 一些计数器还具有元实例,例如_Total或,它实际上是所有实例上的汇总值。

后面的很多章节将详细介绍相关主题对应的计数器。几乎每个Windows子系统都有对应的性能计数器,这些计数器通常适用于每个程序。
但是,在继续之前,您应该熟悉一些基本的操作系统相关的计数器:

• Physical Memory—The actual physical memory chips in a computer. Only the operating system manages physical memory directly.

• Virtual Memory—A logical organization of memory in a given process. Virtual memory size can be larger than physical memory. For example, 32-bit programs have a 4 GB address space, even if the computer itself only has 2 GB of RAM. Windows allows the program to access only 2 GB of that by default, but all 4 GB is possible if the executable is large-address aware. (On 32-bit versions of Windows, large-address aware programs are limited to 3 GB.) As of Windows 8.1 and Server 2012, 64-bit processes have a 128 TB process space, far larger than the 4 TB physical memory limit. Some of the virtual memory may be in RAM while other parts are stored on disk in a paging file. Contiguous blocks of virtual memory may not be contiguous in physical memory. All memory addresses in a process are for the virtual memory.

• Reserved Memory—A region of virtual memory address space that has been reserved for the process and thus will not be allocated to a future requester. Reserved memory cannot be used for memory allocation requests because there is nothing backing it—it is just a description of a range of memory addresses.
•Committed Memory—A region of memory that has a physical backing store. This can be RAM or disk.
•Page—An organizational unit of memory. Blocks of memory are allocated in a page, which is usually a few KB in size.

• Paging—The process of transferring pages between regions of virtual memory. The page can move to or from another process (soft paging) or the disk (hard paging). Soft paging can be accomplished very quickly by mapping the existing memory into the current process’s virtual address space. Hard paging involves a relatively slow transfer of data to or from disk. Your program must avoid this at all costs to maintain good performance.

• Page In—Transfer a page from another location to the current process.

• Page Out—Transfer a page from the current process to another location, such as disk.

• Context Switch—The process of saving and restoring the state of a thread or process. Because there are usually more running threads than available processors, there are often many context switches per second.

• Kernel Mode—A mode that allows the OS to modify low-level aspects of the hardware’s state, such as modifying certain registers or enabling/disabling interrupts. Transitioning to Kernel Mode requires an operating system call, and can be quite expensive.

• User Mode—An unprivileged mode of executing instructions. There is no ability to modify low-level aspects of the system.

以上的我翻译过一次,感觉都不通常,所以还是不翻了,懂的看前面单词就知道什么意思,不懂的百度一下也就知道了。

以下是我将在整本书中使用的一些计数器,特别是在第2章讨论垃圾回收时。 当然如果你想了解相关主题的更多信息,请查看专门介绍操作系统的书,如Windows Internals。 (见附录C中的参考书目)
以下的计数器内容涵盖了进程常用的计数器,它可以详细记录每个进程的数据:

• % Privileged Time—Amount of time spent in executing privileged (kernel mode) code.

• % Processor Time—Percentage of a single processor the application is using. If your application is using two logical processor cores at 100% each, then this counter will read 200.

• % User Time—Amount of time spent in executing unprivileged (user mode) code.

• IO Data Bytes/sec—How much I/O your process is doing.

• Page Faults/sec—Total number of page faults in your process. A page fault occurs when a page of memory is missing from the current working set. It is important to realize that this number includes both soft and hard page faults. Soft page faults are innocuous and can be caused by the page being in memory, but outside the current process (such as for shared DLLs). Hard page faults are more serious, indicating data that is on disk but not currently in memory. Unfortunately, you cannot track hard page faults per process with performance counters, but you can see it for the entire system with the Memory\Page Reads/sec counter. You can do some correlation with a process’s total page faults plus the system’s overall page reads (hard faults). You can definitively track a process’s hard faults with ETW tracing with the Windows Kernel/Memory/Hard Fault event.

• Pool Nonpaged Bytes—Typically operating system and driver allocated memory for data structures that cannot be paged out such as operating system objects like threads and mutexes, but also custom data structures.

• Pool Paged Bytes—Also for operating system data structures, but these are allowed to be paged out.
Private Bytes—Committed virtual memory private to the specific process (not shared with any other processes).

• Virtual Bytes—Allocated memory in the process’s address space, some of which may be backed by the page file, shared with other processes, and memory private to the process.

• Working Set—The amount of virtual memory currently resident in physical memory (usually RAM).

• Working Set-Private—The amount of private bytes currently resident in physical memory.

• Thread Count—The number of threads in the process. This may or may not be equal to the number of .NET threads. See Chapter 4 (Asynchronous Programming) for a discussion of .NET thread-related counters.

根据应用还有一些有用的分类。 您可以使用PerfMon来探索在这些特别的分类。

• IPv4/IPv6—Internet Protocol-related counters for datagrams and fragments.

• Memory—System-wide memory counters such as overall paging, available bytes, committed bytes, and much more.

• Objects—Data about kernel-owned objects such as events, mutexes, processes, threads, semaphores, and sections.

• Processor—Counters for each logical processor in the system.

• System—Context switches, alignment fixes, file operations, process count, threads, and more.

• TCPv4/TCPv6—Data for TCP connections and segment transfers

还是那句话,我翻译过一遍发现太丑陋了就不放出来了,特别是当我翻译完下面的文字的时候。

令人惊讶的是,在互联网里没有找到关于性能计数器的详细介绍,但幸运的是,PrefMon自己有完善的记录,在PrefMon工具里的“添加计数器”对话框中,可以选中底部的“显示描述”框以突出显示计数器的详细信息。

你说你不是坑爹吗,你既然都有描述说明了,干嘛不直接开放出来,非得点勾选一个选项才出来。

PrefMon还能够设置时间定时启动性能计数器,并存储在日志中供以后查看,甚至在计数器超过阈值时执行自定义操作。它不仅限于性能计数器数据的收集,还可以收集系统配置数据和ETW事件数据。

让我们启动性能监视器,设置一次数据收集器

  1. 展开“数据收集器集”树
  2. 右键单击“用户定义”
  3. 选择“新建”
  4. 选择“数据收集器集”

5.给它一个名称,选中“手动创建(高级)”,然后单击下一步

6.检查“创建数据日志”下的性能计数器框,然后单击下一步

7.单击添加以选择要包括的计数器

8.单击下一步设置要存储日志的路径,然后单击下一步直到选择结束

完成后,您可以打开收集器的属性,并设置收集计划。也可以通过右键单击作业节点并选择开始来手动运行。 这将创建一个报表(应该是文件吧),可以通过在主树视图中的“报告--用户定义”下节点来查看。

图1-7。 已保存的报告文件。 使用工具栏按钮将视图更改为收集时的计数器数据的图形。

要创建警报,请执行相同的过程,在向导中选择“性能计数器警报”选项。
使用此处描述的功能可能需要执行性能计数器所需的一切,但如果要采取控制或创建自己的计数器,请参阅第7章(性能计数器)了解详细信息。 您应该将性能计数器分析视为应用程序的所有性能工作的基准。

[翻译]编写高性能 .NET 代码 第一章:工具介绍 -- Performance Counters(性能计数器)的更多相关文章

  1. [翻译]编写高性能 .NET 代码 第一章:工具介绍 -- Visual Studio

    <<返回目录 Visual Studio vs虽然不是全宇宙唯一的IDE,但它是.net开发人员最常用的开发工具.它自带一个性能分析工具,你可以使用它来做开发,不同的vs版本在工具上会略有 ...

  2. [翻译]编写高性能 .NET 代码 第一章:性能测试与工具 -- 平均值 vs 百分比

    <<返回目录 平均值 vs 百分比 在考虑要性能测试的目标值时,我们需要考虑用什么统计口径.大多数人都会首选平均值,但在大多数情况下,这个正确的,但你也应该适当的考虑百分数.但你有可用性的 ...

  3. [翻译] 编写高性能 .NET 代码--第二章 GC -- 减少分配率, 最重要的规则,缩短对象的生命周期,减少对象层次的深度,减少对象之间的引用,避免钉住对象(Pinning)

    减少分配率 这个几乎不用解释,减少了内存的使用量,自然就减少GC回收时的压力,同时降低了内存碎片与CPU的使用量.你可以用一些方法来达到这一目的,但它可能会与其它设计相冲突. 你需要在设计对象时仔细检 ...

  4. [翻译]编写高性能 .NET 代码 第二章:垃圾回收

    返回目录 第二章:垃圾回收 垃圾回收是你开发工作中要了解的最重要的事情.它是造成性能问题里最显著的原因,但只要你保持持续的关注(代码审查,监控数据)就可以很快修复这些问题.我这里说的"显著的 ...

  5. [翻译] 编写高性能 .NET 代码--第二章 GC -- 避免使用终结器,避免大对象,避免复制缓冲区

    避免使用终结器 如果没有必要,是不需要实现一个终结器(Finalizer).终结器的代码主要是让GC回收非托管资源用.它会在GC完成标记对象为可回收后,放入一个终结器队列里,在由另外一个线程执行队列里 ...

  6. [翻译] 编写高性能 .NET 代码--第二章 GC -- 将长生命周期对象和大对象池化

    将长生命周期对象和大对象池化 请记住最开始说的原则:对象要么立即回收要么一直存在.它们要么在0代被回收,要么在2代里一直存在.有些对象本质是静态的,生命周期从它们被创建开始,到程序停止才会结束.其它对 ...

  7. [翻译] 编写高性能 .NET 代码--第二章 GC -- 减少大对象堆的碎片,在某些情况下强制执行完整GC,按需压缩大对象堆,在GC前收到消息通知,使用弱引用缓存对象

    减少大对象堆的碎片 如果不能完全避免大对象堆的分配,则要尽量避免碎片化. 对于LOH不小心就会有无限增长,但LOH使用的空闲列表机制可以减轻增长的影响.利用这个空闲列表,我们可以在两块分配区域中间找到 ...

  8. [翻译]编写高性能 .NET 代码 第二章:垃圾回收 基本操作

    返回目录 基本操作 垃圾回收的算法细节还在不断完善中,性能还会有进一步的提升.下文介绍的内容在不同的.NET版本里会略有不同,但大方向是不会有变动的. 在.net进程里会管理2个类型的内存堆:托管和非 ...

  9. [翻译] 编写高性能 .NET 代码--第二章 GC -- 配置选项

    配置选项 在基于"less rope to hang yourself with"思想下,.NET 框架没有给开发提供很多太多的配置选项.但在大多数情况下,GC会跟你的硬件配置,及 ...

随机推荐

  1. Java多线程异常处理

    在java多线程程序中,所有线程都不允许抛出未捕获的checked exception,也就是说各个线程需要自己把自己的checked exception处理掉.这一点是通过java.lang.Run ...

  2. xml报错 Parse Fatal Error :在实体引用中,实体名称必须紧跟在'&'后面

    修改jndi配置文件中的密码后,重启tomcat报错如下  实际问题是xml中默认’&’是非法字符,用     &   替代

  3. eclipse导入项目之后报错

    一.项目本身就有错 二.jdk版本的问题 参考网址:http://jingyan.baidu.com/article/95c9d20da3ec5fec4e756186.html 从别的地方导入一个项目 ...

  4. 2017年 JavaScript 框架回顾 -- 后端框架

    本文是2017年 JavaScript 框架回顾系列的最后的一篇文章,主要介绍 JavaScript 的后端框架情况. 从上图中可以看到,Express 作为用 JavaScript 编写的后端服务的 ...

  5. [转]sysctl -P 报错解决办法

    问题症状 修改 linux 内核文件 #vi /etc/sysctl.conf后执行sysctl  -P 报错 error: "net.bridge.bridge-nf-call-ip6ta ...

  6. python_判断变量类型

    需求: 已知有一个变量,我想对他进行预处理判断,如果这个变量是字符串,则在字符串后面加上后缀'_str',如果整形就让其加5,还比如我要求这个变量是整形或者字符串,都行 如何做? #!/usr/bin ...

  7. 通过编程为Outlook 2007添加邮件规则

    Outlook 所支持的邮件规则相当有用,我们经常需要针对某些特征的邮件做特殊的处理.例如将其移动到某个特定文件夹,或者删除它等等. Outlook所支持的邮件规则主要两大类:收到邮件时和发送邮件时 ...

  8. Spring MVC 基础笔记

    spring mvc功能: 以Controller为中心完成对系统流程的控制管理 从请求中搜集数据 对传入的参数进行验证 将结果返回给视图 针对不同的视图提供不同的解决方案 针对jsp视图技术提供标签 ...

  9. NetCloud——一个网易云音乐评论抓取和分析的Python库

    在17的四月份,我曾经写了一篇关于网易云音乐爬虫的文章,还写了一篇关于评论数据可视化的文章.在这大半年的时间里,有时会有一些朋友给我发私信询问一些关于代码方面的问题.所以我最近抽空干脆将原来的代码整理 ...

  10. iOS项目——基本框架搭建

    项目开发过程中,在完成iOS项目——项目开发环境搭建之后,我们首先需要考虑的就是我们的项目的整体框架与导航架构设计,然后在这个基础上考虑功能模块的完成. 一 导航架构设计 一款App的导航架构设计应该 ...