KallistiOS git master
Independent SDK for the Sega Dreamcast
|
Lightweight GPROF profiling runtime for KOS More...
Macros | |
#define | GPROF_TRAPA_CODE 33 |
GPROF Trapa Code. | |
Functions | |
void | monstartup (uintptr_t lowpc, uintptr_t highpc) |
Start gprof profiling for a specified address range. | |
void | moncontrol (bool enable) |
Restart or stop gprof profiling. | |
Lightweight GPROF profiling runtime for KOS
This file provides utilities for profiling applications using gprof. Gprof is a profiling tool that allows you to analyze where your program spent its time and which functions called which other functions during execution. This can help you identify performance bottlenecks and optimize your code.
Profiling Steps:
Compile your program with profiling flags:
Use the following flags:
These flags enable profiling and prevent function inlining to ensure accurate profiling data. When you use the -pg flag, the GCC compiler inserts trapa #33 instructions at the beginning of each function into your build.
Running your program to create gmon.out:
Execute your program normally to completion using dcload-ip or dcload-serial. This will generate a file named gmon.out
in the current directory, which contains the profiling data.
Running gprof:
Use the following command to analyze the profiling data:
Replace $(TARGET)
with the name of your compiled program. This command will generate a human-readable report in gprof_output.txt
.
Visualizing profiling data with gprof2dot:
To create a graphical representation of the profiling data, use the gprof2dot
tool:
This converts the gprof
output into a DOT format file, which can be used to generate various types of graphs.
Generating an image from the DOT file:
Use the dot
command from Graphviz to create a SVG image from the DOT file:
This command will generate a SVG image (graph.svg
) that visually represents the profiling data.
By following these steps, you can effectively profile your program and identify performance bottlenecks for optimization.
#define GPROF_TRAPA_CODE 33 |
GPROF Trapa Code.
GCC generates this pattern before each profiled function when you compile your project with the -pg flag:
trapa #33 — This is a 2-byte instruction nop — This is a 2-byte no-op placeholder label — This is a 4-byte LABELNO
void moncontrol | ( | bool | enable | ) |
Restart or stop gprof profiling.
This function restarts or stops gprof profiling. It does NOT start gprof profiling initially, as gprof profiling starts before the program enters the main function. You can use this function to stop profiling and then restart it later when you reach the section of code you want to profile.
enable | A boolean value to restart (true) or stop (false) gprof profiling. |
void monstartup | ( | uintptr_t | lowpc, |
uintptr_t | highpc ) |
Start gprof profiling for a specified address range.
This function is intended for programs not linked with the ‘-pg’ linker switch. If ‘-pg’ was used during linking, monstartup is automatically called by the startup code with arguments covering the entire range of executable addresses, from the program's entry point to the highest code segment address. Using this method to initialize gprof will only generate histogram profiling data, without producing a call graph. Profiling starts immediately after calling this function.
lowpc | The lower bound of the address range to profile. |
highpc | The upper bound of the address range to profile. |