主要内容

Generating a Static Code Metrics Report for Code Generated fromMATLABCode

The static code metrics report contains the results of static analysis of the generated C/C++ code, including generated file information, number of lines, and memory usage. For more information, seeStatic Code Metrics. To produce a static code metrics report, you must use Embedded Coder®生成独立的C/C ++代码并生成代码生成报告。看Code Generation Reports.

默认情况下,静态代码指标分析不会在代码生成时间运行。相反,如果和何时要运行分析并查看结果,请单击Code Metricson the概括代码生成报告的选项卡。

Example Static Code Metrics Report

This example runs static code metrics analysis and examines a static code metrics report.

Create the example functionaveraging_filter.

功能y = aweraging_filter(x)%#codegen% Use a persistent variable 'buffer' that represents a sliding window of% 16 samples at a time.persistentbuffer;ifisempty(buffer) buffer = zeros(16,1);endy = zeros(size(x), class(x));fori = 1:numel(x)% Scroll the bufferbuffer(2:end) = buffer(1:end-1);% Add a new sample value to the bufferbuffer(1) = x(i);%计算窗口的当前平均值,% write resulty(i)= sum(buffer)/numel(buffer);end

Create sample data.

v = 0:0.00614:2*pi; x = sin(v) + 0.3*rand(1,numel(v));

通过使用独立代码生成的配置对象(静态库,动态链接的库或可执行程序)来启用代码生成报告。

cfg = coder.config('lib','ecoder', true); cfg.GenerateReport=true;

Alternatively, use thecodegen-report选项。

Generate code by usingcodegen. Specify the type of the input argument by providing an example input with the-args选项。通过使用-config选项。

codegenaveraging_filter-configcfg-args{x}

To open the code generation report, clickView report.

To run the static code metrics analysis and view the code metrics report, on the概括tab of the code generation report, clickCode Metrics.

Explore the code metrics report.

  1. To see the generated files and the number of lines of code per file, click文件信息.

    文件信息section of the Static Code Metrics report.

  2. 要查看生成代码中的全局变量,请转到Global Variablessection.

    Global Variables section of the Static Code Metrics report.

    To navigate from the report to the source code, click a global variable name.

  3. 要查看生成代码的函数调用树,功能信息部分中,点击致电树.

    静态代码指标报告的功能信息部分。

    To navigate from the report to the function code, click a function name.

  4. To view the functions in a table format, clickTable.

    静态代码指标报告的功能信息部分。

    The second column,Called By, lists functions that call the function listed in the first column. If multiple functions call that function, all functions are listed. If no functions call that function, this column is empty.

Requirements for Running Static Code Metrics Analysis After Code Generation

默认情况下,静态代码指标分析不会在代码生成时间运行。Instead, you can run the analysis later by clickingCode Metricsin the code generation report. Running static code metrics analysis after code generation has these requirements and limitations:

  • 您必须具有嵌入式编码器并使用用于代码生成的平台。运行静态代码指标分析后,您可以在没有嵌入式编码器的情况下打开代码指标报告,或在其他平台上打开它。

  • 如果您在进行分析之前将代码生成报告仅阅读,则每次单击Code Metrics,分析runs.

Running Static Code Metrics at Code Generation Time

If you want the code generator to run static code metrics analysis and produce the code metrics report at code generation time:

  • 在嵌入式编码器代码生成配置对象中,设置GeneratecodeMetricsReportto真的.

  • 在里面MATLAB®Coder™应用程序,在Debuggingtab, setStatic code metricstoYes.

相关话题