如何在 linux 上生成大小合理的 .NET Core 进程内存转储文件?

How to generate a reasonably sized memory dump file of a .NET Core process on linux?

我正在尝试使用 gcore 生成 大小合理 的 运行 .net 核心进程的核心转储,但文件大于20GB。 该进程是 dotnet wapi.dll,它是使用 dotnet new webapi 创建的空项目的二进制文件。 我认为转储的大小与虚拟内存量有关。

主要问题是如何生成较小的核心转储?

这跟我想的(虚拟内存)有关系吗?

我应该限制虚拟内存吗?怎么样?

你试过dotnet-dump和朋友吗?他们支持 mini 转储,这些转储更小,可能足以满足您的需求:

$ dotnet tool install -g dotnet-dump
You can invoke the tool using the following command: dotnet-dump
Tool 'dotnet-dump' (version '3.0.47001') was successfully installed.
$ dotnet dump collect --help
collect:
  Capture dumps from a process

Usage:
  dotnet-dump collect [options]

Options:
  --type <Heap|Mini>  The dump type determines the kinds of information that are collected from the process. There are two types: heap - A large and relatively comprehensive dump containing module lists, thread lists, all
                      stacks, exception information, handle information, and all memory except for mapped images. mini - A small dump containing module lists, thread lists, exception information and all stacks. If not
                      specified 'heap' is the default.

我发现最简单的方法是使用 dotnet 运行时附带的 createdump 实用程序,它位于与 libcoreclr.so 相同的目录中。 (thanks to Maoni Stephens)。

使用 createdump 非常简单:

createdump [options] pid
-f, --name - dump path and file name. The pid can be placed in the name with %d. The default is "/tmp/coredump.%d"
-n, --normal - create minidump (default).
-h, --withheap - create minidump with heap.
-t, --triage - create triage minidump.
-u, --full - create full core dump.
-d, --diag - enable diagnostic messages.

Read more about createdump here


另一种选择是使用 dotnet-dump 全局工具 you can read about it here

On Linux, the runtime version must be 3.0 or greater. On Windows, dotnet-dump collect will work with any version of the runtime.

因为我是 运行 v2.2 所以我无法使用这个工具。