Operating System - HP-UX
1825729 Members
2642 Online
109687 Solutions
New Discussion

how to get cpu usage in c++

 
eric wang_2
Frequent Advisor

how to get cpu usage in c++

I would like to calcuate CPU usage in multiple CPU condition,
I would like to use API like pst_dynamic

cpu usage=1-CPU IDLE% or USER+NICE+SYS+BLOCK+SWAIT+INTR+SSYS

is any api can calcuate it
because i use summary all process usage /number of cpu is not ccurate

how to do program get cpu usage in c++

thanks


5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: how to get cpu usage in c++

Hi:

I'd look at 'pstat_getprocessor()'. see the 'pstat(2)' manpages.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: how to get cpu usage in c++

>how to do program get CPU usage in C++

The answer is the same as for C.
You'll need to scan the various pstat(2) headers in and what they include, to see which call gives the info you need.
eric wang_2
Frequent Advisor

Re: how to get cpu usage in c++

thanks for your reply,
I would like a workable cpu usage program example for hpux ,i search for a long time in web site ,but still have no idea how to do it
Dennis Handly
Acclaimed Contributor

Re: how to get cpu usage in c++

JRF's pstat_getprocessor returns a pst_processor, see .

pst_dynamic also looks like it would give usage by CPU.

James R. Ferguson
Acclaimed Contributor

Re: how to get cpu usage in c++

Hi (again):

> I would like a workable cpu usage program example for hpux ,i search for a long time in web site ,but still have no idea how to do it

The 'pstat(2)' manpages offer some examples, including one using both the 'pst_dynamic' and the 'pst_processor' structures.

You will need to look at the header files (on your system: 'ls -l /usr/include/sys/pstat*' ) and as documented in the manpages for the specific data you can glean.

Regards!

...JRF...