“% Time in GC”性能计数器是什么意思

mil*_*oud 6 c# performance garbage-collection memory-management

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

所以当我跑

gcPerf.NextSample() 
Run Code Online (Sandbox Code Playgroud)

我得到值 42.12273。

但我不明白这个值的单位是 (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);
 }
Run Code Online (Sandbox Code Playgroud)

Cha*_*thJ 4

\n

这是自上次 GC 结束以来 GC 所花费时间的百分比。例如,自上次 GC 结束以来\xe2\x80\x99 已执行了 100 万个周期,而我们在当前 GC 中花费了 30 万个周期,该计数器将\n 显示 30%。

\n
\n\n

阅读这个这个

\n\n
\n

该计数器的健康值是​​多少?\xe2\x80\x99很难说。这取决于您的应用程序的用途。但是,如果您看到一个非常高的值(例如 50% 或更高),那么这是查看托管堆内部发生的情况的合理时间。如果这个数字是 10%,\xe2\x80\x99 可能\n 最好看看应用程序中的其他地方,因为即使你可以\n 去掉其中的一半,你也只能节省 5% - 很可能不是很多\n 值得。

\n
\n

  • 如果我想要它在(毫秒)内我该如何转换它? (3认同)