Re: Getting user idle time - screenSaver?
Re: Getting user idle time - screenSaver?
- Subject: Re: Getting user idle time - screenSaver?
- From: Stéphane Sudre <email@hidden>
- Date: Fri, 16 Nov 2001 17:35:48 +0100
Le vendredi 16 novembre 2001, ` 01:29 PM, Gregory Block a icrit :
On mardi, novembre 13, 2001, at 03:08 , Adam Iser wrote:
Hey everyone - quick question for ya :)
I asked this question a while ago and no one knew of a "legal" way to
get this information from the system... so I ask again now that 10.1
is
out and about in hopes of an answer :)
Something simple I can call every minute or so to keep an accurate
idle counter?
On 13/11/01 6:39 pm, "Stiphane Sudre" <email@hidden> wrote:
While playing with top in the Terminal:
0 idle_threa 85.4% 11:42.18
Well, idle tasks in the Darwin/Mach kernel are basically such that
they're
handled differently than a normal task. This, as some who have tried
renicing apps to -20 have noticed, are not the same thing as a true idle
task in terms of how they get allocated; nor would you want just any
application running in an idle task queue due to resources it might be
holding that things not in the idle task queue might want.
So.
First and foremost, know that true "idle time" is isolated and special,
and
is used by things in the idle task queue.
You *could* go through the list of tasks that are present to find out
which
tasks were scheduled into that idle task queue, and then look at the
mach-level cpu_usage for those threads and add them up.
I don't *think* it'd be that expensive to walk through the mach task
list.
However, the big question is, will you need to be running as root to
get it.
:( That means going setuid for your collecting binary.
Since screensavers hold resources like the display that are in use
elsewhere
within the system, you'd not schedule one into a mach idle queue without
causing all kinds of problems when another task blocked on wanting that
resource back, methinks. So screensavers are going to run as ordinary,
low-priority tasks, which means they operate very differently, even at
-20,
than something which is actually in the idle queue.
Does this sound like a fair answer? You should find that there is one
idle
thread per CPU, but if someone were to hack themselves into that queue
(so
that their thread, whatever it did, only got run in circumstances where
there was nothing to do) you could theoretically end up with more than
one,
so while it may practically work that you could just look up the
specific
idle task process that was mentioned, you probably want to make sure you
check all of the idle threads.
From the class-dumping of LoginWindow, LoginWindow is the (background
application) responsible for launching/stopping screensavers.