jme

A while ago I got reminded about what a wonderful tool JConsole is. It allows you to see a lot of information about a running JVM (like heap, threads and other things).
I thought I'd put together a little AppState that could expose the render statistics through JMX so that they are readable in JConsole.

The render statistics is the stats you see in the bottom left corner in your SimpleApplication. Read more about it at the jMonkeyEngine Wiki

Now since you can see them in real time in your application already why would you want to see them through JConsole? Good question, the short answer is "because you can" :-) It costs next to nothing (in performance) to keep this appstate in the loop and who knows, it might be useful. You might even want to write an alternative to JConsole. For example a panel i jME SDK that shows these stats there instead of cluttering your game screen.

AppState
Attached to this page (at the bottom) you'll find a small zip-file with the source code for the app state I put together. Add these to the source code. Yes you may rename the classes and packages - I don't care :-)
When the classes are in your project and compiles you can attach the state in your simpleInitApp like so:

getStateManager().attach(new StatViewJMXAppState());

Then run your application like you always do.

JConsole
Since maybe not all of you know about JConsole I'll write a little tutorial here.
This is a tool that comes with the JDK so you already have it installed. Just open a terminal and type jconsole. You'll see something like this:
Isn't this cool, it finds all running JVMs on your machine and offers to hook up to them!

Select your running game and press "connect" and you'll see all kinds of neat statistics from the JVM like heap usage, loaded classes and so on. Now select the "MBeans"-tab.

If the appstate is attached you'll see a folder to the left saying "nu.zoom.jme.jmx". Open that and have a look at the stats:
Nice :-) The only drawback is that these do not refresh automatically, this is in the nature of JMX and not much to do about. The positive side is that since the app state only refreshes on demand it puts a very light load on the application game loop. 
If you need the fresh numbers go to the "Operations" branch and invoke the refreshStatistics operation. 
This will cause the appstate to re-read the statistics from the renderer. 



Enjoy your new JMX enabled application :-)

ċ
src.zip
(7k)
Johan Maasing,
12 juni 2012 11:37
Comments