How can I find sections of code which have not been used ("dead code") in the MATLAB file or in the code generated from Simulink 7.0 (R2007b)?

13 views (last 30 days)
I want to find sections of the code that have not been used, i.e., "dead code". I want to highlight code in Simulink or generate a report after running the model to inform me which sections of the code were used and which sections of the code were not.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Jun 2009
Several tools are available to allow you to find the sections of code which has not been used in MATLAB MATLAB files and code generated from Simulink:
1. M-lint Code Check and profiler reports can be used on files in MATLAB.
Code Check Report displays potential errors and problems, as well as opportunities for improvement in your MATLAB files. For example, M-lint will detect and show the variables that are never used in the code.
Profiler helps you improve the performance of your MATLAB files. It also shows which lines in the code were not executed. More information on the M-lint and Profiler can be found in the Tuning and Managing MATLAB files section of the MATLAB documentation by executing:
web([docroot '/techdoc/matlab_env/f9-22317.html'])
2. PolySpace software.
PolySpace provides code-based verification that proves the absence of errors in source code for C, C++, and Ada. It also detects dead code. PolySpace ensures code reliability by detecting run-time and other software errors without requiring program execution, code instrumentation, or test cases. You can verify handwritten code, automatically generated code, or a combination of the two, before compilation and test.
More information about this product can be found online at:
<http://www.mathworks.com/products/polyspace/?s_cid=HP_FP_PS_PolySpace>
Note that PolySpace does not require MATLAB or Simulink to run.
3. Model Coverage in the Simulink Verification and Validation software.
Model coverage determines the extent to which a model test case exercises simulation pathways through a model. The percentage of pathways that a test case exercises is called its model coverage. Model coverage is a measure of how thoroughly a test tests a model. Model coverage therefore helps you to validate your model tests. The documentation for started using Model Coverage can be accessed by executing the following in your MATLAB command line:
web([docroot '/toolbox/slvnv/ug/f22210.html'])
4. In Real-time Workshop you can choose to optimize the code generation in the Optimization Pane of the Configuration Parameters dialog box. For an overview of the Optimization Parameters see the documentation by executing the following in your MATLAB command line:
web([docroot '/toolbox/rtw/ug/f28640.html'])
Note that Block Reduction option in the Optimization pane is selected by default. The Block Reduction includes Dead Code Elimination. More information on the Block Reduction can be found by executing:
web([docroot '/toolbox/rtw/ug/f23021.html#bq33uwi'])
5. Code Coverage Tool (CCT) can be used to measure C statement coverage in code built as a Real-Time Workshop S-Function. CCT is available at the MATLAB Central at:
<http://www.mathworks.com/matlabcentral/fileexchange/14284>
CCT can be used programmatically to find gaps in coverage. For example, it can find all source lines that did not execute during a simulation run. Please note that MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.

More Answers (0)

Categories

Find more on Verification, Validation, and Test in Help Center and File Exchange

Products


Release

R2007b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!