wood burning stoves*
The moose likes Java in General and the fly likes cpu utilization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "cpu utilization" Watch "cpu utilization" New topic
Author

cpu utilization

magi devi
Greenhorn

Joined: Mar 12, 2006
Posts: 2
how to find cpu utilization using java in windows system
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You can't, using pure Java. You would have to use native code and JNI.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Yes Peter is right. But if you want to invoke the TaskManager you can try following on windows.



java j2ee job interview questions with answers | Learn the core concepts and the key areas
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
You might look into the tasklist command since it will write to standard output that you can capture and interpret in your java program. Try
tasklist /?
for online details. Let us know if you come up with something cool.
Bill


Java Resources at www.wbrogden.com
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

All the taskmgr does is pull from the system counters. With Windows XP pro, these same counters are also available with the typeperf command. This command prints to stdout, so you can parse the result from Java.

Try:

typeperf "\processor(_Total)\% Processor Time"

This will give you the total processor ultilization in terms of percentage.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
Great call Henry, I had missed the typeperf command. Incidently I just realized my only book on Java Threads is your first edition so a copy of the latest is on its way from Amazon.
Bill
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

I have to admit that I really like the typeperf command. There doesn't seem to be an equivalent in unix (except maybe the /proc filesystem for some stuff).

The command will tell you every single little detail about system. Heck, on a laptop, it will tell you how much power you have remaining in the batteries...

Henry


BTW, Bill, Thanks...
Mahadevan Gorti SS
Greenhorn

Joined: Jan 31, 2006
Posts: 18
Apart from 'typeperf' -- which is not available in other Windows versions(one has to download from web with possible non-working version of typeperf.exe in another windows version), one can use 'pslist.exe' from http://www.sysinternals.com. pslist.exe is available in http://www.sysinternals.com/Utilities/PsTools.html.

pslist will also be useful for one to see which thread is taking more time(OR doing tight loops in a JVM).


If you JDK 1.5 onwards, pure java code without resorting to Runtime.exec ( which is costly) using JMX package java.lang.management. The JMX-bean/classes you are interested are:
* ThreadInfo
* ThreadMBean
[ March 24, 2006: Message edited by: Mahadevan Gorti SS ]
Martin Simons
Ranch Hand

Joined: Mar 02, 2006
Posts: 196
typeperf seems to be a conglameration of unix commands that simply
uses differing parameters rather than differing commands to get the
info. What you seem to be getting from this is the same information
that you can get from a grouping of the commands ps, sar, psradm and
a few others on unix systems.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cpu utilization
 
Similar Threads
does CPU utilization measure applications performance
UnMarshalling and Marshalling
Threadcount vs Memory size/CPU utilization
XML Parsing and Validation with SAX parser shoots CPU to 100% utilization
Jboss Monitoring Tools