.NET Core的跨平台诊断工具

.NET Core is cross-platform and open-source. Tell someone, maybe your boss.

.NET Core是跨平台的开放源代码。 告诉某人,也许是你的老板。

A good reminder. It's been this way for a half decade but I'm still bumping into folks who have never heard this. Moving forward, .NET 5 will be a unification of the .NET Framework you may have heard for years, and the new .NET Core I like talking about, PLUS great goodness, tools and libraries from Mono and Xamarin. It's one cross-platform .NET with a number greater than 4. Because 5 > 4, natch.

一个很好的提醒。 已经有五年了,但是我仍然碰到从未听说过的人。 展望未来,.NET 5将是您多年来听说过的.NET Framework的统一,以及我喜欢谈论的新.NET Core,Mono和Xamarin的出色功能,工具和库。 它是一个跨平台的.NET,数字大于4。因为5> 4,所以natch。

NOTE: If you like, you can learn all about What is .NET? over on my YouTube.

注意:如果愿意,您可以了解有关什么是.NET? 在我的YouTube上

Now you've made some software, maybe for Windows, maybe Mac, maybe Linux. There's a lot of ways to diagnose your apps in .NET Core, from the Docs:

现在您已经制作了一些软件,可能是Windows,Mac,Linux。 有很多方法可以从Docs中诊断.NET Core中的应用程序

  • Logging and tracing are related techniques. They refer to instrumenting code to create log files. The files record the details of what a program does. These details can be used to diagnose the most complex problems. When combined with time stamps, these techniques are also valuable in performance investigations.

    日志记录和跟踪是相关技术。 它们引用检测代码来创建日志文件。 这些文件记录了程序的详细信息。 这些详细信息可用于诊断最复杂的问题。 当与时间戳结合使用时,这些技术在性能研究中也很有价值。

  • Unit testing is a key component of continuous integration and deployment of high-quality software. Unit tests are designed to give you an early warning when you break something.

    单元测试是持续集成和部署高质量软件的关键组成部分。 单元测试旨在在您破坏某些内容时给您预警。

  • Debug Linux dumps explains how to collect and analyze dumps on Linux.

    调试Linux转储说明了如何在Linux上收集和分析转储。

But I want to talk about the...

但是我想谈谈...

.NET Core诊断全局工具 (.NET Core Diagnostic Global Tools)

First, let's start with...

首先,让我们开始...

网络计数器 (dotnet-counters)

dotnet tool install --global dotnet-counters

Now that I've installed it, I can see what .NET Core apps I'm running, like a local version of my Hanselminutes podcast site.

现在,我已经安装了它,我可以看到我正在运行什么.NET Core应用程序,例如Hanselminutes播客站点的本地版本。

dotnet counters ps
18996 hanselminutes.core D:\github\hanselminutes-core\hanselminutes.core\bin\Debug\netcoreapp3.1\hanselminutes.core.exe
14376 PowerLauncher C:\Program Files\PowerToys\modules\launcher\PowerLauncher.exe
24276 pwsh C:\Program Files\PowerShell\7\pwsh.exe

I also see PowerShell 7 in there that I'm running in Windows Terminal. Pwsh is also written in cross platform .NET Core.

我还在Windows Terminal中运行的其中看到了PowerShell 7 。 Pwsh也使用跨平台.NET Core编写。

I'll run it again with a process id, in this case that of my podcast site:

我将使用进程ID(在本例中为播客站点的ID)再次运行它:

dotnet counters monitor --process-id 18996

Here I'll get a nice constantly refreshing taskman/processmonitor of sorts in the form of dotnet-countersperformance counters:

在这里,我将以dotnet-countersperformance计数器的形式获得一个不错的,不断刷新的任务员/进程监视器:

dotnet-monitor

Again this works outside Visual Studio and it works everywhere. You can watch them and react, or collect them to a file.

同样,它可以在Visual Studio之外运行,并且可以在任何地方运行。 您可以观看它们并做出React,或者将它们收集到文件中。

网络转储 (dotnet-dump)

The dotnet-dump tool is a way to collect and analyze Windows and Linux core dumps without a native debugger. Although it's not yet supported on macOS, it works on Windows and Linux.

dotnet-dump工具是一种无需本机调试器即可收集和分析Windows和Linux核心转储的方法。 尽管macOS尚不支持它,但它可在Windows和Linux上运行。

With a similar syntax, I'll dump the process:

使用类似的语法,我将转储该过程:

dotnet dump collect -p 18996
Writing full to D:\github\hanselminutes-core\hanselminutes.core\dump_20200918_224648.dmp
Complete

Then I'll start an interactive analysis shell session. You can run SOS (Son of Strike) commands to analyze crashes and the garbage collector (GC), but it isn't a native debugger so things like displaying native stack frames aren't supported.

然后,我将开始一个交互式分析Shell会话。 您可以运行SOS(罢工之子)命令来分析崩溃和垃圾收集器(GC),但它不是本机调试器,因此不支持显示本机堆栈帧之类的操作。

dotnet dump analyze .\dump_20200918_224648.dmp
Loading core dump: .\dump_20200918_224648.dmp ...
Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.
Type 'quit' or 'exit' to exit the session.
>

There's tons to explore. Debugging production dumps like this is a lost art.

有很多东西可以探索。 像这样调试生产转储是一门失传的艺术。

Exploring in dotnet dump

You can also do live Garbage Collector dumps with

您还可以使用以下方法进行实时垃圾收集器转储

dotnet-gcdump(dotnet-gcdump)

GCDump is:

GCDump是:

"a way to collect GC (Garbage Collector) dumps of live .NET processes. It uses the EventPipe technology, which is a cross-platform alternative to ETW on Windows. GC dumps are created by triggering a GC in the target process, turning on special events, and regenerating the graph of object roots from the event stream. This process allows for GC dumps to be collected while the process is running and with minimal overhead."

“一种收集实时.NET进程的GC(垃圾收集器)转储的方法。它使用EventPipe技术,它是Windows上ETW的跨平台替代品。GC转储是通过在目标进程中触发GC并打开而创建的特殊事件,并从事件流中重新生成对象根图。此过程允许在过程运行时以最小的开销收集GC转储。”

Once you have a dump you can analyze it in Visual Studio or PerfView on GitHub.

获得转储后,您可以在Visual Studio或GitHub上的PerfView中对其进行分析。

PerfView

Sometimes you may capture a dump from one machine and analyze it on another. For that you may want to download the right symbols to debug your core dumps or minidumps. For that you'll use

有时,您可能会从一台计算机上捕获转储,然后在另一台计算机上进行分析。 为此,您可能需要下载正确的符号来调试核心转储或小型转储。 为此,您将使用

网络符号(dotnet-symbol)

This is great for Linux debugging with lldb.

这对于使用lldb进行Linux调试非常有用。

"Running dotnet-symbol against a dump file will, by default, download all the modules, symbols, and DAC/DBI files needed to debug the dump including the managed assemblies. Because SOS can now download symbols when needed, most Linux core dumps can be analyzed using lldb with only the host (dotnet) and debugging modules."

“默认情况下,针对转储文件运行dotnet-symbol将下载调试转储所需的所有模块,符号和DAC / DBI文件,包括托管程序集。由于SOS现在可以在需要时下载符号,因此大多数Linux核心转储可以仅使用主机(dotnet)和调试模块使用lldb进行分析。”

Interesting in some real tutorials on how to use these tools? Why not learn:

有关如何使用这些工具的一些实际教程很有趣? 为什么不学习:

In the next blog post I'll look at dotnet trace and flame graphs!

在下一篇博客文章中,我将介绍点网跟踪和火焰图

翻译自: https://www.hanselman.com/blog/crossplatform-diagnostic-tools-for-net-core

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值