Skip to content

Commit 9a70907

Browse files
authored
Merge pull request #8041 from poppastring/vs-memory-dump-analyzers
Vs memory dump analyzers
2 parents 8ec9804 + d5d3cf4 commit 9a70907

9 files changed

+109
-1
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Debug a managed memory dump with .NET Diagnostic Analyzers | Microsoft Docs
3+
description: Learn how to use Visual Studio's .NET Diagnostics Analyzers to analyze a managed memory dump
4+
ms.custom: SEO-VS-2021
5+
ms.date: 04/21/2021
6+
ms.topic: how-to
7+
dev_langs:
8+
- CSharp
9+
- VB
10+
helpviewer_keywords:
11+
- analyzers
12+
- dump debugging
13+
- debugging managed memory dump
14+
- debugging [Visual Studio]
15+
author: poppastring
16+
ms.author: madownie
17+
manager: andster
18+
monikerRange: '>= vs-2019'
19+
ms.workload:
20+
- "multiple"
21+
---
22+
23+
# How to debug a managed memory dump with .NET Diagnostic Analyzers
24+
25+
26+
27+
In this tutorial, you will:
28+
29+
> [!div class="checklist"]
30+
> * Opening a memory dump
31+
> * Select and execute analyzers against the dump
32+
> * Review the results of the analyzers
33+
> * Navigating to the problematic code
34+
35+
36+
In the example described in this article, the concern is that your app not responding to requests in a timely manner.
37+
38+
39+
## Opening a memory dump in Visual Studio
40+
41+
1. Open the memory dump in Visual Studio by using the **File > Open > File** menu command and select your memory dump.
42+
43+
1. Notice on the Memory Dump Summary page a new **Action** called **Run Diagnostics Analysis**.
44+
45+
![Action - Diagnostics Analysis](../debugger/media/diagnostic-analyzer-dump-summary-actions.png)
46+
47+
1. Select this action to start the debugger and open the new **Diagnostic Analysis** page with a list of available analyzer options, organized by the underlying symptom.
48+
49+
50+
## Select and execute analyzers against the dump
51+
52+
To investigate these symptoms, the best options are available under **Process Responsiveness** as it best matches the issue in this example.
53+
54+
![Select diagnostics analyzers](../debugger/media/diagnostic-analyzer-diagnostics-analysis-window.png)
55+
56+
1. Click the **Analyze** button to start the investigative process
57+
58+
1. The analyzer will present results based on the combination of process info and CLR data captured in the memory dump.
59+
60+
## Review the results of the analyzers
61+
62+
1. In this case, the analyzer has found two errors. Select the analyzer result to see the **Analysis Summary** and suggested **Remediation**.
63+
64+
![Diagnostics analyzers results](../debugger/media/diagnostic-analyzer-diagnostics-analysis-results.png)
65+
66+
1. The **Analysis Summary** has stated that the “CLR thread pool is experiencing starvation”. This information suggests that the CLR has currently used all available thread pool threads, which means your service cannot respond to any new requests until a thread is released.
67+
68+
> [!NOTE]
69+
> The **Remediation** in this case is "Do not synchronously wait on Monitors, Events, Task, or any other objects that may block your thread. See if you can update the method to be asynchronous.".
70+
71+
## Navigating to the problematic code
72+
73+
My next job is to find that problematic code.
74+
75+
1. Clicking on the **Show call stack** link Visual Studio will immediately switch to the threads that are exhibiting this behavior.
76+
77+
1. The **Call Stack** window will show methods that might potentially quickly distinguish between my code (SyncOverAsyncExmple.*) from Framework code (System.*).
78+
79+
![Diagnostics analyzers link to call stack](../debugger/media/diagnostic-analyzer-call-stack.png)
80+
81+
1. Each call stack frame corresponds to a method and by double-clicking on the stack frames Visual Studio will navigate to the code that led directly to this scenario on this thread.
82+
83+
1. In this example, there are no symbols or code, however, on the **Symbols not loaded** page you can select the **[Decompile Source code](../debugger/decompilation.md)** option.
84+
85+
![Decompilation](../debugger/media/diagnostic-analyzer-decompilation.png)
86+
87+
1. In the decompiled source below it is evident that an asynchronous Task (ConsumeThreadPoolThread) is calling a synchronous blocking function.
88+
89+
> [!NOTE]
90+
> The "DoSomething()" method that contains a WaitHandle.WaitOne method, which is blocking the current thread pool thread until it receives a signal.
91+
92+
To improve the apps responsiveness, it is important to remove blocking synchronous code from all asynchronous contexts.
93+
94+
![Analyze decompiled code](../debugger/media/diagnostic-analyzer-decompiled-code.png)
95+
96+
97+
## See also
98+
99+
* [Use dump files in the debugger](../debugger/using-dump-files.md)
100+
* [Generate source code from .NET assemblies while debugging](../debugger/decompilation.md)
101+
* [Specify symbol (.pdb) and source files](../debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger.md)
Loading
Loading
Loading
Loading
Loading
Loading

docs/debugger/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@
688688
items:
689689
- name: Use dump files
690690
href: using-dump-files.md
691+
- name: Debug a managed memory dump
692+
href: how-to-debug-managed-memory-dump.md
691693
- name: Dump File Summary Extensibility API
692694
href: dump-file-summary-extensibility-api.md
693695
- name: Debugger security
@@ -949,4 +951,4 @@
949951
- name: FAQ - Find your debugging feature
950952
href: find-your-debugging-task.md
951953
- name: What's new for the debugger in Visual Studio
952-
href: what-s-new-for-the-debugger-in-visual-studio.md
954+
href: what-s-new-for-the-debugger-in-visual-studio.md

docs/debugger/using-dump-files.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ The Visual Studio debugger can save dump files for managed or native code. It ca
3939

4040
- To debug dump files from 64-bit machines, Visual Studio must be running on a 64-bit machine.
4141

42+
::: moniker range=">= vs-2019"
43+
- Visual Studio can debug dump files of managed apps from Linux OS.
44+
::: moniker-end
45+
4246
- Visual Studio can debug dump files of native apps from ARM devices. It can also debug dumps of managed apps from ARM devices, but only in the native debugger.
4347

4448
- To debug [kernel-mode](/windows-hardware/drivers/debugger/kernel-mode-dump-files) dump files or use the [SOS.dll](/dotnet/framework/tools/sos-dll-sos-debugging-extension) debugging extension in Visual Studio, download the debugging tools for Windows in the [Windows Driver Kit (WDK)](/windows-hardware/drivers/download-the-wdk).
@@ -111,6 +115,7 @@ If Visual Studio can't find the files it needs to debug a module in the dump, it
111115

112116
## See also
113117

118+
- [How to debug a managed memory dump with .NET Diagnostic Analyzers](../debugger/how-to-debug-managed-memory-dump.md)
114119
- [Just-In-Time debugging](../debugger/just-in-time-debugging-in-visual-studio.md)
115120
- [Specify symbol (.pdb) and source files](../debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger.md)
116121
- [IntelliTrace](../debugger/intellitrace.md)

0 commit comments

Comments
 (0)