Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

4.4.3.5.1. Profiler Example with the Nios® II Command Line

Creating the Profiler Software Example

To create the profiler_gnu software project in the Nios® II command-line flow, follow these steps:

  1. Open a Nios® II command shell by executing one of the following steps, depending on your environment:
    • In the Windows operating system, on the Start menu, point to Programs > Intel FPGA > Nios® II EDS <version>, and click Nios® II <version> Command Shell.
    • In the Linux operating system, in a command shell, change directories to < Nios® II EDS install path>, and type the command ./sdk_shell.
  2. Change to the directory <profiler_software_examples> /app/profiler_gnu
  3. Create and build the application with the create-this-app script, by typing the following command:
    ./create-this-app

    The create-this-app script runs the create-this-bsp script, which reads settings from the parameter_definition.tcl in <profiler_software_examples> /bsp/hal_profiler_gnu. This Tcl file contains the following lines:

    set_setting hal.enable_gprof true
    set_setting hal.enable_exit true

    The first setting enables the GNU profiler, and the second setting enables the alt_main() function to call exit() following main().

Running the Profiler Software Example

To run the application and collect the GNU profiler data, follow these steps:

  1. Open a second Nios® II command shell.
  2. In the second shell, open a nios2-terminal session by typing the following command:
    nios2-terminal
  3. In your original Nios® II command shell, download the .elf to the development board, run your design, and write the GNU profiler data to the gmon.out, by typing the following command:
    nios2-download -g --write-gmon gmon.out *.elf

    The GNU profiler collects data while the application runs, and then writes the data to the gmon.out when the application calls the exit() function. The figure below shows an example of the GNU profiler output in the Nios® II command shell.

  4. Exit nios2-terminal by typing control-C.
    Figure 42. GNU Profiler Output on Nios® II Command Shell

Creating the GNU Profiler Report

When you run your project, your project creates the gmon.out. You must format this file to a readable format. To format this file, follow these steps:

  1. In the original Nios® II command shell, change your directory to <profiler_software_examples> /app/profiler_gnu.
  2. Type the following command:
    nios2-elf-gprof profiler_gnu.elf gmon.out > report.txt
  3. Use any text editor to view the report.txt.

    For more information about the GNU profiler report, refer to “Analyzing the GNU Profiler Report”.