Visible to Intel only — GUID: iga1401400279959
Ixiasoft
Visible to Intel only — GUID: iga1401400279959
Ixiasoft
37.5.2. Using the Performance Counter
Hardware Constants
API Summary
The Nios® II or Nios® V processor application program interface (API) for the performance counter core consists of functions, macros, and constants.
Name | Summary |
---|---|
PERF_RESET() | Stops and disables all counters, resetting them to 0. |
PERF_START_MEASURING() | Starts the global counter and enables section counters. |
PERF_STOP_MEASURING() | Stops the global counter and disables section counters. |
PERF_BEGIN() | Starts timing a code section. |
PERF_END() | Stops timing a code section. |
perf_print_formatted_report() | Sends a formatted summary of the profiling results to stdout. |
perf_get_total_time() | Returns the aggregate global profiling time in clock cycles. |
perf_get_section_time() | Returns the aggregate time for one section in clock cycles. |
perf_get_num_starts() | Returns the number of counter events. |
alt_get_cpu_freq() | Returns the CPU frequency in Hz. |
For a complete description of each macro and function, see the Performance counter API section.
You can get the performance counter hardware parameters from constants defined in system.h. The constant names are based on the performance counter instance name, specified on the System Contents tab in Platform Designer.
Startup
Before using the performance counter core, invoke PERF_RESET to stop, disable and zero all counters.
Global Counter Usage
Use the global counter to enable and disable the entire performance counter core. For example, you might choose to leave profiling disabled until your software has completed its initialization.
Section Counter Usage
To measure a section in your code, surround it with the macros PERF_BEGIN() and PERF_END(). These macros consist of a single write to the performance counter core.
You can simultaneously measure as many code sections as you like, up to the number specified in Platform Designer. See the Define Counters section for details. You can start and stop counters individually, or as a group.
Typically, you assign one counter to each section of code you intend to profile. However, in some situations you may wish to group several sections of code in a single section counter. As an example, to measure general interrupt overhead, you can measure all interrupt service routines (ISRs) with one counter.
To avoid confusion, assign a mnemonic symbol for each section number.
Viewing Counter Values
Library routines allow you to retrieve and analyze the results. Use perf_print_formatted_report() to list the results to stdout , as shown below.
perf_print_formatted_report( (void *)PERFORMANCE_COUNTER_BASE, // Peripheral's HW base address alt_get_cpu_freq(), // defined in "system.h" 3, // How many sections to print "1st checksum_test", // Display-names of sections "pc_overhead", "ts_overhead"); |
The example below creates a table similar to this result.
--Performance Counter Report-- Total Time: 2.07711 seconds (103855534 clock-cycles) +-----------------+--------+-----------+---------------+-----------+ | Section | % | Time (sec)| Time (clocks) |Occurrences| +-----------------+--------+-----------+---------------+-----------+ |1st checksum_test| 50 | 1.03800 | 51899750 | 1 | +-----------------+--------+-----------+---------------+-----------+ | pc_overhead |1.73e-05| 0.00000 | 18 | 1 | +-----------------+--------+-----------+---------------+-----------+ | ts_overhead |4.24e-05| 0.00000 | 44 | 1 | +-----------------+--------+-----------+---------------+-----------+ For full documentation of perf_print_formatted_report(), see the Performance and Counter API section. |