The Artima Developer Community
Sponsored Link

Java Answers Forum
Measuring CPU, Memory Usage and I/O in Java

6 replies on 1 page. Most recent reply: Dec 22, 2002 5:43 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
John William Blair

Posts: 3
Nickname: jwblair
Registered: Dec, 2002

Measuring CPU, Memory Usage and I/O in Java Posted: Dec 20, 2002 11:48 AM
Reply to this message Reply
Advertisement
Can anyone tell me how to get the following program statistics in Java?

CPU Usage of the program
Memory Usage of the program
I/O Usage of the program

Is there a simple way to do this?

Thanks!


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Measuring CPU, Memory Usage and I/O in Java Posted: Dec 20, 2002 3:13 PM
Reply to this message Reply
This is platform dependent, of course. What platform do you want to do this on?

John William Blair

Posts: 3
Nickname: jwblair
Registered: Dec, 2002

Re: Measuring CPU, Memory Usage and I/O in Java Posted: Dec 20, 2002 3:30 PM
Reply to this message Reply
I would like to do this on the Windows XP Platform.

Thanks!

Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Measuring CPU, Memory Usage and I/O in Java Posted: Dec 21, 2002 9:29 AM
Reply to this message Reply
I am interested in this too. A head start is all I would need ;)

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Measuring CPU, Memory Usage and I/O in Java Posted: Dec 21, 2002 6:06 PM
Reply to this message Reply
If you want the quick 'n' dirty approach, you could do this: dynamically create a jscript file that uses WMI to get performance info, which is communicated back via a text file in the %temp% directory.

The less quick, less dirty approach would be to use JNI. The C/C++ implementation of the native stuff could either get the information from the HKEY_DYN_DATA portion of the registry, or also use WMI (using WMI from C++ is a little messier than from jscript, of course, but possible nonetheless).

Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Measuring CPU, Memory Usage and I/O in Java Posted: Dec 22, 2002 5:11 PM
Reply to this message Reply
From the little I know about Windows systems, I learnt that HKEY_DYN_DATA is for 95/98/Me systems. Surely theres got to be an API call that works for all Windows systems. ps -aufwx on Linux gives details about each process. Since there is a parent for each process, its not hard finding the resources taken by an application.

On a separate note, I wonder how much the JVM knows about the memory its eating on its host system.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Measuring CPU, Memory Usage and I/O in Java Posted: Dec 22, 2002 5:43 PM
Reply to this message Reply
There is the GlobalMemoryStatus() API call for getting memory usage and GetProcessTimes() for performance data on processes. There are also the ToolHelp functions for finding out about what processes are running. As I said before though, these days Microsoft is pushing WMI as the way to get all this information.

The IntelliJ IDEA Java editor shows memory usage on its status bar. I don't know whether they do this with JNI and check for which platform, or whether they figured out some other tricks. I think they might be doing it from within Java (maybe there is some way to ask the JVM how much memory you are using?), because its numbers are low; when its status bar says "20M of 32M," for example, the windows task manager says it is using more than 46M.

Flat View: This topic has 6 replies on 1 page
Topic: help with a if statement Previous Topic   Next Topic Topic: bmp to jpeg....urgent help required

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use