[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] How to get CPU time?



Hello!

Well, it's not really lack of functions.

For example, on Linux, for to get CPU usage, I make:

char s[256];

FILE *f=fopen("/proc/stat","r");
fgets(s,sizeof(s),f);
sscanf(s,"%*s %lu %lu %lu %lu",&user,&nice,&sys,&idle);

As MiNT doesn't provide something like "/proc/stat", how can I do to get the CPU usage?

Use /kern/stat instead. As /proc was already used under FreeMiNT we named the Linux style proc /kern.

I have already thought about that but with the MiNT kernel that I use( 1.16.0Beta), /kern/stat and all the datas from the /kern folder are empties :/

How do you read it out? These files are special and don't have a file size (for some files the size changes and is only known at the time you read it). With other words, some ATARI text editors have problems with that.
Just try a cat /kern/stat on the command line.

or look at getloadavg,

getloadavg() gets only system load averages, so no the CPU's load at the moment where we call this function.

There is no CPU load for the moment. A CPU load is always a summary of the CPU usage over a time interval. For getloadavg you get the load about the last minute, the last 5 minutes and the last 15 minutes.

You can for sure repeat the call of getloadavg and you get the uptodate load average of the last minute. top do exactly this.


Regards,
Frank

--
ATARI FALCON 060 // MILAN 060
-----------------------------------------
http://www.cs.uni-magdeburg.de/~fnaumann/
e-Mail: fnaumann@freemint.de