This project demonstrates how to create and use two shared libraries in C++:
libprint
- A library that provides a function to print a string and an API to register callbacks that are triggered on function entry and exit.libprofiler
- A library that registers callbacks to record timestamps and profile the execution time of the function provided bylibprint
.
The project also includes an application that uses these libraries to print a string and profile the function execution time.
- Ensure you have a C++ compiler (e.g.,
g++
) installed on your system. - Open a terminal and navigate to the directory containing the project files.
- Run the following command to build the shared libraries and the application:
make
To build and run the application with the code instrumented to start the profiling:
make run-instrumented
You should see the printed string and the profiling output indicating the function's execution time.
To build and run the application with the code not instrumented:
make run-not-instrumented
To build and run the application with the code not instrumented but externally starting the profiling using LD_PRELOAD=./libprofiler.so
and ENABLE_PROFILING=1
:
make run-ld-preload
printString(const char* str)
: Prints the given string.registerEnterCallback(Callback callback)
: Registers a callback function to be called on function entry.registerExitCallback(Callback callback)
: Registers a callback function to be called on function exit.
registerProfilingCallbacks()
: Registers the enter and exit callbacks to record timestamps and profile the execution time of theprintString
function.
This project is licensed under the MIT License.