Table of Contents

Laboratorul 10 - Analiza Performantei Programelor

The purpose of this lab is the familiarization with the field of application profiling & debugging, through the means of dedicated tools for spotting performance bottlenecks.

We will focus on several open source and commercial tools, as follows:

1. Valgrind / KCachegrind

Valgrind is a tool used for memory debugging, memory leak detection and profiling. It is also a generic framework for creating dynamic analysis tools, such as memory checkers [1].

Valgrind is in essence a virtual machine using just-in-time compilation techniques, including dynamic recompilation. It is important to keep in mind that nothing from the original program ever gets run directly on the host processor. Instead, it will translate the input program into a simpler form called Intermediate Representation (IR), which is processor neutral. After this transformation, a tool [2] is called to do whatever transformation of the IR it needs and the resulting IR is then translated back into machine code and ran on the host processor.

The tools available in Valgrind are:

2. Analysis of the Tachyon raytracing engine

In this section, we will focus on analyzing a software application. We will analyze both a serial and a parallel implementation. The application is called “tachyon” and you can find the source code attached to this lab.

On your own system, before compilation, you must install the X11 dev tools and create a set of symlinks. For Ubuntu 64 bit, we must do the following:

To compile it, you must extract the archive Tachyon to local disk and run make. You can test the compilation by running in the same directory:

./tachyon_find_hotspots dat/balls.dat 

You should see a window like the one below:

To run and observe the functionalities of this tool, follow the following sequence of steps and instructions:

wget -O tachyon_vtune_amp_xe.tgz http://ocw.cs.pub.ro/courses/_media/asc/lab6/tachyon_vtune_amp_xe.tgz 
gunzip tachyon_vtune_amp_xe.tgz
tar -xvf tachyon_vtune_amp_xe.tar
cd tachyon
make

Using Valgrind on the Tachyon Code

1. Make sure you have Valgrind and KCachegrind installed on the system (or login on the hp-sl.q queue) and the application in the initial state, without any modifications on your system

sudo apt-get update
sudo apt-get install valgrind kcachegrind

2. We will use the tool callgrind to get information from the running application. Run the following command line:

valgrind --tool=callgrind --collect-jumps=yes --dump-instr=yes --collect-systime=yes -- ./tachyon_find_hotspots dat/balls.dat

3. Open the profile in KCachegrind and click on the Calee Map tab. Also, make sure that the buttons % Relative, Cycle detection and Relative to parent are selected. You should see something like this: From this image, we can see that valgrind measured that about 78% of the total time was spent in the initialize_2D_buffer function. Double click the square containing the function name, then select the “Source code” tab and you will see the problematic code.

3. Perf

Perf is a performance analysis tool, available in the Linux kernel since version 2.6.31 [5]. The userspace control application is accessed from the command line and provides a number of subcommands. Unlike Valgrind, perf is capable of statistical profiling of both the entire system (kernel and userspace) and per process PID basis. It supports hardware performance counters, tracepoints, software performance counters (e.g. hrtimer), and dynamic probes (for example, kprobes or uprobes).

Perf is used with several subcommands:

1. Make sure you have perf installed on the system and the application in the initial state, without any modifications. You can only run perf as root. You can only do this on your system. 2. Run the following command line:

perf record -a -g -- ./tachyon_find_hotspots

For other perf parameters, you can read this link 3. Run the following command line to view the collected results:

perf report

You should see a screen like the following: From this image you can see that perf will display the symbol for the function that takes the most amount of CPU time in red. In our case it’s the _Z20initialize_2D_bufferPjS_, which translates in the C source code into the same function as with VTune and Valgrind.

Hint: To find out the demangled name, use the c++filt command:

 c++filt _Z20initialize_2D_bufferPjS_

Exercitii

Pentru acest laborator se pot utiliza sistemele din cluster prin intermediul fep.grid.pub.ro:

  1. ssh -Y username@fep.grid.pub.ro (natural puneti utilizatorul vostru in loc de username)
  2. wget https://ocw.cs.pub.ro/courses/_media/asc/lab6/lab6_skl.tar.gz -O lab6_skl.tar.gz - Downloadati arhiva laboratorului
  3. tar -xzvf lab6_skl.tar.gz - dezarhivati arhiva downloadata mai sus
  4. srun --time 00:05:00 --x11 -p haswell --pty /bin/bash - conectati-va pe coada Haswell cu 14 servere
  5. apptainer run docker://gitlab.cs.pub.ro:5050/asc/asc-public/c-labs:1.3.1 /bin/bash - accesati imaginea de docker in cadrul căreia avem permisiunile necesare realizării laboratorului

Task 0 - Folosit valgrind pentru task0.c urmarind TODO-uri pentru teste.

Task 1 - Analizati aplicatia Tachyon.

Task 2 - Folositi tool-ul cachegrind din valgrind pentru a analiza codul care realizeaza inmultirea de matrice folosind diferite reordonari ale buclelor.

Recomandăm sa va delogati mereu de pe serverele din cluster dupa terminarea sesiunii, utilizand comanda exit

Alternativ, daca ati uitat sesiuni deschise, puteti verifica acest lucru de pe fep.grid.pub.ro, utilizand comanda squeue. In cazul in care identificati astfel de sesiuni “agatate”, le puteti sterge (si va rugam sa faceti asta), utilizand comanda scancel ID unde ID-ul il identificati din comanda anterioara squeue. Puteți folosi mai precis squeue -u username (username de pe fep.grid.pub.ro) pentru a vedea doar sesiunile care vă interesează.

Daca nu veti face aceasta delogare, veti putea ajunge in situatia in care sa nu va mai puteti loga pe nodurile din cluster.

Reference

Resources