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. (Using category: ".NET CLR Memory")
After I migrated it to .NET6, counters on ".NET CLR Memory" category throws error because the instance (which is the process name) is missing.
I then check this from perfmon, and realized that our app is no longer showed in the instance list.
Since we distribute our desktop app to enduser, we record the gc stats periodically onto log while they are running the app. So using external tool adhoc is not an option to us.
I want to know for a .NET6 app:
Many thanks for your help & advice!
I have tried below things, but still the app can't be found on perfmon:
In .NET 6, it is still possible to get GC statistics in-app using the System.Diagnostics.PerformanceCounter class. 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.
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.0 has improved built-in GC statistics that can be accessed directly on the GC
class instead of using the performance counter infrastructure. You can get a lot of information about the current process' memory usage by calling the new method GC.GetGCMemoryInfo()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.