• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cpu utilization

 
magi devi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to find cpu utilization using java in windows system
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, using pure Java. You would have to use native code and JNI.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Peter is right. But if you want to invoke the TaskManager you can try following on windows.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic