6
\$\begingroup\$

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.

\$\endgroup\$
0

4 Answers 4

2
+50
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ Aug 2, 2010 at 20:34
  • \$\begingroup\$ Really glad that helped. I am a longtime Eclipse user myself at work but now use Netbeans at home. \$\endgroup\$ Aug 6, 2010 at 22:27
3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ +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. \$\endgroup\$ Jul 25, 2010 at 14:34
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .