IntelliTrace 功能(C#、Visual Basic、C++)IntelliTrace Features (C#, Visual Basic, C++)

可以使用 IntelliTrace 记录事件和调用应用程序的方法,它让你能够在执行中的不同位置检查其状态(调用堆栈和局部变量值)。You can use IntelliTrace to record events and method calls your application, which allows you to examine its state (call stack and local variable values) at different points in the execution. 正常启动调试即可,默认启用 IntelliTrace,并且可以在“事件”选项卡下的新“诊断工具”窗口中看到 IntelliTrace 正在记录的信息 。选择一个事件,然后单击“激活历史调试”以查看为此事件记录的调用堆栈和局部变量。Just start debugging as usual - IntelliTrace is turned on by default, and you can see the information IntelliTrace is recording in the new Diagnostic Tools window under the Events tab. Select an event and click Activate Historical Debugging to see the call stack and locals recorded for this event.

有关分步说明,请参阅演练:使用 IntelliTraceFor a step-by-step description, see Walkthrough: Using IntelliTrace.

Visual Studio Enterprise 版中提供 IntelliTrace,但 Visual Studio Professional 或 Community 版中不提供。IntelliTrace is available in Visual Studio Enterprise edition, but not in the Visual Studio Professional or Community editions.

若要确认 IntelliTrace 已启用,请打开“工具”>“选项”>“IntelliTrace”选项页。To confirm that IntelliTrace is turned on, open the Tools > Options > IntelliTrace options page. 默认情况下应选中“启用 IntelliTrace”。Enable IntelliTrace should be checked by default.

备注

“IntelliTrace”选项页上的所有设置都针对 Visual Studio 这个整体,而不针对单个项目或解决方案。The scope of all settings on the IntelliTrace options page is Visual Studio as a whole, not individual projects or solutions. 这些设置中的更改适用于 Visual Studio 的所有实例、所有调试会话和所有项目或解决方案。A change in these settings applies to all instances of Visual Studio, all debugging sessions and all projects or solutions.

选择 IntelliTrace 记录的事件(C#、Visual Basic)Choose the events that IntelliTrace records (C#, Visual Basic)

可以启用或禁用针对特定 IntelliTrace 事件的记录。You can turn on or off recording for specific IntelliTrace events.

如果在进行调试,请停止调试。If you're debugging, stop debugging. 转到“工具”>“选项”>“IntelliTrace”>“IntelliTrace 事件”。Go to Tools > Options > IntelliTrace > IntelliTrace Events. 选择想要 IntelliTrace 记录的事件。Choose the events you want IntelliTrace to record.

收集快照(C#、Visual Basic、C++)Collect snapshots (C#, Visual Basic, C++)

默认情况下不启用此功能,但 IntelliTrace 可以在每个断点和调试器单步执行事件中捕获应用程序的快照,可以在历史调试会话中查看这些快照。This isn't enabled by default, but IntelliTrace can capture snapshots of your application at every breakpoint and debugger step event, and you can view these snapshots in a historical debugging session. 快照提供完整应用程序状态的视图。A snapshot gives you a view of your full application state. 若要启用快照捕获,请转到“工具”>“选项”>“IntelliTrace”>“常规”,然后选择“IntelliTrace 快照(托管和本机)”。To enable the capture of snapshots, go to Tools > Options > IntelliTrace > General, and select IntelliTrace snapshots (managed and native). 有关详细信息,请参阅使用 IntelliTrace 检查上一应用状态For more information, see Inspect previous app states using IntelliTrace.

快照功能在 Visual Studio Enterprise 2017 版本 15.5 及更高版本中可用,并且需要 Windows 10 周年更新或更高版本。Snapshots are available in Visual Studio Enterprise 2017 version 15.5 and higher, and it requires Windows 10 Anniversary Update or above. 对于 .NET Core 和 ASP.NET Core 应用,需要 Visual Studio Enterprise 2017 版本 15.7。For .NET Core and ASP.NET Core apps, Visual Studio Enterprise 2017 version 15.7 is required. 对于面向 Windows 的本机应用,需要 Visual Studio Enterprise 2017 版本 15.9 预览版 2。For native apps targeting Windows, Visual Studio Enterprise 2017 version 15.9 Preview 2 is required.

收集 IntelliTrace 事件和调用信息(C#、Visual Basic)Collect IntelliTrace events and call information (C#, Visual Basic)

默认情况下不启用此选项,但 IntelliTrace 可以随事件一起记录方法调用。This isn't enabled by default, but IntelliTrace can record method calls along with events. 若要启用方法调用的集合,请转到“工具”>“选项”>“IntelliTrace”>“常规”,然后选择“IntelliTrace 事件和调用信息(仅限托管)”。To enable collection of method calls go to Tools > Options > IntelliTrace > General, and select IntelliTrace events and call information (managed only).

调用信息当前不可用于 .NET Core 和 ASP.NET Core 应用。Call information is not currently available for .NET Core and ASP.NET Core apps.

这使你可以查看调用堆栈历史记录以及在代码中的调用间后退和前进。This lets you see the call stack history and step backward and forward through calls in your code. IntelliTrace 记录的数据包括方法名、方法进入和退出点,以及部分参数值和返回值。IntelliTrace records data such as method names, method entry and exit points, and certain parameter values and return values.

提示

默认情况下不启用此选项,因为它会增加大量开销。This option is not enabled by default because it adds considerable overhead. IntelliTrace 不仅需要截获应用程序生成的每个方法调用,当需要在屏幕上显示数据或将数据保留到磁盘时,它还需要处理一组更大的数据。Not only does IntelliTrace have to intercept every method call your application makes, but it also has to deal with a much larger set of data when it comes to showing it on the screen or persisting it to disk.

可以通过限制 IntelliTrace 记录的事件列表以及将收集的模块数保持为最小值来减少性能开销。You can reduce the performance overhead by restricting the list of events that IntelliTrace records and by keeping the number of modules you are collecting to a minimum. 有关详细信息,请参阅控制 IntelliTrace 记录的调用信息量For more information, see Control how much call information IntelliTrace records.

使用导航线Use the navigation gutter

可以使用代码窗口左侧显示的导航线。You can use the navigation gutter that appears to the left of the code window. 如果没有看到导航线,请转到“工具”>“选项”>“IntelliTrace”>“高级”,然后选择“在调试模式中显示导航线” 。If you don't see the navigation gutter, go to Tools > Options > IntelliTrace > Advanced, and select Display the navigation gutter while in debug mode.

导航线让你能够在历史调试模式下向前和向后移动方法调用和事件。The navigation gutter allows you to move forwards and backwards through method calls and events in historical debugging mode. 有关历史调试的详细信息,请参阅历史调试For more information about historical debugging, see Historical Debugging. 它拥有多个命令:It has a number of commands:

在此设置调试器上下文Set Debugger Context Here 将调试上下文设置为调用出现的调用时间范围。Set the debugging context to the call timeframe where it appears.

此图标仅在当前调用堆栈上显示。This icon appears only on the current call stack.
返回调用站点Return to Call Site 将指针和调试上下文移回调用当前函数的位置。Move the pointer and debugging context back to where the current function was called.

如果处于实时调试模式下,则此命令会启用历史调试。If you are in Live Debugging mode, this command turns Historical Debugging on. 如果向后定位到原始执行中断,则会禁用历史调试并启用实时调试。If you navigate back to the original execution break, Historical Debugging is turned off and Live Debugging is turned on.
转到上一个调用或 IntelliTrace 事件Go to Previous Call or IntelliTrace Event 将指针和调试上下文移回上一个调用或事件。Move the pointer and debugging context back to the previous call or event.

如果处于实时调试模式下,则此命令会启用历史调试。If you are in Live Debugging mode, this command turns on Historical Debugging.
单步执行Step In 单步执行当前选择的函数。Step into the currently selected function.

只有处于历史调试模式下时才能使用此命令。This command is available only when you are in Historical Debugging mode.
转到下一个调用或 IntelliTrace 事件Go to Next Call or IntelliTrace Event 将指针和调试上下文移到存在 IntelliTrace 数据的下一个调用或事件。Move the pointer and debugging context to the next call or event for which IntelliTrace data exists.

只有处于历史调试模式下时才能使用此命令。This command is available only when you are in Historical Debugging mode.
转到实时模式Go to Live Mode 返回实时调试模式。Return to Live Debugging mode.

在 IntelliTrace 中搜索某行或某个方法Search for a line or method in IntelliTrace

仅当已启用方法调用信息时才可以搜索方法。You can search methods only when method call information has been enabled. 可以搜索 IntelliTrace 历史记录以查找特定行或方法。You can search IntelliTrace history for a specific line or method. 暂停调试程序执行时,在函数正文内右键单击以查看上下文菜单,然后单击“在 IntelliTrace 中搜索此行”或“在 IntelliTrace 中搜索此方法” 。While debugger execution is halted, right-click inside the body of the function to see the context menu, and click either Search For This LIne In IntelliTrace or Search For This Method In IntelliTrace.

控制 IntelliTrace 记录的调用信息量Control how much call information IntelliTrace records

默认情况下,IntelliTrace 记录解决方案使用的所有模块的信息。By default IntelliTrace records information for all the modules used by your solution. 可以将 IntelliTrace 设置为仅记录你感兴趣的模块的调用信息。You can set IntelliTrace to record call information only for the modules that interest you. 在“工具”>”选项”>“IntelliTrace”>“模块”中,可以指定 IntelliTrace 要包括或排除的模块。In Tools > Options > IntelliTrace > Modules, You can specify the modules to include or the modules to exclude from IntelliTrace. IntelliTrace 将仅收集你指定的模块中生成的事件,以及你感兴趣的模块内发生的方法调用。IntelliTrace will collect only the events that originated from the modules you have specified, and the method calls that happened within the modules you are interested in.

若要添加多个模块,请在字符串的开头或结尾使用通配符 *。To add multiple modules, use the wildcard character * at the start or the end of the string. 对于模块名称,请使用文件名,而不是程序集名称。For module names, use file names, not assembly names. 不接受文件路径。File paths are not accepted.

尝试将模块数保持为最小值。Try to keep the number of modules to a minimum. 因为要收集的数据变少,所以可以获得更好的性能。You get better performance because there is less data to be collected. UI 中的噪音也会减少,因为要浏览的数据变少。You also get less noise in the UI because there is less data to go through.

将 IntelliTrace 数据保存到文件(C#、Visual Basic、C++)Save IntelliTrace data to file (C#, Visual Basic, C++)

正在进行调试且应用程序处于中断状态时,通过转到“调试”>“IntelliTrace”>“保存 IntelliTrace 会话”,可以保存 IntelliTrace 收集的数据。You can save the data that IntelliTrace has collected going to Debug > IntelliTrace > Save IntelliTrace Session while you are debugging and the application is in a break state. 如果应用程序仍在运行或如果你已经停止调试,则菜单项会被禁用,且你将无法保存 IntelliTrace 收集的数据。The menu item is disabled and you will not be able to save the data IntelliTrace has collected if the application is still running or if you have stopped debugging.

通过转到“工具”>“选项”>“IntelliTrace”>“高级”并选择“在此目录中存储 IntelliTrace 记录”,可以将 IntelliTrace 配置为自动保存到文件 。You can configure IntelliTrace to automatically save to a file by going to Tools > Options > IntelliTrace > Advanced and selecting Store IntelliTrace recordings in this directory. 还可以为生成的文件配置固定大小,这会让 IntelliTrace 在空间不足时覆盖旧数据。You can also configure a set size for the generated file, which causes IntelliTrace to write over older data when it runs out of space. 自动保存文件并启用 Visual Studio 承载进程 (vshost.exe) 时,Visual Studio 会为每个 IntelliTrace 会话创建两个文件。Visual Studio creates two files for each IntelliTrace session when they are saved automatically and the Visual Studio hosting process (vshost.exe) is turned on.

提示

为了节省磁盘空间,请在不再需要时禁用自动保存文件。To save disk space, turn off saving files automatically when you don't need them anymore. 不会删除任何现有文件。Any existing files will not be deleted. 可以随时从上下文菜单按需保存到文件。You can always save to file on demand from the context menu.

将 IntelliTrace 数据保存到文件中时,每个 IntelliTrace 从中进行收集的进程都将获得一个 .itrace 文件。When you save IntelliTrace data to file, you get one .itrace file for each process that IntelliTrace collected from. 然后,通过转到“文件”>“打开”>“文件”并从“打开文件”对话框中选择 .itrace 文件,可以在 Visual Studio 中打开 .itrace 文件。You can then open the .itrace file in Visual Studio by going to File > Open > File and selecting the .itrace file from the Open File dialog. 有关详细信息,请参阅使用保存的 IntelliTrace 数据For more information, see Using saved IntelliTrace data.

博客Blogs

Visual Studio Enterprise 2015 中的 IntelliTraceIntelliTrace in Visual Studio Enterprise 2015

在 Visual Studio 2015 中使用 IntelliTrace 进行实时调试的演练(文本编辑器)Walkthrough of Live Debugging using IntelliTrace in Visual Studio 2015 (Text Editor)

在 Visual Studio 2015 中使用 IntelliTrace 进行实时调试的演练(社交俱乐部)Walkthrough of Live Debugging using IntelliTrace in Visual Studio 2015 (Social Club)

Visual Studio Enterprise 2015 中的 IntelliTrace 现在支持附加!IntelliTrace in Visual Studio Enterprise 2015 now supports attach!

使用 IntelliTrace 独立收集器从 Windows 服务收集数据Collect data from a windows service using the IntelliTrace Standalone Collector

编辑 IntelliTrace 收集计划Editing the IntelliTrace collection plan

使用 IntelliTrace 的自定义 TraceSource 和调试Custom TraceSource and debugging using IntelliTrace

IntelliTrace 独立收集器和在 Active Directory 帐户下运行的应用程序池IntelliTrace Standalone Collector and Application Pools running under Active Directory accounts

论坛Forums

Visual Studio 调试器Visual Studio Debugger

视频Videos

IntelliTrace 体验IntelliTrace Experience

Microsoft Visual Studio Ultimate 2015 中的 IntelliTrace 调试历史记录Historical Debugging with IntelliTrace in Microsoft Visual Studio Ultimate 2015