【发布时间】: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