User manual

STice features UM0036
280/385 Doc ID 7705 Rev 11
Optimizing variables
Unused variables: The results of a coverage and profiling session can help you examine
how you use variables in your code. First, it shows which variables are simply not used at all,
and therefore can be removed. Unused variables are shown in gray on the Data View tab in
the Coverage and Profiling Analysis window.
Inadequate variable type: It also shows where you can more effectively replace a variable
by another structure. For example, you might be able to simplify a structure type variable
(such as the date), by deleting unused fields (day, or month, or year).
In particular, global variables that are only read and never written to can be more efficiently
replaced by a constant or a define. The compiler can thus optimize the code and save a
RAM variable and one or two bytes of Flash memory.
Location in memory: At last, when a variable is indeed useful, data occurrence counting
can help you optimize its placement in memory. In some cases, a variable that appears only
once in the code can actually be accessed very often (if it is in a loop for example). By
moving this variable to page zero, you will optimize execution speed and save memory.
Processing interrupts more efficiently
Coverage and profiling analysis can help you identify:
Handled interrupts never called
Interrupts that occur very often, where optimization of processing time can have a big
impact
The gain obtained from your code optimizations
Detecting and investigating bottlenecks
Detecting bottlenecks in the execution of your code is a prime example of how profiling
information helps you make very big gains in efficiency in a small number of key areas of
your code. This is a very different approach from the compiler optimizations where the
efficiency gain is small throughout the code. These approaches are, therefore,
complementary.
This section uses an illustrated example to guide you through the main steps of the process
of detecting and investigating bottlenecks
1. Configure the Code coverage and profiling option.
Bottleneck detection is based on time profiling information. Therefore, when you start
your profiling session, make sure you have selected the Code coverage and Profiling
option in the Coverage and Profiling settings window (see Section 9.2.1: Configuring
the coverage and profiling settings on page 267).
2. Start a profiling session, and run the application from beginning to end.
For information on running a profiling session, refer to Section 9.2.2 on page 271.
When the application has executed to the end, you can stop the profiling session. The
Coverage and Profiling Analysis window is displayed.
3. Identify the most time consuming code block.
On the Functions/Instructions View tab, you can identify the code block that is the
most time consuming in the Percentage of Focus column. Expand the block and look at
the most time-consuming function or instruction. In Figure 214, the most time-
consuming function is ComputeOutputValue with 90.83% of the total processing
time.