Target Language Compiler | ![]() ![]() |
TLC Profiler
This section discusses how to use the TLC profiler to analyze your TLC code to improve code generation performance.
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.
Using the Profiler
To access the profiler, select Profile TLC from the TLC debugging
category of the Real-Time Workshop pane of the Simulation Parameters dialog box. Apply your changes and click the Build button.
At the end of the build process, the HTML summary and related files are placed in the Real-Time Workshop project directory and the report will be opened in your MATLAB selected Web browser.
Analyzing the Report
The created report is fairly self explanatory. Some points to note are
A situation where the profiler report may be helpful is when you have inlined S-functions in your model. You can use the profiler to compare time spent in specific user-written or Lib
functions, and then modify your TLC code accordingly.
This is a portion of the profiler report for the simple.log
model in matlabroot
/toolbox/rtw/rtwdemos/tlctutorial/tlcdebug
.
The report shows the time spent in the function FcnEliminateUnnecessaryParams
in gain.tlc
and other functions, both built-in and library, called during various stages of code generation.
Nonexecutable Directives
TLC considers the following directives to be nonexecutable lines. Therefore, these directives are not counted in TLC Profiler reports:
%filescope
%else
%endif
%endforeach
%endfor
%endroll
%endwith
%body
%endbody
%endfunction
%endswitch
%default
any type of comment (%% or /% stuff %/)
Improving Performance
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 that were written by you, or try alternative methods to improve code generation speed. Two points to consider are
EXISTS
. Performing an EXISTS
on 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 EXISTS
on the entity, compare it against the default value.
![]() | TLC Coverage | Inlining S-Functions | ![]() |