Profiling a Java* Application in a Docker* Container

This recipe guides you through the configuration of a Docker container for the Intel® VTune™ Amplifier analysis to identify hotspots in a Java application running in the isolated container environment.

Note

Advanced Hotspots analysis was integrated into the generic Hotspots analysis starting with VTune Amplifier 2019, and is available via the Hardware Event-based Sampling collection mode.

Ingredients

This section lists the hardware and software tools used for the performance analysis scenario.

  • Application: MatrixMultiplication. The application is used as a demo and not available for download.

  • Tools: Intel® VTune™ Amplifier 2018 - Advanced Hotspots analysis

    Note

    • For trial VTune Amplifier downloads and product support, visit https://software.intel.com/en-us/vtune.

    • All the Cookbook recipes are scalable and can be applied to VTune Amplifier 2018 and higher. Slight version-specific configuration changes are possible.

  • Linux container runtime: docker.io

  • Operating system: Ubuntu* 17.04

  • CPU: Intel® microarchitecture code named Skylake with 8 logical CPUs

Install and Configure a Docker* Container

  1. [Optional] Remove a previous Docker version from your host system, if required:

    host> sudo apt-get remove docker
  2. Install Docker:

    host> sudo apt-get update
    host> sudo apt-get install docker.io

    Note

    • The version of the Docker container runtime depends on your OS version. To know your version, enter: apt-cache search "container runtime"

    • If you cannot install the package, make sure you have the proxy server configured in the Docker systemd service file. Details are available at https://docs.docker.com/engine/admin/systemd/#httphttps-proxy. Follow steps 1-6 and replace the proxy in the example with your proxy name.

    • More installation details are available at https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#install-docker-ce.

  3. Create a Docker image:

    host> cd /tmp
    host> touch Dockerfile
     host> echo FROM ubuntu:latest > ./Dockerfile
     host> docker build -t myimage .
    Sending build context to Docker daemon 6.295 MB
    Step 1: FROM ubuntu:latest
    e0a742c2abfd: Pull complete
    486cb8339a27: Pull complete
    dc6f0d824617: Pull complete
    4f7a5649a30e: Pull complete
    672363445ad2: Pull complete
    Digest: sha256:84c334414e2bfdae99509a6add166bbb4fa4041dc3fa6af08046a66fed3005f
    Status: Downloaded newer image for ubuntu:latest
    ---> 14f60031763d
    Successfully built 14f60031763d
    
  4. Make sure the image myimage is created:

    host> docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    myimage             latest              14f60031763d        2 weeks ago         119.5 MB
    

    Note

    Alternatively, you may choose to load a tarred repository from a file: docker load -i image.tar

  5. Run the container and keep it running using the -t and -d options:

    host> docker run -td myimage

    Note

    To run a Docker container for the VTune Amplifier's algorithm analysis (Basic Hotspots, Concurrency or Locks and Waits), make sure to enable the ptrace support as follows:

    host> docker run --cap-add=SYS_PTRACE -td myimage

    or launch the container in the privileged mode:

    host> docker run –-privileged -td myimage
  6. Check the container ID:

    host> docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    98fec14f0c08        myimage             "/bin/bash"         10 seconds ago      Up 9 seconds                           sharp_thompson
    
  7. Use the container ID to get bash into this container in the background mode:

    host> docker exec -it 98fec14f0c08  /bin/bash
  8. Copy your Java application with the JVM to the running Docker instance. For example:

    host> docker cp /home/samples/jdk1.8.tar 98fec14f0c08:/var/local
    host> docker cp /home/samples/matrix.tar 98fec14f0c08:/var/local
  9. Extract the matrix.tar and jdk archives.

Run Advanced Hotspots Analysis in the Attach Mode

  1. Launch the VTune Amplifier on the host, for example:

    host> cd /opt/intel/vtune_amplifier_2018.0.2.522558
    host> source ./amplxe-vars.sh
    host> amplxe-gui
  2. Create a project for your analysis, for example: matrix_java.

  3. Run the Java application within the container:

    container> cd /var/local/matrix
    container> /var/local/jdk1.8.0_72-x64/bin/java -cp . MatrixMultiplication 2000 2000 2000 2000                
  4. Run the top command to get the PID of the java process.

  5. Configure the Analysis Target tab to select:

    • local host target system

    • Attach to Process target type

    • PID (Process ID) for java, for example: 24116:

    • Click the Binary/Source Search button on the right to specify a search path to your sources located on the host:

      VTune Amplifier searches this path to associate a hotspot with the source code and exact machine instruction(s) that caused this hotspot.

  6. Switch to the Analysis Type tab, select the Advanced Hotspots analysis type, and choose the Hotspots and stacks option:

  7. Click Start to run the analysis.

Analyze Data Collected in the Container

When the data collection is complete, the VTune Amplifier opens the results in the default Hotspots viewpoint:

The Top Hotspots section of the Summary view shows that the multiply function of the target application took the most CPU time. Click the function in the list to switch to the Bottom-up tab and view the stack flow for this hotspot function:

For further analysis, double-click the hotspots function to identify the hotspot source code line for the function and analyze metric data collected for this line.

To get statistics on the Docker container modules, group the data by Module/Function/Call Stack and identify the container modules by the docker entry in the module path:

Note

To discuss this recipe, visit the VTune Amplifier developer forum.

For more complete information about compiler optimizations, see our Optimization Notice.