使用 SQL 的 Visual Studio 2010 探查器
我正在使用 Visual Studio 2010 的内置分析器来查看性能不佳的代码部分。然而,我看到一些不太有意义的结果。这是报告的截图:
这似乎表明 Regex.Replace 是瓶颈(因此我应该尽量减少或消除这种使用)。然而,这感觉不准确,因为我知道这个特定的代码部分正在大量使用数据库,因此我预计 SqlCommand.ExecuteNonQuery 在这份报告中至少会更高一点,如果不是比正则表达式更占主导地位的话使用。
所以,我的问题是:这个分析器工具对于涉及数据库访问的任何事情都是无用的,因为 SQL 工作是由另一个进程(即 SQL 服务器)完成的,因此我必须以其他方式来测量它?
I'm using Visual Studio 2010's built-in profiler to look at a section of poorly performing code. However, I'm seeing some results that don't quite make sense. Here is a shot of the report:
This seems to indicate that Regex.Replace is the bottleneck (and I should therefore try to reduce or eliminate this use as much as possible). However, this feels inaccurate, as I know that this particular section of code is making heavy use of the database, and thus I would expect the SqlCommand.ExecuteNonQuery to be at least a little higher in this report, if not more dominant than the Regex use.
So, my question is: is this profiler tool useless for anything involving database access, since the SQL work is being done by another process (i.e. the SQL server), and therefore I have to measure it some other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Visual Studio 探查器有两种操作模式:采样和检测。
在采样模式下,与 I/O 一样,当它被阻塞时,它不会采样。
因此,除了叶子正在执行原始 CPU 处理的部分之外,它无法向您显示调用树的任何部分。
您正在使用采样模式。尝试使用仪器模式,该模式根据挂钟时间运行,因此包含 I/O。
无论你做什么,请忽略专属时间。仅注意包含时间,即占总时间的百分比。
您正在代码中寻找在大部分时间内处于活动状态的例程,其中大部分时间都花在调用其他例程上,
而您正在寻找不需要的电话。
PS我这样做这个 ,这总是有效的。
The Visual Studio profiler has two modes of operation, sampling and instrumentation.
In sampling mode, it does not draw samples when it is blocked, as for I/O.
Because of that, it cannot show you any part of the call tree except that in which the leaves are doing raw CPU processing.
You are using sampling mode. Try the instrumentation mode, which operates on wall-clock time, thus it includes I/O.
And whatever you do, please ignore exclusive time. Only pay attention to inclusive time, as a percent of total time.
You are looking for routines in your code that are active a large fraction of time, most of it spent in calling other routines,
and you are looking for the calls you can do without.
P.S. I do this, which always works.
在我看来,关于 SQL 工作,您对 Visual Studio 探查器的假设是正确的。
为了检查您的 SQL 工作,更好的选择是运行 SQL Profiler 并跟踪您的查询。您可以设置 SQL 探查器,以显示应用程序中所有传入查询(...针对相关数据库)的执行计划。这将表明这是您的 SQL 工作还是如快照所示的 Regex.Replace 工作。
哈萨尼
In my opinion, your assumption about Visual Studio's profiler is correct, regarding the SQL work.
In order to check your SQL work, a better option would be to run SQL Profiler and track your queries. You can setup the SQL profiler, to show the execution plans of all incoming queries (...for the relevant database(s) ) from your application. That will indicate whether it's your SQL work or as the snapshot suggests Regex.Replace.
Hasanain
Visual Studio 分析器是一个CPU 分析器。 CPU Profiler 对于分析 CPU 密集型程序或 IO 密集型程序的 CPU 密集部分非常有用。以下是这些术语的介绍:
由于您的进程是 I/O 限制,CPU 分析器不会帮助您使程序运行得更快。正如您所怀疑的,您必须使用其他工具来分析 SQL 查询,例如:
或许多其他工具之一。
The Visual Studio Profiler is a CPU Profiler. CPU Profilers are useful for analyzing CPU-bound programs or CPU-bound portions of IO-bound programs. Here are introductions to those terms:
Since your process is I/O-bound, a CPU profiler will not help you make your program run faster. As you suspected, you will have to profile the SQL query using other tools such as the:
or one of many other tools.
您可能还会发现“层交互分析”选项对于使用 Visual Studio 2010 分析器调查 SQL 问题很有用。您可以在性能向导的第 3 页上启用此选项,或者作为会话属性的一部分启用此选项(请参阅 我们的博客获取屏幕截图)。
使用此模式收集数据后,切换到“层交互”视图,您将看到有关 SQL 调用的详细信息,包括调用计数和运行时间(图片来自分析器博客)
You might also find the 'Tier Interaction Profiling' option useful for investigating SQL issues with the Visual Studio 2010 profiler. You can enable this option on page 3 of the Performance Wizard or as part of the session properties (see our blog for screenshots).
Once you have collected data using this mode, switch to the 'Tier Interactions' view and you will see detailed information about SQL calls, including call counts and elapsed times (picture from profiler blog)