Birds Eye View/Performance/Profiling: Difference between revisions
mNo edit summary |
|||
Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
{{Birds Eye View/Head|next=Contact_us|previous=Performance/PC|keywords=}} | {{Birds Eye View/Head|next=Contact_us|previous=Performance/PC|keywords=|title=Birds Eye View Performance Profiling}} | ||
</noinclude> | </noinclude> | ||
= 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 a 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 | ||
Line 28: | Line 28: | ||
= BEV examples profiling = | == BEV examples profiling == | ||
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: | ||
Line 37: | Line 37: | ||
</source> | </source> | ||
== A) Profile the whole process runtime == | === A) Profile the whole process runtime === | ||
'''1.''' To start profiling run: | '''1.''' To start profiling run: | ||
Line 71: | Line 71: | ||
[[File:Bev pprof.png|700px|frameless|center]] | [[File:Bev pprof.png|700px|frameless|center]] | ||
== B) Profile part of process runtime == | === 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. | 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. | ||
Line 107: | Line 107: | ||
</source> | </source> | ||
== 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: |
Revision as of 09:01, 3 March 2020
⇦ Performance/PC | Home | Contact_us ⇨ |
Getting Started |
---|
User Guide |
Calibration Guide |
GStreamer |
Performance Measurements |
Contact Us |
Application Profiling
The library supports a 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