Visible to Intel only — GUID: iga1464370967659
Ixiasoft
Visible to Intel only — GUID: iga1464370967659
Ixiasoft
4.4.3.3.1. Profiler Mechanics
You enable the GNU profiler by turning on the hal.enable_gprof switch in the scripts to generate the BSP. Turning on this switch automatically turns on the -pg compiler switch and then links the profiling library code in the altera_nios2 software component with the BSP. This code counts the number of calls to each profiled function.
The -pg compiler option forces the compiler to insert a call to the mcount() function (located in the file altera_nios2/HAL/src/alt_mcount.S) at the beginning of every function call. The calls to mcount() track every dynamic parent and child function call relationship to enable the construction of a call graph. The option also installs nios2_pcsample()function (located in the file altera_nios2/HAL/src/ alt_gmon.c) that samples the foreground program counter at every system clock interrupt. When the program executes, the GNU profiler collects data on the host of the gmon.out. The nios2-elf-gprof utility can read this file and display profiling information about the program.
The profiling code operates on the target by performing the following steps:
- The Compiler implements function prologues with a call to mcount() to enable the Compiler to determine the function call graph. The GNU profiler documentation refers to this data as the function call arc data.
- The timer interrupt handler registers an alarm to capture information about the foreground function (histogram data) that executes when the alarm triggers.
- The heap allocates a target memory to store the profiling data.
- When your code exits with a BREAK 2 instruction, the nios2-download utility copies the profiling data from the target to the host.
The nios2-elf-gprof utility requires the function call arc data and the histogram data to work correctly.