TopJ

What is TopJ?

TopJ is a lightweight and powerful real-time Java method timing agent for JVMs. It can find where the bottlenecks are in your Java code so you can increase the performance of your running JVM. It does this by utilising the award-winning ByteBuddy library to instrument classes and times method calls at nano second precision. These method calls are sorted by average usage so that you can quickly investigate performance latencies.

The software is similar in nature to JEP 520, but can work with JVM versions >=11.

Here's a sample output from a test class:

As you can see TopJ has ranked the method calls with the bottleneck method at the top as expected.

Here's a sample output when running with Spring Boot:

Top marks from TopJ for Spring Boot - very optimised! The ones at the top are due to decompression of archives so not much you could do there apart from pre-decompress.

So why does it take 6 seconds to boot up? Well if you have a look at the stack at full boot-time after all initialization has completed:

It's due to de-serialization of JSON and a significant amount of method calls. This could be improved by changing from JSON to binary object mapping and reducing method call quantity.

It's been tested on production JVMs with 1000s of method calls and the efficiency savings when you isolate and fix methods can range from a few % to 10s of %. Other example test cases are for Hazelcast, Kafka and Spring-Boot.

How to Use

Simply download the Jar file below and attach as an agent to your running JVM:

java -javaagent:/path/to/TopJ.jar Tests

This will run TopJ in default mode, which is the top 20 methods of all user classes printed to System.out when the JVM shuts down.

You can modify the settings on the command line like this:

java -javaagent:/path/to/TopJ.jar=<interval secs>,<topX>,<regex>,<out/err> Tests

Example for TopJ printing the top 2000 of all classes to System.err every 3 seconds:

java -javaagent:/path/to/TopJ.jar=3,2000,".*",err Tests

If you use a lot of 3rd party libraries, you may want to solely focus just on your classes:

java -javaagent:/path/to/TopJ.jar=3,2000,"com.my.package",err Tests

Download

[TopJ] sha256sum:a05f67ad6fa54f50f5f231954a745c01d2fe68ab3f4c75e9658b17a5f110f5bc  4406128 bytes

Troubleshooting

Due the complexity of reflection, lambdas and various other quirks involving class loading you may get errors such as java.lang.StackOverflowError. To avoid these errors you may need to omit classes and packages using the regex parameter. Remember to focus only on the classes of interest.
DeployJ.com