简体   繁体   English

Visual Studio探查器[clr.dll]

[英]visual studio profiler [clr.dll]

I'm trying to profile a .NET application in Visual Studio using the build-in profiler. 我正在尝试使用内置探查器在Visual Studio中探查.NET应用程序。 Tracking CPU samples, I come across something weird. 跟踪CPU样本,我遇到了一些奇怪的事情。 In a part of the application I have the following (simplified for clarity): 在应用程序的一部分中,我具有以下内容(为清楚起见已简化):

var requestObject = new RequestObject(parameters);
var result = GetResult(requestObject,"stringvalue");

I see that the second row uses about 10% of the samples. 我看到第二行使用了大约10%的样本。 However, the method ´GetResult()´ only uses about 7%, the rest seems to be in [clr.dll]. 但是,方法“ GetResult()”仅使用约7%,其余似乎在[clr.dll]中。 I know clr.dll is responsible for garbage collection, JIT compiling, context switching etc, and the ´GetResult()´ method is fairly complex (spanning multiple assemblies, possibly using multiple threads) so it's not implausible that some of these actions need to be taken once the method returns. 我知道clr.dll负责垃圾收集,JIT编译,上下文切换等,并且“ GetResult()”方法相当复杂(跨多个程序集,可能使用多个线程),因此其中某些动作需要方法返回后立即采取。 The ´RequestObject´ is also a bit complex so that might have something to do with it. “ RequestObject”也有点复杂,因此可能与它有关。

My question is: Can I track down exactly what happens here, and what can I do to make it faster? 我的问题是:我可以准确跟踪一下这里发生了什么,如何做才能使其更快? Note that 3% does not sound much, but ´GetResult()´ will be called a lot of times during the programs lifespan, even though when testing it is only run once. 请注意,3%听起来并不多,但是在程序生命周期中将多次调用“ GetResult()”,即使在测试时仅运行一次。 And it is very important that I can reduce the response time of the application. 减少应用程序的响应时间非常重要。

Thanks a lot in advance for any answers! 提前非常感谢您提供任何答案!

You're not alone in trying to figure out what the profiler output means. 您并非一个人试图弄清楚探查器输出的含义。 SO has many questions like that. 所以有很多这样的问题。 I work in a big .net app, and I've tried various profilers, and I know it's not what people are taught, but what actually works is this method . 我在大型.net应用程序中工作,并且尝试了各种探查器,但我知道这不是人们要教的,但实际上有效的是这种方法 For one thing, you can take some samples during initialization, and other samples during basic run time. 一方面,您可以在初始化期间进行一些采样,而在基本运行时进行其他采样。 You don't have to pile the two together and try to guess what the load would be like in each phase without the other. 您不必将两者叠加在一起,而不必猜测每个阶段的负载情况。

Also, if you look only at CPU time, you will miss any speedup opportunities due to extra I/O. 另外,如果仅查看CPU时间,由于额外的I / O,您将错过任何提速机会。 You should not assume there isn't any, or that it's insignificant. 您不应该假设没有任何东西,或者它是无关紧要的。 If you do manage to find a CPU-only speedup opportunity, and fix it, then the part you didn't find becomes a larger fraction of the whole. 如果您确实设法找到了仅CPU加速的机会并加以解决,那么您找不到的部分将占整体的很大一部分。 You could get to a point where if you can't find anything else to fix, you might assume there is nothing else, when in fact there is, and it could be large. 您可能会发现,如果找不到其他要修复的东西,您可能会假设没有其他东西,而实际上有其他东西,而且可能很大。 If you take samples yourself, you get a clear view of what's costing time. 如果您自己取样,则可以清楚地了解所花费的时间。

You might want to say "But that's not accurate!" 您可能要说“但这不准确!” Well, OK, if there's something you could fix, and fixing it would save 90% of the time, but your inquiry is inaccurate and says it's taking 80%, or 95%, does that prevent you from fixing it and getting the 10-times speedup? 好吧,好的,如果您可以修复某些问题,并且修复它可以节省90%的时间,但是您的查询不准确,并说它占用了80%或95%的信息,这会阻止您修复它并获得10-倍加速? The fact is, when your goal is to actually find problems, rather than just measure them, the bigger they are, the fewer samples it takes. 事实是,当您的目标是实际发现问题而不是仅仅解决问题时,问题越大,样本数量就越少。

You may be interested in using the PerfView tool that is available for free download. 您可能对使用免费下载的PerfView工具感兴趣。 I agree with Mike that in this scenario (of a web-request) CPU might not be the dominate factor, so using a CPU profiler could easily be inaccurate. 我同意Mike的观点,在这种情况下(基于Web请求)CPU可能不是主要因素,因此使用CPU Profiler可能很不准确。 PerfView can do CPU analsysis, but it has the ability to do 'wall clock' analysis too (see the 'Wall Clock / Blocked time' link on PerfView's welcome page). PerfView可以进行CPU分析,但是它也可以进行“挂钟”分析(请参阅PerfView的欢迎页面上的“壁钟/阻塞时间”链接)。 This view shows BOTH CPU and blocking but takes more care in interpreting the data (you have to find the right thread and include the segment of thread of interest). 该视图显示了CPU和阻塞两种情况,但是在解释数据时要格外小心(您必须找到正确的线程并包括感兴趣的线程段)。 If this is an ASP.NET application there is a special view (the ASP.NET Thread Time Stacks), that is of particular interest (also in the docs). 如果这是ASP.NET应用程序,则会有一个特殊的视图(ASP.NET线程时间堆栈),该视图特别有意义(在文档中也是如此)。

The bad news is that there is no substitute for understanding what your profiler is telling you, so you will have to spend some time learning what this tool is showing you. 坏消息是,除了了解您的探查器告诉您的内容外,别无他法,因此您将不得不花一些时间来学习此工具向您显示的内容。 I think it is more then worth it and there are PerfView Videos , and reasonably good documentation built into the tool to help you out, but you have to be willing to invest some time (eg an hour). 我认为这是值得的,并且PerfView视频和该工具中内置的相当不错的文档可以帮助您,但是您必须愿意花一些时间(例如一个小时)。

The good news is that the payoff is for your investment is non-trivial. 好消息是,为您的投资带来的回报是不平凡的。 You should be able to figure out your particular problem within an hour, and with a few hours of investment you will be able to figure a broad variety of issues in pretty much any application (even ones you did not build). 您应该能够在一小时内解决您的特定问题,并且只需花费几个小时的投资,您就可以解决几乎所有应用程序(甚至是您未构建的应用程序)中的各种问题。 The tool is very powerful, but with power comes lots of potential avenues of investigation, and with it the ability to misuse the data and become confused. 该工具功能非常强大,但功能强大,带来了许多潜在的调查途径,并且具有滥用数据并引起混乱的能力。

this post is old but I wanted to clarify a few things. 这篇文章很旧,但我想澄清一些事情。 In the current implementation of the profiler whenever you see [], it means we know the name of the dll but were unable to resolve symbols for it. 在探查器的当前实现中,只要看到[],就意味着我们知道dll的名称,但无法为其解析符号。 One reason is that you did not select the microsoft symbol servers in your sysmbol settings. 原因之一是您没有在sysmbol设置中选择Microsoft符号服务器。 Another possibility is that the module was ngen (wherein you will see []). 另一种可能性是该模块是ngen(在其中您将看到[])。 In that case you will need to generate the ngen pdb to actually get symbols resolved. 在这种情况下,您将需要生成ngen pdb才能真正解析符号。 Once that occurs you should be able to see exacly what functions are using what fraction of the cpu. 一旦发生这种情况,您应该就能清楚地看到哪些功能正在使用cpu的哪一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM