Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am looking for tips to profile the server side game loop of a Java program for CPU usage. I tried to use the TPTP plugin for Eclipse so far.

The problem I am having is that it is really slow. For example the startup of the server is normally done in less than a minute. But with the profiler it takes about 30 minutes.

Okay, I can enable the profiler only after the server is started, but I am still facing the problem that it is way too slow and using much CPU. So I am unable to connect a number of clients in order to reproduce the problem (even with disabled timeouts).

I already did some optimization based on no client at all and some very short profiling sessions with one client. This is, however, not really helpful because the game server is doing most of its work only if a player is in reach.

I am thankful for any tips on profiling for CPU usage.

share|improve this question
    
Thank you Ricket for adding the profiling tag. –  Hendrik Brummermann Jul 24 '10 at 17:47

4 Answers 4

up vote 2 down vote accepted
+50

Netbeans has a pretty good profiler built in as well and its free! I struggled to get TPTP to work and YourKit always seemed slow. The Netbeans one seemed to be the best of the bunch.

Some profilers will allow you to mark points in your code where profiling should start and stop. This can definitely help when measuring performance.

However, a really good (but old school) means of debugging is print statements!

Try putting these in at various stages. You can then use a binary chop method to identify the slow bits. We do this all the time and its amazingly effective.

If you have good unit tests there are 3p libs that will allow you to put in timing restrictions i.e. fail the test if it takes more than nnn ms to complete.

share|improve this answer
    
While it was quite a hassle to get Netbeans to work (I am an Eclipse user), the profiler is really good. Especially the feature of defining a root method did the trick for me. –  Hendrik Brummermann Aug 2 '10 at 20:34
    
Really glad that helped. I am a longtime Eclipse user myself at work but now use Netbeans at home. –  Fortyrunner Aug 6 '10 at 22:27

I've had much better success profiling using YourKit for Java. I tried TPTP but it is very painful to use.

YourKit also allows for remote connection.

If you want a more simplified monitoring solution you can give JConsole a try. This is the bundled monitor program that is distributed with Java.

share|improve this answer

Yeah you have discovered the main problem with most profilers. They profile everything.

You can use options to reduce the profiling scope to some key classes or just time very small bits of your code.

You should already know what is probably slowing it down, so test that part. It will take some time to hunt down the slow bits, but I find it a lot more productive than using a uber slow profiler.

share|improve this answer

Have you tried adding your own "profiling" classes - eg a Timing class that you can call before/after key methods, which will log/track start/end/elapsed times. This could expand into tracking down potential problem areas. This should add only a small overhead. You could also have 2 versions a PROD vs PROFILE version so that you can switch to the PROD one when needed and thus gain back any of the added overhead.

share|improve this answer
    
+1, although it gets rather difficult if you have 100,000 with a logic() method that is called in the loop and only a small number of object are actually doing something. –  Hendrik Brummermann Jul 25 '10 at 14:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.