找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 6741|回复: 2

Understanding Profiling Methods(VS2010)

[复制链接]
发表于 2010-5-23 14:51:17 | 显示全部楼层 |阅读模式
Understanding Profiling Methods


Microsoft Visual Studio Premium Profiling Tools provide five methods that you can use to collect performance data. This topic describes the different methods and suggests some scenarios in which collecting data with a particular method can be appropriate.

Method
Description
Sampling
Collects statistical data about the work performed by an application.
Instrumentation
Collects detailed timing information about each function call.
Concurrency
Collects detailed information about multi-threaded applications.
.NET memory
Collects detailed information about .NET memory allocation and garbage collection.
Tier interaction
Collects information about asynchronous ADO.NET function calls to a SqlServer database.

By using some of the profiling methods, you can also collect additional data, such as software and hardware performance counters. For more information, see Collecting Additional Performance Data.

Sampling

The sampling profiling method collects statistical data about the work that is performed by an application during a profiling run. The sampling method is lightweight and has little effect on the execution of the application methods.
Sampling is the default method of the Microsoft Visual Studio Premium Profiling Tools. It is useful for the following:
  • Initial explorations of the performance of your application.
  • Investigating performance issues that involve the utilization of the processor (CPU).
The sampling profiling method interrupts the computer processor at set intervals and collects the function call stack. Exclusive sample counts are incremented for the function that is executing and inclusive counts are incremented for all of the calling functions on the call stack. Sampling reports present the totals of these counts for the profiled module, function, source code line, and instruction.
By default, the profiler sets the sampling interval to CPU cycles. You can change the interval type to another CPU performance counter and you can set the number of counter events for the interval. You can also collect tier interaction profiling(TIP) data that provides information about the queries that are made to a SQL server database through ADO.NET.
Collecting Performance Statistics by Using Sampling
Understanding Sampling Data Values in Profiling Tools
Profiler Sampling Method Data Views

Instrumentation

The instrumentation profiling method collects detailed timing for the function calls in a profiled application. Instrumentation profiling is useful for the following:
  • Investigating input/output bottlenecks such as disk I/O.
  • Close examination of a particular module or set of functions.
The instrumentation method injects code into a binary file that captures timing information for each function in the instrumented file and each function call that is made by those functions. Instrumentation also identifies when a function calls into the operating for operations such as writing to a file. Instrumentation reports use four values to represent the total time spent in a function or source code line:
  • Elapsed Inclusive - The total time that is spent executing the function or source line.
  • Application Inclusive - The time that is spent executing the function or source line, but excluding time that is spent in calls to the operating system.
  • Elapsed Exclusive - The time that is spent executing code in the body of the function or source code line. Time that is spent executing functions that are called by the function or source line is excluded.
  • Application Exclusive - The time that is spent executing code in the body of the function or source code line. Time that is spent executing calls to the operating system and time that is spent executing functions that are called by the function or source line is excluded.
You can also collect both CPU and software performance counters by using the instrumentation method.
Understanding Instrumentation Data Values in Profiling Tools
Collecting Detailed Timing Data by Using Instrumentation
Profiler Instrumentation Method Data Views


Concurrency

Concurrency profiling collects information about multithreaded applications. Resource contention profiling collects detailed call stack information every time that competing threads are forced to wait for access to a shared resource. Concurrency visualization also collects more general information about how your multithreaded application interacts with itself, the hardware, the operating system, and other processes on the host computer:
  • Resource contention reports display the total number of contentions and the total time that was spent waiting for a resource for the modules, functions, source code lines, and instructions in which the waiting occurred. Timeline graphs also show the contentions as they occurred.
  • The concurrency visualizer displays graphical information that you can use to locate performance bottlenecks, CPU underutilization, thread contention, thread migration, synchronization delays, areas of overlapped I/O, and other information. When possible, the graphical output links to call stack and source code data. Concurrency visualization data can be collected only for command line and Windows applications.
Understanding Resource Contention Data Values in Profiling Tools
Collecting Thread and Process Concurrency Data
Resource Contention Data Views
Concurrency Visualizer

.NET Memory

The .NET memory allocation profiling method interrupts the computer processor at each allocation of a .NET Framework object in a profiled application. When object lifetime data is also collected, the profiler interrupts the processor after each .NET Framework garbage collection.
The profiler collects information about the type, size, and number of objects that were created in an allocation or were destroyed in a garbage collection.
  • When an allocation event occurs, the profiler collects additional information about the function call stack. Exclusive allocation counts are incremented for the function that is currently executing and inclusive counts are incremented for all the calling functions on the call stack. .NET reports present the totals of these counts for the profiled types, modules, functions, source code lines, and instructions.
  • When a garbage collection occurs, the profiler collects data about the objects that were destroyed and information about the objects in each garbage collection generation. At the end of the profiling run, the profiler records data about the objects that were not explicitly destroyed. The Object Lifetime report displays the totals for each type that was allocated in the profiling run.
.NET memory profiling can be used in either sampling or instrumentation mode. The mode that you select does not affect the Allocation and Object Lifetime reports that are unique to.NET memory profiling:
  • When you run .NET memory profiling in sampling mode, the profiler.NET uses memory allocation events as the interval and displays the number of objects that were allocated and the total bytes that were allocated as the inclusive and exclusive values in the reports.
  • When you run .NET memory profiling in instrumentation mode, detailed timing information is collected together with the inclusive and exclusive allocation values.
Understanding Memory Allocation and Object Lifetime Data Values in Profiling Tools
Collecting .NET Memory Allocation and Lifetime Data
Profiling Tools .NET Memory Data Views

Tier Interaction

Tier-interaction profiling adds information to a profiling data file about synchronous ADO.NET calls between an ASP.NET page or other application and a SQL Server database. Data includes the number and time of calls, and the maximum and minimum times. Tier-interaction data can be added to profiling data that is collected with the sampling, instrumentation, .NET memory, or concurrency methods.
Tier interaction data that is collected by Profiling Tools

How to: Collect Tier Interaction Data
Tier Interaction Views
 楼主| 发表于 2010-5-23 14:51:58 | 显示全部楼层
简单的摘要了几点信息
Sampling
定时中断CPU查看函数调用堆栈。代价较小
Exclusive sample 函数正在执行增加计数
Inclusive count   函数处于堆栈调用中增加计数
Instrumentation
注入代码到二进制文件中,捕捉函数调用的时间信息。
1.        Elapsed Inclusive所有时间
2.        Application Inclusive排除操作系统调用
3.        Elapsed Exclusive排除函数调用
4.        Application Exclusive排除函数调用与操作系统调用
Concurrency
在每次竞争线程被迫等待访问共享资源时,收集详细的调用堆栈信息
.NET memory
中断并收集信息,在对象分配,垃圾回收时。
Tier Interaction
同步ADO.NET调用ASP.NET页之间或其他应用程序和SQL Server数据库。

[ 本帖最后由 modern 于 2010-5-23 14:56 编辑 ]
 楼主| 发表于 2010-5-23 14:56:27 | 显示全部楼层
研究了一段时间,感觉确实如微软自己所说Sampling是比较推荐的办法,
相较于VS2008,VS2010结果报告分析与展示要友好很多。

[ 本帖最后由 modern 于 2010-5-23 15:02 编辑 ]
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-11-23 17:33 , Processed in 0.019382 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表