Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Measure Java CPU usage

 
SivaramaKrishnan Nageswaran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm not sure whether this is the right forum to post this message.

I have a java application and basically it takes lots of CPU time and memory. What my concern right now is the CPU usage. Basically I reduced the number of CPUs from 8 to 4 (Solaris v1280 box) and the CPU usage got increased from 30% to 90%

My requirement: Is there anyway that I can measure the CPU usage using Java code itself, so that I can insert those "set of APIs" (for measuring CPU usage), between APIs to collect the CPU usage data?

Thanks,
Siva
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Javaranch. You can monitor a JVM using the management api (JMX). However, that will just tell you what you already know: Your program uses a lot of CPU. What you want is a code profiler like JProfiler or JProbe. They will help you determine where the bottlenecks are in your code and benchmark alternate implementations.
 
SivaramaKrishnan Nageswaran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does JDK 1.3.1 have support for JMX ? And is that also possible to measure the CPU usage of every thread using JProbe? Because so far (as far as I know), Jprobe gives the memory usage and hasn't seen the CPU usage. Can you also tell the procedure for getting the CPU usage using JProbe?

Thanks
Siva
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by SivaramaKrishnan Nageswaran:
Does JDK 1.3.1 have support for JMX ?

Not that I know of.

Jprobe gives the memory usage and hasn't seen the CPU usage. Can you also tell the procedure for getting the CPU usage using JProbe?

You must be looking at the Memory Debugger. There's another product called the Profiler which is used to identify bottlenecks. There's tutorials provided with JProbe which will teach you how to use it. Profiling is not as easy as hitting a button and getting a report. You need to learn how to use the tools effectively so you can figure out what changes will do the most good.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic