Visual Profiler is a lightweight/header-only/singleton-pattern file which generate a json file to profile your CPU code. The backend is using chrome://tracing. Therefore, the json file needs to be complied with the chrome::tracing format
- Download/copy-paste the VisualProfiler.hpp
- Insert PROFILE_FUNCTION() Marco into the functions you want to profile e.g.
void dummyFunction()
{
PROFILE_FUNCTION(); // place marco at the topest of the function
. . .
}
- Insert Instrumentor::get().beginSession("name")
int main()
{
Instrumentor::get().beginSession("Profile"); // insert beginSession
dummyPrintOut();
dummySum();
dummyFactorial();
Instrumentor::get().endSession();
}
- Open Chrome tracing and type Chrome:://tracing in your Chrome
- Drag and drop the ProfileResult.json
- Check the code in main.cpp
- you can git clone this repo and try it out
mkdir build && cd build
cmake ..
make
./VisualProfiler
If you are using it to profile a large program, likely you might use ctrl+c
to terminate it during runtime.
In this case, your will NOT call writeFooter()
correctly, you will need to manually add "]}" to the end of the json file.