Decorators to attach to C++
or Python
code to profile runtime characteristics.
The C++ profiler contains an Instrumentor
class which is responsible for writing timing data to .json
. This is then leveraged by the CPUProfiler
class to write runtime data. The CPUProfiler decorates a function that you wish to profile.
- Include the class declaration in the required source file (preferably using a header file).
#include "[$PATH]/profiler.cpp"
- Attached the macro (that calls the CPUProfiler decorator) to the desired code block.
void function() {
PROFILE_FUNCTION();
// some function...
};
-
Compile and build your source code.
-
Use chrome:https://tracing to upload and analyse the (nearly created)
profile.json
file.
-
Simply attach the decorators
@CPUProfiler.profile
and@MemoryProfiler.profile
to any code and you'll generate the necessary data. -
I recommend using
snakeviz
to view the newly generated.prof
file.snakeviz [$PATH]/pstats.prof
A detailed example is provided on my Medium
: Zach Wolpe
: 10 July 2023