CPU percent used by a task/process

10 posts / 0 new
Last post
zzd10h
zzd10h's picture
Offline
Last seen: 7 years 2 weeks ago
Joined: 2012-08-24 20:56
CPU percent used by a task/process

Hi,
I'm building a little tool (SysMon on OS4Depot) and I would like to implement a kind of CPU task monitor.
I'm just able to scan the Exec task/process list but for the CPU used...
I have really no idea in which direction to search to do this.

Is somebody have an idea where to search to do that ?

Many thanks, by advance, for your help.

hypex
hypex's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-09-09 16:20
Possibly one way is to add an

Possibly one way is to add an idle task running at low priority that signals your task and then waits a little while. That way you can determine CPU load by the amount of lag between signals. If you know how long it will wait before each "pulse" then you can use that as a baseline. That would be one way AFAIK.

DOpus and CPUDocky also test for system load.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 2 weeks ago
Joined: 2012-08-24 20:56
Thank you hypex, therefore it

Thank you hypex,
therefore it must be possible for the entire workload but not for each task/process ?

hypex
hypex's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-09-09 16:20
AFAIK yes only for the whole

AFAIK yes only for the whole workload. But that is value determined by testing live and not querying the OS.

I'm not aware of each task storing any type of load. I'm not sure of any easy way to do it. I suppose you could run an interrupt on a timer and montor the current task to see what ones are mostly in use. The vertical blank was used for task switching IIRC. What would be good is checking at the same speed tasks are switched so you can catch the change.

Or you could also run through the task list in an interrupt to see what ones are ready and waiting. I don't know if that would be more or less accurate but an interrupt shouldn't be used for any time consuming work or anything sensitive as causing a fault will freeze the system. Even though the task list would be fairly static during an interrupt.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 2 weeks ago
Joined: 2012-08-24 20:56
It's a pity, I was hoping

It's a pity, I was hoping that somewhere in a structure, this kind of info was stored...

Thank you for these technicals explanations, hypex.

hypex
hypex's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-09-09 16:20
You're welcome. But I am

You're welcome.

But I am surprised. There has got to be other people on the site who have either programmed a CPU task monitor or know how it would be done. At least on AmigaOS.

Another thing is to examine the task priority and enter this into the equation. Since tasks running on a higher priority than others will logically gain more CPU time. Also, there is Quantum and Elapsed fields of ExecBase. These contain how much time a task gets and how much it has used currently. IIRC this is controlled by a standard vertical blanking interrupt. So you could also keep watch of these values to see how much time a task is getting and if a task is hogging the CPU. Peeking ThisTask from an interupt will give you the current one.

Each task wold get an even anount of time. AFAIK the quantum amount was 4 ticks. So if there were 50 ticks a second which is the standard for DOS BTW then each task gets an equal amount of 0.08 seconds each or 4/50. Or 12.5 tasks a second. If my math is correct. :-)

Of course this is the time they have but not always the time they use with other factors involved such as a task waiting for signals and thus giving up ownership of their slice of quantums. And even though there is the simple round robin multiasking algorithm at work (provided tools like Executive are not being run) some tasks can hog the CPU.

Now where do the task priorities come into play? Off the top of my head being that a task would be part of a node Exec would shuffle the task nodes in the task list so that the higher priority ones will get their time first before lower priority ones. As far as I understand it. :-)

kas1e
kas1e's picture
Offline
Last seen: 3 months 3 days ago
Joined: 2010-11-30 15:30
@zzd10h If you still haven't

@zzd10h

If you still haven't solution, i can say that Thomas Frieden write such kind of code for some internal purposes, which show in realtime the processes/tasks and their cpu loading in %. What mean that is possible with current api, and i ask him today about explaining how he do that, or about sources, as well as pointed out on this thread. Once he will have time for answer (there or to me), you will have solution.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 2 weeks ago
Joined: 2012-08-24 20:56
Thank you Kas1e, Very nice!

Thank you Kas1e,
Very nice!

kas1e
kas1e's picture
Offline
Last seen: 3 months 3 days ago
Joined: 2010-11-30 15:30
Thomas says that he can't

Thomas says that he can't open up a souces just because its use some internal Exec's structures, which should stays closed (to avoid coders to poke with it). There is some plans to make it all as nice API, but not yet.

Through, as he say, what you can do is (without any help of the system): "Just" patch AddTask so that after adding the task, it also automatically adds Launch and Switch entries that store the time the task was launched and switched, and compare that to the timings of idle.task.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 2 weeks ago
Joined: 2012-08-24 20:56
Thank you Hypex and Kas1e for

Thank you Hypex and Kas1e for your replys,
but it's a little bit to much complex for my little system knowledge !

Good new that a new API will be available, certainly not soon but at least it will be available...

Log in or register to post comments