c# - "% Time in GC"性能计数器是什么意思

标签 c# performance memory-management garbage-collection

我正在使用 perfcounter = "% Time in GC"

所以当我运行的时候

gcPerf.NextSample() 

我得到值 42.12273。

但我不明白这个值的单位是 (ms) 还是什么?

如果我想在 (ms) 内转换它,我该如何转换它?

这是全局代码

 string category = ".NET CLR Memory";
 string counter  = "% Time in GC";
 string instance = Process.GetCurrentProcess().ProcessName;
 PerformanceCounter gcPerf;

 // make sure the performance counter is available to query
 if (PerformanceCounterCategory.Exists(category) &&
     PerformanceCounterCategory.CounterExists(counter, category) &&
     PerformanceCounterCategory.InstanceExists(instance, category))
 {
    gcPerf = new PerformanceCounter(category, counter, instance);
 }

最佳答案

This is the percentage of the time spent in GC since the end of the last GC. For example, it’s been 1 million cycles since last GC ended and we spent 0.3 million cycles in the current GC, this counter will show 30%.

阅读thisthis .

What is a health value for this counter? It’s hard to say. It depends on what your app does. But if you are seeing a really high value (like 50% or more) then it’s a reasonable time to look at what’s going on inside of the managed heap. If this number is 10%, it’s probably better to look elsewhere in your app because even if you could get rid of half of that, you would only be saving 5% - most likely not very worthwhile.

关于c# - "% Time in GC"性能计数器是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31570183/

相关文章:

c# - 仅使用 .NET 中可用的库/服务在 C# 中创建 XMPP/Jabber 服务器

c - memcpy() 通常比 strcpy() 快吗?

c - 由电影支持的 QTMovie 最初可以工作,但不能以其他方法工作

Linux Ubuntu Tomcat Best Config 避免内存不足

javascript - 循环等待 Promise.all 内存泄漏

c - C 中段错误的不稳定行为

c++ - 内存管理

c# - 自定义 xmlns :a= tag in a soapresponse from WCF

c# - 在 AutoFixture 自定义上调用 Dispose 方法

c# - Sitecore 动态占位符允许渲染