当程序响应缓慢时,该程序正在做什么?

Pau*_*ulH 2 c# performance

我在Windows 8.1 x64上使用C#.NET 4.0应用程序需要很长时间(18秒)才能执行某些操作.我想尝试诊断为什么会发生这种情况.Process Monitor跟踪显示:

??????????????????????????????????????????????????????????
? Relative Time ?               Operation                ?
??????????????????????????????????????????????????????????
? 00:02.000000  ? Thread Create                          ?
? 00:02.000100  ? Thread Create                          ?
? 00:04.000000  ? Thread Create                          ?
? 00:04.000100  ? Thread Create                          ?
? 00:04.000200  ? Thread Create                          ?
? 00:04.000300  ? Thread Exit                            ?
? 00:04.000400  ? Thread Create                          ?
? 00:04.000500  ? TCP Disconnect                         ?
? 00:04.000600  ? Thread Exit                            ?
? 00:06.000000  ? Thread Create                          ?
? 00:06.000100  ? Thread Create                          ?
? 00:06.000200  ? Thread Create                          ?
? 00:06.000300  ? Thread Create                          ?
? 00:06.000400  ? Thread Create                          ?
? 00:07.000000  ? Thread Exit                            ?
? 00:10.000000  ? Thread Create                          ?
? 00:11.500000  ? CreateFile                             ?
?               ? // read the file contents              ?
? 00:11.540000  ? CloseFile                              ?
? 00:11.541000  ? CreateFile                             ?
?               ? // read the file contents              ?
? 00:11.600000  ? CloseFile                              ?
? 00:12.100000  ? Thread Exit                            ?
? 00:19.000000  ? Thread Exit                            ?
? 00:20.000000  ? Thread Exit                            ?
?               ? // from here on things respond quickly ?
??????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

有几个很大的差距,我想更好地了解该计划正在做什么.假设我可以获得符号(但可能不是源代码),我能做些什么来更好地理解正在发生的事情?我愿意使用WinDbg或Windows性能监视器.我只是想从哪些工具开始,以便缩小这些特定的差距.

Bra*_*NET 7

更好的选择是通过分析器简单地运行程序.Visual Studio有一个很好的,它在"Analyze"菜单下(至少在VS 2012中).

使用分析器将向您显示正在占用所有时间的代码,直至单个方法调用.使用您拥有的信息/工具,获取此信息将非常困难.