cputime, times, cycles – cpu time in this process and children

#include <u.h>
#include <libc.h>

int      times(long t[4])

double cputime(void)

void     cycles(uvlong *cyclep)

If t is non–null, times fills it in with the number of milliseconds spent in user code, system calls, child processes in user code, and child processes in system calls. Cputime returns the sum of those same times, converted to seconds. Times returns the elapsed real time, in milliseconds, that the process has been running.

These functions read /dev/cputime, opening that file when they are first called.

Cycles reads the processor's timestamp counter of cycles since reset, if any, and stores it via cyclep. Currently supported architectures are 386, amd64, and power; on all others, cycles will store zero.


exec(2), cons(3)

Only 386 processors starting with the Pentium have timestamp counters; calling cycles on earlier processors may execute an illegal instruction.