Birds Eye View/Performance/Profiling: Difference between revisions

From RidgeRun Developer Wiki
mNo edit summary
No edit summary
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{Birds Eye View/Head|next=Contact_us|previous=Performance/PC|keywords=|title=Birds Eye View Performance Profiling}}
{{Birds Eye View/Head|next=Contact_us|previous=Performance/PC|metakeywords=Application Profiling, GPerfTools, Birds Eye View Examples|title=Birds Eye View Performance Profiling}}
</noinclude>
</noinclude>


<seo
title="Birds Eye View - Performance Profiling" titlemode="replace"
metakeywords="bev, birds-eye-view, birds eye view, cuda, stiching, stitcher, image processing, computer vision, jetson, nvidia" description="Our Birds Eye View project library supports application profiling as a developer-oriented feature using gperftools. Learn more.">
</seo>


== Application Profiling ==
== Application Profiling ==


The library supports a application profiling as a developer oriented feature using [https://github.com/gperftools/gperftools/wiki gperftools].
The library supports application profiling as a developer-oriented feature using [https://github.com/gperftools/gperftools/wiki gperftools].


== GPerfTools Installation ==
== GPerfTools Installation ==


Install the library packages from github repository
Install the library packages from GitHub repository


<source lang="bash">
<syntaxhighlight lang="bash">
git clone https://github.com/gperftools/gperftools
git clone https://github.com/gperftools/gperftools
cd gperftools
cd gperftools
Line 19: Line 23:
make
make
sudo make install
sudo make install
</source>
</syntaxhighlight>


On debian-based systems the complementary tools are packaged under the google-perftools package. For graphical output you also need graphviz installed:
On Debian-based systems, the complementary tools are packaged under the google-perftools package. For graphical output you also need Graphviz installed:
<source lang="bash">
<syntaxhighlight lang="bash">
sudo apt-get install google-perftools graphviz
sudo apt-get install google-perftools graphviz
</source>
</syntaxhighlight>
Note that all the tools have the “google-” prefix under debian - the prefix may be missing on other systems (and is also missing in the official documentation).
Note that all the tools have the “google-” prefix under debian - the prefix may be missing on other systems (and is also missing in the official documentation).


Line 32: Line 36:
To enable profiling execute meson and compile the library with the following option:
To enable profiling execute meson and compile the library with the following option:


<source lang="bash">
<syntaxhighlight lang="bash">
meson -Dprofiling=enabled ..
meson -Dprofiling=enabled ..
ninja
ninja
</source>
</syntaxhighlight>


=== A) Profile the whole process runtime ===
=== A) Profile the whole process runtime ===
Line 45: Line 49:
'''CPUPROFILE:''' Name of the output log file
'''CPUPROFILE:''' Name of the output log file


<source lang="bash">
<syntaxhighlight lang="bash">
LD_PRELOAD=/usr/local/lib/libprofiler.so CPUPROFILE=test.prof ./path/to/bin
LD_PRELOAD=/usr/local/lib/libprofiler.so CPUPROFILE=test.prof ./path/to/bin
</source>
</syntaxhighlight>


'''2.''' Keep the application open or running until it finishes, in this mode if the execution is canceled
'''2.''' Keep the application open or running until it finishes, in this mode if the execution is canceled
Line 53: Line 57:


'''3.1''' Once the application ended the ''test.prof'' file contains the CPU profile information. To get a graphical output run:
'''3.1''' Once the application ended the ''test.prof'' file contains the CPU profile information. To get a graphical output run:
<source lang="bash">
<syntaxhighlight lang="bash">
pprof -gv ./path/to/bin test.prof
pprof -gv ./path/to/bin test.prof
</source>
</syntaxhighlight>


'''3.2''' Also as an alternative viewer you can display it to a web browser by running:
'''3.2''' Also as an alternative viewer you can display it to a web browser by running:
<source lang="bash">
<syntaxhighlight lang="bash">
pprof --web ./path/to/bin test.prof
pprof --web ./path/to/bin test.prof
</source>
</syntaxhighlight>


'''4.''' To generate a PDF report with the previous graphic output run:
'''4.''' To generate a PDF report with the previous graphic output run:
<source lang="bash">
<syntaxhighlight lang="bash">
pprof --pdf ./path/to/bin test.prof > output.pdf
pprof --pdf ./path/to/bin test.prof > output.pdf
</source>
</syntaxhighlight>


Example graphical output:
Example graphical output:
Line 76: Line 80:


'''1.''' To start profiling run:
'''1.''' To start profiling run:
<source lang="bash">
<syntaxhighlight lang="bash">
LD_PRELOAD=/usr/local/lib/libprofiler.so CPUPROFILE=test.prof CPUPROFILESIGNAL=12 ./path/to/bin
LD_PRELOAD=/usr/local/lib/libprofiler.so CPUPROFILE=test.prof CPUPROFILESIGNAL=12 ./path/to/bin
</source>
</syntaxhighlight>


'''2.''' Leave the program running until you want to start the profiling process. Then send the signal:
'''2.''' Leave the program running until you want to start the profiling process. Then send the signal:
Line 87: Line 91:
'''2.1''' Also you can use '''killall''' command to send the ''-12'' signal
'''2.1''' Also you can use '''killall''' command to send the ''-12'' signal


<source lang="bash">
<syntaxhighlight lang="bash">
killall -12 /path/to/bin
killall -12 /path/to/bin
</source>
</syntaxhighlight>


'''3.''' Leave the program until the point you want to profile it, then run again:
'''3.''' Leave the program until the point you want to profile it, then run again:
<source lang="bash">
<syntaxhighlight lang="bash">
killall -12 /path/to/bin
killall -12 /path/to/bin
</source>
</syntaxhighlight>


You will notice the following output when the output file was correctly generated:
You will notice the following output when the output file was correctly generated:
<source lang="bash">
<syntaxhighlight lang="bash">
Using signal 12 as cpu profiling switch
Using signal 12 as cpu profiling switch
PROFILE: interrupts/evictions/bytes = 4773/1826/231936
PROFILE: interrupts/evictions/bytes = 4773/1826/231936
</source>
</syntaxhighlight>


'''4.''' Once the application ended the ''test.prof.0'' file contains the CPU profile information. To get a graphical output run:
'''4.''' Once the application ended the ''test.prof.0'' file contains the CPU profile information. To get a graphical output run:
<source lang="bash">
<syntaxhighlight lang="bash">
pprof -gv ./path/to/bin test.prof
pprof -gv ./path/to/bin test.prof
</source>
</syntaxhighlight>


=== C) Profile specific section of source code ===
=== C) Profile specific section of source code ===


'''1.''' Add the header file in your code:
'''1.''' Add the header file in your code:
<source lang="C">
<syntaxhighlight lang="bash">
#include <gperftools/profiler.h>
#include <gperftools/profiler.h>
</source>
</syntaxhighlight>


'''2.''' Add the following functions calls around the code you want to profile:
'''2.''' Add the following functions calls around the code you want to profile:
<source lang="C">
<syntaxhighlight lang="C">


ProfilerStart("output_inside.prof"); //Start profiling section and save to file
ProfilerStart("output_inside.prof"); //Start profiling section and save to file
Line 124: Line 128:


ProfilerStop(); //End profiling section
ProfilerStop(); //End profiling section
</source>
</syntaxhighlight>


'''3.''' Run the test application, where you will an output similar to the following:
'''3.''' Run the test application, where you will an output similar to the following:


<source lang="bash">
<syntaxhighlight lang="bash">
fsolano@ridgerun-laptop:build$ ./test
fsolano@ridgerun-laptop:build$ ./test
PROFILE: interrupts/evictions/bytes = 9/0/280
PROFILE: interrupts/evictions/bytes = 9/0/280
Line 137: Line 141:
PROFILE: interrupts/evictions/bytes = 7/0/464
PROFILE: interrupts/evictions/bytes = 7/0/464
PROFILE: interrupts/evictions/bytes = 8/0/680
PROFILE: interrupts/evictions/bytes = 8/0/680
</source>
</syntaxhighlight>


'''4.''' With this method you can wait until the application execution ends, or end it with Ctrl+C.
'''4.''' With this method you can wait until the application execution ends, or end it with Ctrl+C.


'''5.''' Once the application ended the ''output_inside.prof'' file contains the CPU profile information. To get a graphical output run:
'''5.''' Once the application ended the ''output_inside.prof'' file contains the CPU profile information. To get a graphical output run:
<source lang="bash">
<syntaxhighlight lang="bash">
pprof -gv ./test output_inside.prof
pprof -gv ./test output_inside.prof
</source>
</syntaxhighlight>
 
 


<noinclude>
<noinclude>
{{Birds Eye View/Foot|Performance/PC |Contact_us}}
{{Birds Eye View/Foot|Performance/PC |Contact_us}}
</noinclude>
</noinclude>

Latest revision as of 17:06, 28 August 2024





⇦ Performance/PC Home Contact_us ⇨





Application Profiling

The library supports application profiling as a developer-oriented feature using gperftools.

GPerfTools Installation

Install the library packages from GitHub repository

git clone https://github.com/gperftools/gperftools
cd gperftools
./autogen.sh
./configure
make
sudo make install

On Debian-based systems, the complementary tools are packaged under the google-perftools package. For graphical output you also need Graphviz installed:

sudo apt-get install google-perftools graphviz

Note that all the tools have the “google-” prefix under debian - the prefix may be missing on other systems (and is also missing in the official documentation).


BEV examples profiling

To enable profiling execute meson and compile the library with the following option:

meson -Dprofiling=enabled ..
ninja

A) Profile the whole process runtime

1. To start profiling run:

LD_PRELOAD: Path to the libprofiler.so usually located at /usr/local/lib/

CPUPROFILE: Name of the output log file

LD_PRELOAD=/usr/local/lib/libprofiler.so CPUPROFILE=test.prof ./path/to/bin

2. Keep the application open or running until it finishes, in this mode if the execution is canceled for example with Ctrl+C the output file will not be generated.

3.1 Once the application ended the test.prof file contains the CPU profile information. To get a graphical output run:

pprof -gv ./path/to/bin test.prof

3.2 Also as an alternative viewer you can display it to a web browser by running:

pprof --web ./path/to/bin test.prof

4. To generate a PDF report with the previous graphic output run:

pprof --pdf ./path/to/bin test.prof > output.pdf

Example graphical output:

B) Profile part of process runtime

In addition to defining the environment variable CPUPROFILE you can also define CPUPROFILESIGNAL. This allows profiling to be controlled via the signal number that you specify. The signal number must be unused by the program under normal operation. Internally it acts as a switch, triggered by the signal, which is off by default.

1. To start profiling run:

LD_PRELOAD=/usr/local/lib/libprofiler.so CPUPROFILE=test.prof CPUPROFILESIGNAL=12 ./path/to/bin

2. Leave the program running until you want to start the profiling process. Then send the signal:

2.1 You can use htop program to send the signal to the desired process:

2.1 Also you can use killall command to send the -12 signal

killall -12 /path/to/bin

3. Leave the program until the point you want to profile it, then run again:

killall -12 /path/to/bin

You will notice the following output when the output file was correctly generated:

Using signal 12 as cpu profiling switch
PROFILE: interrupts/evictions/bytes = 4773/1826/231936

4. Once the application ended the test.prof.0 file contains the CPU profile information. To get a graphical output run:

pprof -gv ./path/to/bin test.prof

C) Profile specific section of source code

1. Add the header file in your code:

#include <gperftools/profiler.h>

2. Add the following functions calls around the code you want to profile:


ProfilerStart("output_inside.prof"); //Start profiling section and save to file

/* 
* Code to be analyzed
*/

ProfilerStop(); //End profiling section

3. Run the test application, where you will an output similar to the following:

fsolano@ridgerun-laptop:build$ ./test
PROFILE: interrupts/evictions/bytes = 9/0/280
PROFILE: interrupts/evictions/bytes = 7/0/584
PROFILE: interrupts/evictions/bytes = 12/0/872
PROFILE: interrupts/evictions/bytes = 9/0/712
PROFILE: interrupts/evictions/bytes = 9/0/904
PROFILE: interrupts/evictions/bytes = 7/0/464
PROFILE: interrupts/evictions/bytes = 8/0/680

4. With this method you can wait until the application execution ends, or end it with Ctrl+C.

5. Once the application ended the output_inside.prof file contains the CPU profile information. To get a graphical output run:

pprof -gv ./test output_inside.prof



⇦ Performance/PC Home Contact_us ⇨