vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

load.c (550B)


      1 #include	"u.h"
      2 #include	<sys/times.h>
      3 #include	"lib.h"
      4 #include	"mem.h"
      5 #include	"dat.h"
      6 
      7 /*
      8  * CPU load
      9  */
     10 void
     11 ploadproc(void *v)
     12 {
     13 	double load;
     14 	vlong hz;
     15 	struct tms t;
     16 	clock_t now, last;
     17 	clock_t used, lastused;
     18 
     19 	hz = sysconf(_SC_CLK_TCK);
     20 	last = 0;
     21 	lastused = 0;
     22 	load = 0;
     23 
     24 	for(;;){
     25 		usleep(1000000);
     26 		now = times(&t);
     27 		used = t.tms_utime + t.tms_stime;
     28 		load = (double)(used - lastused) / (now - last);
     29 		machp[0]->load = load * 100 * hz;
     30 /*
     31 iprint("XXX Load: %d%%\n", (int)(load * 100));
     32 */
     33 		lastused = used;
     34 		last = now;
     35 	}
     36 }
     37