代码分析和追溯
通过使用报告、可追溯性和 Polyspace® 静态代码分析产品来手动验证生成的代码和分析关键路径
生成代码后,请通过分析代码度量、接口、替换和代码生成假设,确保代码满足您的要求。代码生成报告会提供有关生成代码的这些方面的信息。您可以评估代码并修改模型,以生成满足您要求的代码。
要验证生成的代码,请使用代码追溯在代码行及其对应的模型元素之间导航。您可以从代码中的超链接追溯到模型元素,也可以从模型元素追溯到代码行。您还可以包含从生成的代码到模型元素要求的链接。
您还可以通过使用关键路径分析来分析生成的代码,以确定产生最长执行时间的执行路径。产生最长执行时间的路径称为关键路径。使用代码探查分析器来识别已标识路径中开销最大的部分,并对开销较大的部分执行优化以满足性能要求。
App
代码探查分析器 | Analyze execution-time and stack usage profiles for generated code (自 R2023a 起) |
函数
rtwtrace | Trace a block to generated code in code generation report |
coder.profile.test.analyzePath | Identify critical paths of tasks (自 R2024a 起) |
coder.profile.test.generateTests | Generate decision coverage tests for execution-time analysis (自 R2024a 起) |
coder.profile.test.generateCriticalPathTest | Generate tests for critical paths (自 R2024a 起) |
coder.profile.test.getCriticalPathElements | Get cell array of model elements in critical path (自 R2024a 起) |
coder.profile.test.hiliteCriticalPath | Highlight critical path in model canvas (自 R2024a 起) |
主题
代码分析
- Check Code Generation Assumptions
Use standalone workflow to check code generator assumptions. - Analyze Code Replacements in Generated Code
The Code Replacements Report section in the code generation report documents the code replacement library (CRL) functions that were used for code replacements during code generation. - Generate Static Code Metrics Report for Simulink Model
When generating code, generate a report that includes static code metrics, such as, the number of lines of code, size of global variables, and the number of reads and writes. - Static Code Metrics
The code generator performs static analysis of the generated C or C++ code and provides these metrics in the static code metrics report in the code generation report. - Analyze Generated Data Code Interface Report
Use the code interface report to see documentation of the generated code data interfaces, including model entry-point functions and data interfaces. - Analyze Generated Service Code Interface Report
Use the code interface report to see documentation of the generated code service interface, including execution functions and services. - Log Program Execution Results
Log data to a MAT-file during execution of generated code.
代码追溯
- Verify Generated Code by Using Code Tracing
Code tracing enables navigation between generated code and its corresponding elements in a model. - Trace Simulink Model Elements in Generated Code
Trace Simulink® model elements by using code-to-model and model-to-code traceability in the code generation report. - Trace Stateflow Elements in Generated Code
Trace different Stateflow® elements to corresponding lines in generated code. - Reload Existing Traceability Information
Example of how to reload existing traceability information for a model. - Customize Traceability Reports
Obtain complete mapping between model elements and generated code. - Use Traceability in MATLAB Function Blocks
Trace between source code and generated code in a MATLAB Function block.
关键路径分析
- Analyze Execution Times of Critical Paths
Identify and analyze critical paths in the generated code.