osx - Process CPU Usage for OS X using libproc.h from Go -


i known excellent replies exist on subject questions like:

the problem i'm trying use libproc.h defines proc_threadinfo structure (among others) field pth_cpu_usage 0 (see trheadinfohandler() func here see how i'm using struct go).

looking @ snippet of chromium source here (that doesn't use libproc.h), wondering if using fields both proc_threadinfo , proc_taskinfo possible calculate cpu percent usage.

 proc_threadinfo.pth_user_time; /* user run time */ proc_threadinfo.pth_system_time; /* system run time */  proc_taskinfo.pti_total_user; /* total time */ proc_taskinfo.pti_total_system; 

edit

some pseudo code illustrating the right algorithm or suggestion put me on right path appreciated.

using /proc filesystem think able calculate cpu % usage in linux:

 func cpuusageof(pid int, waithandler func()) float32 {     stat1 := procfsstatof(pid)     utime1 := stat1.utime // /proc/[pid]/stat field index 13     stime1 := stat1.stime // /proc/[pid]/stat field index 14     cputime1 := procfscputimetotal() // /proc/stat -> sum of cpu values      waithandler() // here wait 1 second      stat2 := procfsstatof(pid)     utime2 := stat2.utime // /proc/[pid]/stat field index 13     stime2 := stat2.stime // /proc/[pid]/stat field index 14     cputime2 := procfscputimetotal() // /proc/stat -> sum of cpu values      return float32(cpucount() * ((utime2 + stime2) - (utime1 + stime1)) * 100) / float32(cputime2 - cputime1) } 

for os x, i've use values proc_threadinfo or proc_taskinfo? , can find same values in linux read /proc/stat (procfscputimetotal())?

full code here (as in commit 9e34d3c72bf853ff49ef3970ad6a6c9688e9ba23); fast link os x code here.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -