PDA

View Full Version : Cross platform CPU idle timeout



skyphyr
4th April 2007, 18:06
Hi All,

I'm trying to find a way to detect when the CPU has been idle for X minutes that will work cross-platform. It's for http://splish.sf.net - a render manager in case anyone's interested. It's using Qt4.

Cheers,

Alan.

wysota
4th April 2007, 19:42
I guess Heisenberg would say this was impossible ;)

skyphyr
20th April 2007, 16:45
ahhh ok - thanks Wysota - I was hopeful.

wysota
20th April 2007, 17:26
The thing is that the act of measurement influences the measurement itself - if you want to test for "idleness" (which is hard to define on its own), you have to do some calculations causes the CPU to become not idle.

You could try cheating by checking once in a while the load average and assume that if during the last X minutes you didn't notice that it went higher than some predefined threshold, it means the cpu is idle. Or you could do it even simpler - by checking the long term load average and again decide against some threshold.

skyphyr
30th April 2007, 15:47
You could try cheating by checking once in a while the load average and assume that if during the last X minutes you didn't notice that it went higher than some predefined threshold, it means the cpu is idle.

This sounds ideal for what I'm after. I assume that a crossplatform support for this is also going to require custom code for each platform?

Cheers,

Alan.

marcel
30th April 2007, 16:53
On win you can use GetSystemTimes (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtimes.asp)( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtimes.asp)
This gives you idle time, kernel time and user time. You can poll this function periodically and compute some statistics.

On Linux and Mac there are similar syscalls (which I can't remember now :) ).

regards

winifredrayen
9th December 2010, 17:53
Msdn link is gr8 but do u think there is ne such work around for a mobile ? (im using qt 4.7)