NetBeans – profiler test pack (Docker based)

If you want to test remote profiler in NetBeans, it might be quite a struggle. Main source of the problem lays in the fact, you need remote code running. You have few options here: locally started code (you can access it via localhost), Virtual Machine with all the components (JDK, source code, profiler pack), dedicated bare metal based solution (but you need a machine to spare). Anyway, in all cases you have to copy files back and forth, that’s a little struggle. Not to mention time required to setup environment on target machine.

There is, however, yet another way. It simplifies the whole process quite heavily. You can use Docker.

First of all, you need a Docker. But I assume that you either have it somewhere or you know how to install it: Docker.

Then, you need to create Remote profiling pack.

Let’s say, you have saved it here: /tmp/profiler-server-linuxamd64.zip. At the moment, Docker based solution supports only Linux (Intel/AMD) 64bit JVM.

All you have to do, is to build Docker image. Unfortunately,profiler-server-linuxamd64.zip must be at the same level as Dockerfile. You have to pass just one argument – location of JDK you want to install inside Docker container (jdk_location).

> git clone https://github.com/mkowsiak/ProfilerDocker.git
> cd ProfilerDocker
> cp /tmp/profiler-server-linuxamd64.zip ./profiler-server-linuxamd64.zip
> docker build -t profiler \
--build-arg jdk_location=\
"https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz" \
.

Once you have image created, you can run it: docker run -p 5140:5140 profiler.

As you can see, Java is waiting for a profiler to connect on port 5140. All we have to do is to press Attach inside NetBeans.

That’s it! Profiled code starts to roll, and you can observe results inside NetBeans.

Note 1: In case you are running on macOS make sure to set memory to some reasonable size. Otherwise, your Java code will fail with java.lang.OutOfMemoryError. Take a look here: Docker and memory settings

Note 2: Sometimes, it’s good to clean Docker images so you don’t run out of disk sapce. Take a look here: Cleaning Docker images.