Author : Kiselev, Sergey (Intel)
Intel® System Studio – Intel® VTune™ Amplifier
Profiling C++ Application in Docker* Container
Intel® VTune™ Amplifier 2018 included with Intel® System Studio 2018 adds the container targets profiling feature. This feature allows profiling native or Java* applications running in an LXC*, Docker*, or Mesos* container on a Linux* system. This article gives an example of setting up a C++ application in a Docker* container, and profiling it using Intel® VTune™ Amplifier 2018.
The following hardware and software components are required for the profiling applications in the container environment:
- Host system with supported OS: Windows* or Linux*
- Intel® System Studio 2018 installed on the host system
- Target system with supported OS – Ubuntu* Linux*
- Docker* container platform installed on the target system
- Network connection between the host and the target system
It is possible to use the same system as both the host and the target, and run the Docker* containers and Intel® VTune™ Amplifier on that system.
The target system needs to have an SSH server installed. The password-less SSH login is required for Intel® VTune™ Amplifier in order to connect to the remote system. Please refer to Configuring SSH Access for Remote Collection section of Intel® VTune™ Amplifier 2018 Help for the password-less SSH login setup instructions.
The target Linux* system needs to have Sampling Drivers installed in order to run Advanced Hotspot analysis. Please refer to Building and Installing the Sampling Drivers for Linux* Targetsdocument.
Installing and Configuring Docker* Container
On your target system, open a terminal, and run the following commands to install Docker*:
$ sudo apt update $ sudo apt install docker.io
Creating and Running Ubuntu* Linux Based Docker* Container
Run the following commands to create an Ubuntu* Linux based Docker* image:
$ mkdir vtune-sample $ cd vtune-sample $ echo FROM ubuntu:latest > Dockerfile $ docker build -t vtune-sample .
Make sure that vtune-sample image has been created:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE vtune-sample latest 20c44cd7596f 2 weeks ago 123MB
Run the container and keep it running using the -t and -d options:
$ docker run -td vtune-sample
Installing Build Tools in the Container
Check the container ID:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 532c7d19c91b vtune-sample "/bin/bash" 8 seconds ago Up 6 seconds nostalgic_lamport
Use the container ID to run bash shell in this container in the interactive mode:
$ docker exec -it 532c7d19c91b /bin/bash
Run the following commands in the container’s bash shell to install build-essential package in the container:
root@532c7d19c91b:/# apt update root@532c7d19c91b:/# apt install -y build-essential
Deploying matrix_sample to the Container
Run the following command to copy the matrix sample to the container:
$ docker cp <path_to_vtune_samples>/matrix_vtune_amp_xe.tgz 532c7d19c91b:/home
Intel® VTune™ Amplifier 2018 samples are normally located in the following directories:
Linux* host: /opt/intel/system_studio_2018/vtune_amplifier_2018/samples/en/C++/
Windows* host: C:\IntelSWTools\system_studio_2018\Vtune_Amplifier_2018\samples\en\C++\
Run the following commands in the container’s bash shell to extract and build the matrix_sample:
root@532c7d19c91b:/# cd /home/ root@532c7d19c91b:/home# tar xf matrix_vtune_amp_xe.tgz root@532c7d19c91b:/home# cd matrix/linux root@532c7d19c91b:/home/matrix/linux# make gcc
Running Advanced Hotspot Analysis
Starting Intel® VTune™ Amplifier on Linux* host
Run the following commands to start the Intel® VTune™ Amplifier GUI:
$ source /opt/intel/system_studio_2018/vtune_amplifier_2018/amplxe-vars.sh $ amplxe-gui
Starting Intel® VTune™ Amplifier on Windows* host
Click on the Start/Windows button and search for “vtune”. Click on the Intel VTune Amplifier 2017 for Systems icon.
Configuring the Analysis Target and Analysis Type
Create a new project in the Intel® VTune™ Amplifier, and configure it as follows:
- Select a target system to profile: Configure it according to your host and target setup. Use remote Linux (SSH) for a remote/separate target, or use local host when using the same system to run Intel® VTune™ Amplifier and Docker* container. The screenshot below shows the local option
- Select a target type to profile: Select Attach to Process
- Select Process name radio button, and enter matrix.gcc in the process name field. At this point you might see a warning about the process not running on the system.
Start matrx.gcc process in the container’s bash shell:
If needed click on the Retry button in the Intel® VTune™ Amplifier GUI
Next, click on the Choose Analysis button, and configure the Analysis type as follows:
- Select Advanced Hotspots analysis
- Select Hotspots and stacks option
Click on the Start button to start the analysis
Analyzing the Collected Data
Once analysis is complete, the Intel® VTune™ Amplifier opens the Summary tab:
Click on the Bottom-up tab to view the detailed information.
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:
- Intel® System Studio: /content/www/us/en/develop/tools/system-studio.html
- Getting Started with Intel® VTune™ Amplifier 2018: https://software.intel.com/en-us/get-started-with-vtune
- Configuring SSH Access for Remote Collection: https://software.intel.com/en-us/vtune-amplifier-help-configuring-ssh-access-for-remote-collection
- Building and Installing the Sampling Drivers for Linux* Targets: https://software.intel.com/en-us/vtune-amplifier-help-building-and-installing-the-sampling-drivers-for-linux-targets
- Intel® VTune™ Amplifier 2018 Help - Profiling Container Targets: https://software.intel.com/en-us/vtune-amplifier-help-profiling-container-targets
- Intel® VTune™ Amplifier Performance Analysis Cookbook - Profiling a Java* Application in a Docker* Container: https://software.intel.com/en-us/vtune-amplifier-cookbook-java-profiling-in-docker-container