[英]Is GC stats still accessible on perfmon/PerformanceCounter.dll for a .NET6 desktop app?
We have a WPF app (x64) running on .NET4.8 and we used to print GC/memory related stats onto log periodically using System.Diagnostics.PerformanceCounter.我们有一个在 .NET4.8 上运行的 WPF 应用程序 (x64),我们曾经使用 System.Diagnostics.PerformanceCounter 定期将 GC/内存相关统计信息打印到日志中。 (Using category: ".NET CLR Memory")
(使用类别:“.NET CLR 内存”)
After I migrated it to .NET6, counters on ".NET CLR Memory" category throws error because the instance (which is the process name) is missing.在我将它迁移到 .NET6 之后,“.NET CLR Memory”类别上的计数器会抛出错误,因为实例(即进程名称)丢失了。
I then check this from perfmon, and realized that our app is no longer showed in the instance list.然后我从 perfmon 检查了这一点,并意识到我们的应用程序不再显示在实例列表中。
Since we distribute our desktop app to enduser, we record the gc stats periodically onto log while they are running the app.由于我们将桌面应用程序分发给最终用户,因此我们会在他们运行应用程序时定期将 gc 统计信息记录到日志中。 So using external tool adhoc is not an option to us.
所以使用外部工具 adhoc 不是我们的选择。
I want to know for a .NET6 app:我想知道 .NET6 应用程序:
Many thanks for your help & advice!非常感谢您的帮助和建议!
I have tried below things, but still the app can't be found on perfmon:我尝试了以下方法,但仍然无法在 perfmon 上找到该应用程序:
In .NET 6, it is still possible to get GC statistics in-app using the System.Diagnostics.PerformanceCounter class.在 .NET 6 中,仍然可以使用 System.Diagnostics.PerformanceCounter 类在应用程序内获取 GC 统计信息。 However, the ".NET CLR Memory" category is no longer available, and you will need to use a different category to get the GC statistics you are interested in.
但是,“.NET CLR Memory”类别不再可用,您将需要使用不同的类别来获取您感兴趣的 GC 统计信息。
To get GC statistics in-app using .NET 6, you can use the ".NET Core Memory" category, which includes counters for various GC-related statistics, such as the number of bytes in the GC heap, the number of GC collections that have occurred, and the amount of time spent in GC.要使用 .NET 6 在应用程序内获取 GC 统计信息,您可以使用“.NET Core Memory”类别,其中包括各种 GC 相关统计信息的计数器,例如 GC 堆中的字节数、GC 收集次数已发生的事件,以及在 GC 中花费的时间。
.NET 6.0 has improved built-in GC statistics that can be accessed directly on the GC
class instead of using the performance counter infrastructure. .NET 6.0 改进了内置的 GC 统计信息,可以直接在
GC
类上访问,而不是使用性能计数器基础结构。 You can get a lot of information about the current process' memory usage by calling the new method GC.GetGCMemoryInfo()
.您可以通过调用新方法
GC.GetGCMemoryInfo()
获取有关当前进程内存使用情况的大量信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.