• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

cpu utilization

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

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic