CPU load


I want to monitor the CPU load during normal operation. I need to be able to read out or calcultae the load and than print the result to a log file.

Somebody mentioned some 3rd party CD. I guess I won’t be able to introduce any 3rd party SW. Only source code examples would help.

I would very much appreciate some help.




Just how detailed do you need the information to be?

There is a utility that comes with QNX that’s called hogs. This gives CPU load in percentages.

For example ‘hogs -n -s1 -%1’ will once a second print out all processes that use more than 1% of the CPU time. You can redirect this to a logfile.


There was some posting on this matter, Search : /proc/1/as
To my knowledge sending DCMD_PROC_TIDSTATUS brings back some statistical info, which might be used to measure CPU utilization.
Frankly said I have never tried this.

Thank you for the reply.

I tried hogs and the result printed out is what I was looking for. The only think is that I rather like to have more control over when to read the values and select for example only the idle thread to monitor. In one posting somebody mentioned to look into the source code of hogs. Is this possible since the source code is not available?

Concerning the other hint about the DCMD_PROC_TIDSTATUS:

Here I could only find:

_Uint64t start_time; /* thread start time in nsec /
_Uint64t sutime; /
thread system + user running time in nsec */

out of the debug_thread_t; struct defined in debug.h which may help to calculate the cpu load.

Strange think is that the start_time remains 0.

Do you see any other way to retrieve the cpu load?

Best regards,


You can use the ClockId() function to get a cpu clock for the idle thread - and then use ClockTime() to read it out. See this entry… openqnx.com/index.php?name=P … ic&p=24398

I smell a kernel guy. Aren’t clock_getcpuclockid() and clock_gettime() more portable?

Yes, there ARE clock_getcpuclockid() and pthread_getcpuclockid() but neither of those allows you to specify BOTH pid and tid, which is what you need here.
You should be able to use clock_gettime() though - that simply makes use of the clock id returned.