【问题标题】:What is the meaning of "% Time in GC" performance counter“% Time in GC”性能计数器是什么意思
【发布时间】:2023-03-28 04:15:01
【问题描述】:

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

所以当我跑步时

gcPerf.NextSample() 

我得到的值是 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);
 }

【问题讨论】:

  • 这是经过时间的百分比。你读过documentation吗?有什么不清楚的地方?
  • 如果是百分比,我将如何以 (ms) 计算?因为 process.TotalProcessorTime 一直在提供包括 GC 在内的所有时间,以及我如何从中减去 GC 时间以获得没有 GC 时间的 CPU 时间?

标签: c# performance memory-management garbage-collection


【解决方案1】:

这是自 GC 结束以来花费在 GC 上的时间百分比 最后一次GC。例如,自上次 GC 结束以来已经 100 万次循环 我们在当前的 GC 中花费了 30 万个周期,这个计数器将 显示 30%。

阅读thisthis

这个计数器的健康值是​​多少?很难说。这取决于 关于您的应用程序的功能。但是如果你看到一个非常高的价值(比如 50% 或更多),那么现在是查看正在发生的事情的合理时机 在托管堆内部。如果这个数字是 10%,它可能是 最好在您的应用程序中查看其他地方,因为即使您可以摆脱 其中一半,你只会节省 5% - 很可能不是很 值得。

【讨论】:

  • 如果我想要它在(毫秒)我如何转换它?
猜你喜欢
  • 2018-08-16
  • 2023-01-11
  • 2015-05-11
  • 1970-01-01
  • 1970-01-01
  • 2015-09-05
  • 2018-08-30
  • 2016-10-29
  • 2015-01-03
相关资源
最近更新 更多