KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches

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.
 

Detailed Description

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:

  1. Compile your program with profiling flags:

    Use the following flags:

    CFLAGS = -pg -fno-omit-frame-pointer -fno-inline

    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.

  2. 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.

  3. Running gprof:

    Use the following command to analyze the profiling data:

    $(KOS_GPROF) $(TARGET) gmon.out > gprof_output.txt

    Replace $(TARGET) with the name of your compiled program. This command will generate a human-readable report in gprof_output.txt.

  4. Visualizing profiling data with gprof2dot:

    To create a graphical representation of the profiling data, use the gprof2dot tool:

    gprof2dot gprof_output.txt > graph.dot

    This converts the gprof output into a DOT format file, which can be used to generate various types of graphs.

  5. Generating an image from the DOT file:

    Use the dot command from Graphviz to create a SVG image from the DOT file:

    dot -Tsvg graph.dot -o graph.svg

    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.

Author
Andy Barajas

Macro Definition Documentation

◆ GPROF_TRAPA_CODE

#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

Function Documentation

◆ moncontrol()

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.

Parameters
enableA boolean value to restart (true) or stop (false) gprof profiling.

◆ monstartup()

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.

Parameters
lowpcThe lower bound of the address range to profile.
highpcThe upper bound of the address range to profile.