Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Introduction to the profiler

In this section:

Reasons for using the profiler

Function profiling can help you find the functions in your source code where the most time is spent during execution. You should focus on those functions when optimizing your code. A simple method of optimizing a function is to compile it using speed optimization. Alternatively, you can move the data used by the function into more efficient memory. For detailed information about efficient memory usage, see Efficient coding for embedded applications.

Alternatively, you can use filtered profiling, which means that you can exclude, for example, individual functions from being profiled. To profile only a specific part of your code, you can select a time interval—using the Timeline window—for which C-SPY produces profiling information.

Instruction profiling can help you fine-tune your code on a very detailed level, especially for assembler source code. Instruction profiling can also help you to understand where your compiled C/C++ source code spends most of its time, and perhaps give insight into how to rewrite it for better performance.

Briefly about the profiler

Function profiling information is displayed in the Function Profiler window, that is, timing information for the functions in an application. Profiling must be turned on explicitly using a button on the window’s toolbar, and will stay enabled until it is turned off.

For debug probes that support it, C-SPY can capture full instruction trace in real time, and process the information for the Function Profiler window.

Instruction profiling information is displayed in the Disassembly window, that is, the number of times each instruction has been executed.

Profiling sources

The profiler can use different mechanisms, or sources, to collect profiling information. Depending on the available trace source features, one or more of the sources can be used for profiling:

  • Trace (calls)

    The full instruction trace (ETM trace) is analyzed to determine all function calls and returns. When the collected instruction sequence is incomplete or discontinuous, as sometimes happens when using ETM trace, the profiling information is less accurate.

    Select this profiling source (or Trace (flat)) to activate ETM trace for code coverage.

  • Trace (flat)/Sampling

    Each instruction in the full instruction trace (ETM trace) or each PC Sample (from SWO trace) is assigned to a corresponding function or code fragment, without regard to function calls or returns. This is most useful when the application does not exhibit normal call/return sequences, such as when you are using an RTOS, or when you are profiling code which does not have full debug information.

    Select this profiling source (or Trace (calls)) to activate ETM trace for code coverage.

Power sampling

Some debug probes support sampling of the power consumption of the development board, or components on the board. Each sample is associated with a PC sample and represents the power consumption (actually, the electrical current) for a small time interval preceding the time of the sample. When the profiler is set to use power sampling, additional columns are displayed in the Profiler window. Each power sample is associated with a function or code fragment, just as with regular PC sampling.

Note

This does not imply that all the energy corresponding to a sample can be attributed to that function or code fragment. The time scales of power samples and instruction execution are vastly different—during one power measurement, the CPU has typically executed many thousands of instructions. Power sampling is a statistics tool.

Requirements for using the profiler

The C-SPY simulator supports the profiler for most cores and devices. If supported, there are no further specific requirements.

To use the profiler in your hardware debugger system, you need one of these alternatives:

  • An I-jet or I-jet Trace in-circuit debugging probe, a J-Link, a J-Trace, ST-LINK debug probe with an SWD/SWO interface between the probe and the target system, which must be based on a Cortex-M device

  • A I-jet Trace in-circuit debugging probe and an Arm device with ETM trace

  • A J-Trace debug probe and an Arm7/9 or Cortex-M device with ETM trace.

This table lists the C-SPY driver profiling support:

Target system

Trace (calls)

Trace (flat)

Sampling

Power

C-SPY simulator

Yes4

Yes4

CMSIS-DAP

Yes

Yes

I-jet

Yes

Yes

Yes1

Yes

I-jet Trace

Yes

Yes

Yes1

Yes

J-Link

Yes

Yes

Yes1

J-Link Ultra

Yes

Yes

Yes1

Yes2

J-Trace

Yes

Yes

Yes1

GDB Server

ST-LINK

Yes1

Yes1

TI Stellaris

TI XDS

Yes1

Yes3

TI MSP-FET

Yes

Table 24. C-SPY driver profiling support  


1 Only for Cortex-M devices supporting SWO.

2 Requires SWO trace.

3 Only for XDS110 with EnergyTrace(TM) options.

4 Not for all cores and devices.