.net - Get CPU Usage in Dotnet on MacOS - Stack Overflow

I have some C-Sharp code, running on MacOS(Sequoia), and I measure its resource usage by calling these

I have some C-Sharp code, running on MacOS(Sequoia), and I measure its resource usage by calling these two functions before and after, and subtracting.

public static long GetClockTime()
{
   var timespan = DateTime.Now - DateTime.MinValue;
   return (long)timespan.TotalMilliseconds;
}

public static long GetCpuTime()
{
   return (long)Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
}

In one particular case, in which I'm 99% sure that no i/o is happening, it's reporting 30 seconds of clock time and 1 second of CPU time. At a guess, 30 seconds of CPU time seems about right.

Any guesses as to why GetCpuTime is reporting a number that is too low?

If my code spawns more threads, which do the actual work, would that time get lost?

Is there a more correct way to get the total cpu?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744402057a4572438.html

相关推荐

  • .net - Get CPU Usage in Dotnet on MacOS - Stack Overflow

    I have some C-Sharp code, running on MacOS(Sequoia), and I measure its resource usage by calling these

    6天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信