我正在使用 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%.
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/