1827294 Members
1767 Online
109717 Solutions
New Discussion

Re: cpu utilization

 
bob giuffre
New Member

cpu utilization

I need to determine my cpu utilization without spawning a process. top, glance, and sar cannot be used. does anyone know of a system call that will return the cpu utilization?

i have looked at getconf and sysconf but they do not seem to have this variable as a return.

Thanks, bob giuffre
22 REPLIES 22
Santosh Nair_1
Honored Contributor

Re: cpu utilization

Well I suppose you could write a program that makes a system call to the pstat routines, more specificially pstat_getprocessor.

-Santosh

P.S. Hi bob :-)
Life is what's happening while you're busy making other plans
James R. Ferguson
Acclaimed Contributor

Re: cpu utilization

Hi Bob:

Take a look at pstat(). See "man 2 pstat". 'ps' uses this interface to gather much of its information.

Regards!

...JRF...
Santosh Nair_1
Honored Contributor

Re: cpu utilization

Also, if you have measureware already running on this system you can use PerfView from another system to connect to this system and get performance data.

-Santosh
Life is what's happening while you're busy making other plans
Sridhar Bhaskarla
Honored Contributor

Re: cpu utilization

You might want to check pstat_getdynamic routine.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
John Poff
Honored Contributor

Re: cpu utilization

You can code the 'pstat' function in a C program, but it too will use a process to run. I don't see how you can get real time monitoring of the CPU without some kind of process running. You can use MeasureWare or sar to get the CPU usage after the fact.

What exactly are you trying to measure? Do you have a system that is so loaded that you can't run top/glance/sar? Or are you trying to just measure the performance of a particular program? There are some ways to measure things, but you have to give up something to do it.

JP
James R. Ferguson
Acclaimed Contributor

Re: cpu utilization

Hi (again) Bob:

Ah, the Heisenberg Uncertainty Principal... ;-)

...JRF...
Santosh Nair_1
Honored Contributor

Re: cpu utilization

James,

Arggg...flashbacks from high school chemistry :-)

-Santosh
Life is what's happening while you're busy making other plans
bob giuffre
New Member

Re: cpu utilization

Thanks everyone for the fast replies.

However, I cannot afford to kick off another process, program, or SNMP call within my system.

Any ideas for a system call to give me a snapshot of the cpu utilization?
bob giuffre
New Member

Re: cpu utilization

Please!! I taught high school chemistry for four years.

Remember orbital hybridization? Well, neither do any of my students!!
Santosh Nair_1
Honored Contributor

Re: cpu utilization

Bob,

Unfortunately, I don't believe there's any way to make a system call without spawning another process...again, if you already have measureware running, you can connect to the measureware daemons from another machine using perfview...but short of that, I think you're out of luck.

-Santosh
Life is what's happening while you're busy making other plans
Sridhar Bhaskarla
Honored Contributor

Re: cpu utilization

You wrote you tried getconf. Even if it worked, it's a command again, and is going to spawn a process. You gotta somehow solve the schodinger's equation to get the status of the particle.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
John Poff
Honored Contributor

Re: cpu utilization

Oh no! Chemistry? I flunked that my first year in college and had to take it again! :)

Hmmmm. If you are running on a K-class or a V-class system, you can look at the LCD display on the side and see the CPU usage in one of the digits displayed. I'm not sure if you can get similar information from other classes of systems, but if you can, these wizards will know how to do it.

JP
linuxfan
Honored Contributor

Re: cpu utilization

Hi Bob,

Do you already have any data collected (sar, measureware) then you can analyze the data on a different machine.

BTW, thanks to my chemistry classes, i still know and love "C2H5OH (ethyl alcohol)" ;-)

Just an atom of thought

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
James R. Ferguson
Acclaimed Contributor

Re: cpu utilization

Hi Folks:

...well, you have to admint that wave theory and electron shells (no pun intended) were interesting!

Regards to all!

...JRF...
linuxfan
Honored Contributor

Re: cpu utilization

Hi Bob,

I know of a way to check the CPU utilization without spawning another process on the running system, TURN the POWER OFF, the CPU utilization will definitely be known ;-)

Disclaimer: If you want the HP's promise of 5 Nines then you wouldn't want to try the above recommendation.

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Sanjay_6
Honored Contributor

Re: cpu utilization

Paula J Frazer-Campbell
Honored Contributor

Re: cpu utilization

Hi Bob

Back to basic principles - you cannot get something for nothing, and you have to balance the equation.

No matter what you do you will have to use a process to get it. If your machine is that loaded that you cannot use another process then you are in deep dodo. (Technical expression meaning in a waterey place without a paddle).

top -q -d 1 - will jump in and out of top and produce just one screen display the -q will force top in at a high priority and get the info.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Mike Stroyan
Honored Contributor

Re: cpu utilization

There seems to be a deep misunderstanding here.
pstat_getdynamic is just fine.
It is a system call that does not start another process.
Folks are just being pedantic trying to point out that your program making the system call is a process.
A program can call pstat_getproc to find out how much cpu time one particular process is using.
I have attached one example program that calls pstat_getdynamic to get the load average. I also included an example program that watches its own behavior and tries to maintain a specific cpu load.

P.S. Watch out for changes to the reported load average that occured in 11i. They are changed back in patch PHKL_24551.
bob giuffre
New Member

Re: cpu utilization

Thanks for all the replies....I think we are heading in the right direction.

Unfortunately, the systems in question are pretty much maxed out. I can't run either 'sar' or 'top' because these will take resources. The current strategy of using an SNMP get from the MIB also takes resources.

I need something like the low level call that 'sar' makes to the system to get the cpu value, then have this process quit. I can then invoke this as needed. Any suggestions?
Sridhar Bhaskarla
Honored Contributor

Re: cpu utilization

Bob,

If you do a strings on sadc, you can clearly see all the pstat routines. The problem here is, either you need to write a program or embed these routines in the C programs that are already running. You cannot simply run them at the command prompt and get the CPU utilization. Even if you write a small C program, it will become a process. This is the reason why all the Quantum Mechanics has been brought up.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
John Poff
Honored Contributor

Re: cpu utilization

Hello Bob,

Here is the real question: Do you have access to the source code of the programs running on these machines? If so, you can add in the function discussed above. If not, there is not much you can do.

Pedantically yours,

JP
Bill Thorsteinson
Honored Contributor

Re: cpu utilization

If you are so maxed out that you can't afford to gather the stats required to get out of the fix you are in deep.

You should be looking at the output of glance, top,
sar, or something for a few minutes to get a feel
for where your resources are being maxed out.
If you have idle cpu or excessive sys load then
you may be able to tune your way of the the corner.

See if you can find five or ten minutes a day at near
peek load to identify the bottlenecks. Then you can
move the bottleneck towards a resource that isn't
overloaded.

If you have no idle time, you may have some processes
you can nice down or move elsewhere to free up
some cpu.