return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>.net - Get CPU Usage in Dotnet on MacOS - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论