Collecting memory dumps is a crucial part of diagnosing and troubleshooting application issues on Linux machines. Microsoft suggests three primary tools for this purpose: dotnet-dump, procdump, and createdump. In this blog post, we will explore these tools, provide the commands needed to use them, and offer a summary to understand their significance better.
1. Methods to Collect Memory Dumps on Linux
dotnet-dump
The dotnet-dump tool is a part of the .NET SDK and can be used to collect and analyze dumps. It allows you to capture a dump file from a running .NET application without needing to install additional debugging tools.
https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump
procdump
Procdump is a versatile tool provided by Microsoft that captures dumps based on various triggers, such as high CPU usage or unhandled exceptions. Originally built for Windows, it has been ported to Linux, offering similar functionalities.
https://github.com/microsoft/ProcDump-for-Linux
createdump
The createdump utility is specifically designed for .NET Core applications. It creates core dumps that can be used for post-mortem debugging when an application crashes.
https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/aspnetcore/practice-troubleshoot-linux/lab-1-3-capture-core-crash-dumps#configure-createdump-to-run-at-process-termination
2. Command for dotnet-dump
To collect a memory dump using dotnet-dump, you can execute the following command:
./dotnet-dump collect -p <ProcessID>
In case you want to collect dump on crash you can use below :
./dotnet-dump collect -p <ProcessID> -Crashreport
Here, replace with the ID of the process you want to dump.
3. Command for procdump
To capture a dump with procdump, use the command:
sudo procdump -p <PID> -n 3 - s 10
sudo procdump -C <CPU_Usage> -M <Memory_Usage> <PID> -n 3 - s 10
In this example, the tool will create a dump if the CPU usage exceeds a certain threshold over three consecutive 10-second intervals. Adjust the parameters as needed for your specific scenario.
4. Command for createdump
To generate a dump using createdump, the command is:
sudo createdump --full <PID>
Replace with the appropriate process ID.
Summary
Collecting memory dumps is essential for diagnosing application issues on Linux. Microsoft provides three recommended tools: dotnet-dump, procdump, and createdump. Each of these tools offers unique functionalities to help capture detailed information about your applications' state at the time of issues. By utilizing the respective commands for each tool, you can efficiently collect memory dumps and troubleshoot more effectively.
The commands for capturing memory dumps are straightforward:
- dotnet-dump: dotnet-dump collect -p
- procdump: procdump -p -s 10 -n 3
- createdump: createdump --full <PID>
By following these steps, you can ensure that you have the necessary data to analyze and resolve issues efficiently. Memory dump collection is a valuable skill for any Linux system administrator or developer, and mastering these tools will significantly enhance your troubleshooting capabilities.