File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes CPU usage monitoring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "CPU usage monitoring" Watch "CPU usage monitoring" New topic
Author

CPU usage monitoring

Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I've done no research, so I'm open to be flamed.

Is there any way to detect what the cpu is doing while your program is running? My thought is that I could run a 'stress test' on the computer the program is running on. Depending on the results, it would set program options differently at runtime. I could turn off music or load lower quality images, etc.

Any info?
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
You run loops and test the start and finish time with System.currentTimeMillis (). Not sure what that would prove, though.


The nice thing about Standards is that there are so many to choose from!
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Is there any way to detect what the cpu is doing while your program is running?

The standard way to answer this question in a systematic manner, as well as to identify the bottlenecks and to improve the performance of your app is to use a profiler. The are many different ones on the market, such as OptimizeIt, JProbe, and others. As you profile the app, you get a report of how much time is spent in each method (or even on each line) of your code. The practice shows the 80-20 rule: 20% of the code runs 80% of the time. Once the 20% is identtified, it can be optimized to improve the performance. This discussion clearly belongs to the "performance" forum here.
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I haven't gotten my real question across. I'm not trying to profile the performance after its run. I want to adjust the performance WHILE its running. If I were making a game, I would want it to be the best experience I could. On a super fast computer, having all the graphics and sounds turned on and the AI would be fine. On an older computer, maybe the AI routine needs to be turned down a bit and the graphics adjusted by using smaller textures.

You can optimize a program, but until its running on the actual machine, you won't know how its going to perform. I want to check the CPU load while my app is running and then adjust how the program is running. This isn't really a performance issue, so much as what a specific computer can handle one.

On another forum, some one mentioned my only solution was JNI. I had hoped this wasn't the case, as it will lose its platform independence.

Any other information available?

Regards,
Aaron R>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can't easily tell what they CPU is doing, but you can tell what your program is doing. Some critical method might keep track of max, min and average elapsed times for the last "n" calls and adjust its internal algorithms, perhaps switch between strategies.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
Thats not a bad idea. I know trying to 'profile' code that way is usually frowned up, but maybe for doing what I'm aiming at, it might be ok. The only difficulty might be in trying to easily figure out where the acceptable range is.

Thanks for the input!

Regards,
Aaron R>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hmmm, frowned upon? We do that kind of thing in production and report when anything goes over 3 seconds. It's a valuable indicator of trouble. We often know of slow-downs or failures before the users call us to complain.

I built something that keeps stats on any method for a configurable number of intervals of a configurable length, say the last 60 1-minute intervals for an hour's worth of data. Each interval tracks number of calls, max, min and average time. The code in the method is simple:

This will go in the next release.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CPU usage monitoring