Cookbook

  • 2020
  • 06/18/2020
  • Public Content

Profiling Docker* Containers

Intel® VTune™
Profiler
allows you to profile applications running in Docker* containers, including profiling multiple containers simultaneously. This recipe guides you through the configuration of a Docker container and describes ways to use
VTune
Profiler
to analyze one or multiple concurrently running containers. This recipe also utilizes the Java* Code Analysis capabilities of
VTune
Profiler
.

Ingredients

This section lists the hardware and software tools used for the performance analysis scenario.
  • Application
    :
    MatrixMultiplication
    . This Java application is used as a demo and is not available for download.
  • Tools
    : Intel VTune Profiler 2020 - Hotspots analysis with Hardware Event-Based Sampling.
    • For
      VTune
      Profiler
      downloads and product support, visit https://software.intel.com/en-us/vtune .
    • All the Cookbook recipes are scalable and can be applied to Intel VTune Amplifier 2018 and higher. Slight version-specific configuration changes are possible.
    • Intel® VTune™ Amplifier has been renamed to Intel® VTune™ Profiler starting with its version for Intel® oneAPI Base Toolkit (Beta). You can still use a standalone version of the VTune Profiler, or its versions integrated into Intel Parallel Studio XE or Intel System Studio.
  • Linux container runtime
    : docker.io.
  • Operating system
    : Ubuntu* 17.04 based on Linux* kernel version 4.10 or newer.
  • 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
    • 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/config/daemon/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/install/linux/docker-ce/ubuntu/.
  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
  5. Run the container and keep it running using the
    -t
    and
    -d
    options:
    host> docker run -td myimage
    To analyze Docker containers with
    VTune
    Profiler
    using User-Mode Sampling or Memory Consumption analyses, 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 Hotspots analysis with Hardware Event-Based Sampling in the Profile System mode

  1. Launch the
    VTune
    Profiler
    on the host, for example:
    host> cd /opt/intel/vtune_
    profiler
    host> source ./vtune-vars.sh host> vtune-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. On the
    Configure Analysis
    tab, configure the following options:
    • On the
      WHAT
      pane, select the
      Profile System
      target type
    • Select the
      Hardware Event-Based Sampling
      mode
    • On the
      HOW
      pane, enable stack collection
  5. Click
    Start
    to run the analysis.
You can also profile Docker containers using the Attach to Process target type, but you will only be able to profile one container at a time.

Analyze Data Collected in the Containers

When the data collection is complete, the
VTune
Profiler
opens the results in the Hotspots
Summary
tab:
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 hottest function to identify the hotspot source code line for the function and analyze metric data collected for this line.
To view the performance data for individual Docker containers, group the data by
Container/Process/Function/Thread/Call Stack
and identify the containers by the
docker
prefix:
VTune
Profiler
also allows you to view the performance data for system binaries that are running inside a container. To do this, select the
Module/Function/Call Stack
grouping and locate the entries with the
docker
prefix in the
Module Path
column. This groping mode also allows you to view performance data for host system binaries and containerized system binaries simultaneously.
To discuss this recipe, visit the developer forum .

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804