The in-code profiler library.
This library is intended to provide profiling thanks to markers set directly in the code sources of the application to which it is linked.
It produces an XML file that can easily be read by the tool distributed with this project.
The official source code is accessible under LGPLv3 here:
https://github.com/MightyCreak/libbench
-
bench/
The core library. -
test/
A simple multi-threaded test that generates a profiling file. -
tool/
The tools that display the content created by the library. At the moment it includes a GTK viewer.
libbench is licensed under the GNU LGPLv3.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.
I wanted the library to be easy to use, so you'll need to link your application with the bench library, initialize it, add markers you want to profile your code, save the profiling into a file, and then shutdown the library. That's all you'll need to do!
The library's name is libbench. To activate the markers, you'll need to
define USE_LIBBENCH
.
The define is an easy way to switch the markers activation. It is important to deactivate the markers when your application is optimized and ready to release. Profiling takes time and you don't want to waste time in the overhead induced by the markers. So simply remove or comment the define once you're done. You can let the markers where they are they will be completely disabled.
To initialize the library, simply call bench::Initialize()
.
The markers are presented in the form of macros:
BENCH_START_PROFILE
Start a profile. Must be ended by aBENCH_STOP_PROFILE
.BENCH_SCOPED_PROFILE
Start a scoped profile. It will be automatically ended at the end of the scope.
Once your profiling is over, you can dump it into a file thanks to the
function: bench::WriteToXml(std::ostream& stream)
.
As for intialization, to shutdown the library, simply call
bench::Shutdown()
.
You'll find a multi-threaded example in the test directory.
Romain "Creak" Failliot