Using the Profiler
The TLC profiler collects timing statistics for TLC code. It collects execution time for functions, scripts, macros, and built-in functions. These results become the basis of HTML reports that are identical in format to MATLAB® profiler reports. By analyzing the report, you can identify bottlenecks in your code that make code generation take longer.
On the Configuration Parameters dialog box, select Profile TLC. Apply your changes and press Ctrl+B.
At the end of the TLC process, the build process creates the HTML summary and related files.
Analyzing the Report
The profile report is generated into the build folder. To open the report, change folder
cd) to the build folder and open the file
, opening it in a browser window. Here
is a sample of a TLC profiling report:
The created report is fairly self-explanatory. Some points to note are
Functions are sorted in descending order of their execution time.
Self-time is the time spent in the function alone, not including the time spent in functions called by the function.
Functions are hyperlinks that take you to the details related to that specific function.
The profiler report can be helpful when you have inlined S-functions in your model. You can
use the profiler to compare time spent in specific user-written or
functions, and then modify your TLC code accordingly.
TLC considers the following directives to be nonexecutable lines. Therefore, these directives are not counted in TLC Profiler reports:
/% text %/
Analyzing the profiler results also gives you an overview of which functions are used more often or are more expensive. Then, you can either improve those functions, or try alternative methods to improve code generation speed. Two points to consider are
Reduce usage of
EXISTS. Performing an
EXISTSon a field is more costly than comparing the field to a value. When possible, create an inert default value for a field. Then, instead of doing an
EXISTSon the entity, compare it against the default value.
Reduce the use of one-line functions. One-line functions might be a bottleneck for code generation speed. When readability is not an issue, consider expanding the function.