Introduction to the profiler
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.
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:
The full instruction trace is analyzed to determine all function calls and returns. When the collected instruction sequence is incomplete or discontinuous, the profiling information is less accurate.
Each instruction in the full instruction trace or each PC Sample 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.
Requirements for using the profiler
The C-SPY simulator supports the profiler; there are no specific requirements.
This table lists the C-SPY driver profiling support:
C-SPY driver | Trace (calls) | Trace (flat) |
|---|---|---|
C-SPY simulator | Yes | Yes |
C-SPY hardware debugger driver | — | — |