dotnet-trace 不会收集容器上的托管代码

dotnet-trace won't collect managed code on a container

我在跟踪容器内完成的 .net core 3.1 应用程序的托管代码时遇到问题。

我做了一个非常简单的 .net core 3.1 程序 - 这是它的主体 Main:

for (int i = 0; i < 1000; i++) {
    Thread.Sleep(1000);
    Console.WriteLine("test");
}

然后在dotnet publish -c release之后我构建了一个镜像(包括dotnet-trace)。这是 Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS sdk
RUN dotnet tool install --tool-path /tools dotnet-trace

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
COPY test-trace/bin/Release/netcoreapp3.1/publish app/
RUN mkdir /tools
COPY --from=sdk /tools /tools

ENTRYPOINT ["dotnet", "app/test-trace.dll"]

映像已部署到 Kubernetes 集群:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-trace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-trace
  template:
    metadata:
      name: test-trace
      labels:
        app: test-trace
    spec:
      containers:
      - name: test-trace
        image: test-trace:latest
        imagePullPolicy: IfNotPresent
      restartPolicy: Always

最后我 运行 dotnet-trace collect -p 1 --duration 00:00:00:10 进入容器,但是当我在 PerfView 中打开跟踪文件时,调用树中没有托管代码行:

在我的工作站 (Windows) 上,dotnet-trace 输出确实包含一个托管代码行(尽管我 运行 它带有 dotnet test-trace.dll 而不是在容器中):

我在 Windows 跟踪文件中看到了命名空间的 .il 后缀,但我不知道它是否包含任何解决方案的线索。我错过了什么?谢谢!

更新:我将制作一个独立的版本并查看跟踪文件是否显示托管代码 (dotnet publish -r ubuntu-x64 -c Release --self-contained)。如果可行,我会 post 作为答案。

解决方案是发布一个 self-contained 应用程序 - 这样所有托管代码符号都得到了解决: dotnet publish -r ubuntu-x64 -c Release --self-contained

这些变量也被添加到 Dockerfile 中:

ENV COMPlus_PerfMapEnabled=1
ENV COMPlus_EnableEventLog=1