简体   繁体   English

对于 .NET6 桌面应用程序,是否仍然可以在 perfmon/PerformanceCounter.dll 上访问 GC 统计信息?

[英]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 应用程序:

  • If getting GC stat in-app is still possible?如果仍然可以在应用程序内获取 GC 统计信息?
  • If yes - Is category ".NET CLR Memory" still the right category?如果是 - 类别“.NET CLR Memory”是否仍然是正确的类别?
  • If yes - Is there any runtime config required for performanceCounter to expose the app itself for querying?如果是 - performanceCounter 是否需要任何运行时配置来公开应用程序本身以供查询?
  • If no - Is there any alternative api to get GC stat in-app?如果没有 - 是否有其他 api 可以在应用程序中获取 GC 统计信息?

Many thanks for your help & advice!非常感谢您的帮助和建议!

I have tried below things, but still the app can't be found on perfmon:我尝试了以下方法,但仍然无法在 perfmon 上找到该应用程序:

  • Starting the app with (debug) & without visual studio.使用(调试)和不使用 visual studio 启动应用程序。
  • Starting the app with Any CPU on visual studio (used to be x64).在 visual studio 上使用任何 CPU 启动应用程序(以前是 x64)。
  • Adding myself to Performance Monitor Users & Performance Log Users group.将自己添加到 Performance Monitor Users & Performance Log Users 组。 (I believe this is not related anyways, since the build on .NET4.8 can still be discovered by perfmon without this being set and the data can be read from performanceCounter.dll without issue.) (我相信这无论如何都不相关,因为 perfmon 仍然可以在没有设置的情况下发现 .NET4.8 上的构建,并且可以毫无问题地从 performanceCounter.dll 读取数据。)
  • Asking IT to add myself admin right.要求 IT 添加我自己的管理员权限。
  • Start a simple new console app on .NET6 - same result - not discovered on perfmon.在 .NET6 上启动一个简单的新控制台应用程序 - 结果相同 - 未在 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.

相关问题 GC.Collect()和PerformanceCounter - GC.Collect() and PerformanceCounter Net6 控制台应用程序,自定义 ConfigurationProvider 问题 - Net6 Console app, custom ConfigurationProvider question .NET6:使用 regsvr32 注册 COM DLL 结果为 80040111 - .NET6: registering COM DLL with regsvr32 results in 80040111 .NET GC 停止桌面应用程序 - 性能问题 - .NET GC Stalling Desktop Application - Performance Issue .net6 无法在 DLL user32.dll 中找到名为“AdjustWindowRectExForDpi”的入口点 - .net6 unable to find an entry point named 'AdjustWindowRectExForDpi' in DLL user32.dll 在 .NET6 Blazor Webassembly 应用程序中使用外部程序集构建错误 - Build Error with External Assembly in .NET6 Blazor Webassembly App 使用针对 .NET6 的 WPF Windows 应用程序的 Nunit 测试时出错 - Error using Nunit test with WPF Windows app targeting .NET6 从.NET Web应用程序删除ReportViewer,仍在寻找ReportViewer dll - Deleting ReportViewer from .NET web app, something still looking for ReportViewer dll Microsoft Monitoring Agent 的 Perfmon.dll 在使用 Log4Net 时使 IIS Web 应用程序池崩溃 - 2.0.9.0 或更高版本 - Microsoft Monitoring Agent's Perfmon.dll crashing IIS Web Application Pool while Using Log4Net - 2.0.9.0 or later 如何在 .NET6 中启用 UnobtrusiveJavaScriptEnabled? - how to enable UnobtrusiveJavaScriptEnabled in .NET6?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM