Main Content

Generate Static Code Metrics Report for Simulink Model

The Static Code Metrics Report is a section included in the HTML Code Generation Report. For more information on the static analysis of the generated code, see Static Code Metrics Analysis.

  1. To generate the static code metrics report in the HTML Code Generation Report, open the Configuration Parameters dialog box for your model. On the Code Generation > Report pane, select the Generate static code metrics check box. If your model includes referenced models, select the Generate static code metrics check box in each referenced model’s configuration set. Otherwise, you cannot view a separate static code metrics report for a referenced model.

    Alternatively, after you generate code, generate only the static code metrics report by using the function coder.report.generateCodeMetrics.

  2. Press Ctrl+B to build your model and generate the HTML code generation report. For more information, see Generate Code Generation Report.

  3. If the HTML Code Generation Report is not already open, open the report. On the left navigation pane, in the Contents section, select Static Code Metrics Report.

    Contents pane of the code generation report. The Static Code Metrics link is highlighted.

    If you generated only the static code metrics report, open the report. By default, the static code metrics report file metrics.html is generated in the current folder.

  4. To see the generated files and how many lines of code are generated per file, look at the File Information section.

    File Information section of the static code metrics report. A table shows columns for the file name, lines of code, lines, and generation date for each file.

  5. Hover your cursor over column titles and some column values to see a description of the corresponding data.

  6. If your model includes referenced models, the File information section includes a Referenced Model column. In this column, click the referenced model name to open its static code metrics report. If the static code metrics report is not available for a referenced model, specify the Generate static code metrics parameter in the referenced model’s configuration set and rebuild your model.

  7. To view the global variables in the generated code, their size, and the number of accesses, see the Global Variables section.

    Global variables section of the Static Code Metrics report. A table shows columns for the variable name, size, reads/writes, and reads/writes in a function for each global variable.

    The Reads/Writes column displays the total number of read and write accesses to the global variable. The Reads/Writes in a Function column displays the maximum number of read and write accesses to the global variable within a function. You use this information is to estimate the benefit of turning on optimizations, which reduce the number of global references. For more information, see Optimize Global Variable Usage.

    Click [+] to expand structures.

    Global Variable table expanded to show the structures of the global variables.

  8. To navigate from the report to the source code, click a global variable or function name. These names are hyperlinks to their definitions.

  9. To view the function call tree of the generated code, in the Function Information section, click Call Tree at the top of the table.

    Function information section of the Static Code Metrics report. A table shows columns for the function name, accumulated stack size, self stack size, lines of code, lines, and complexity for each function. The function names in the left column are organized by the call tree.

    ert_main.c is not included in the code metrics analysis, therefore it is not shown in the call tree format. The Complexity column includes the cyclomatic complexity of each function.

  10. To view the functions in a table format, click Table.

    Function Information section. The function names in the left column are not organized by the call tree.

    The second column, Called By, lists functions that call the function listed in the first column, using the following criteria:

    • If a function is called by multiple functions, all functions are listed.

    • If a function has no called function, this column is empty.

    For example, Fueling_Mode is called by Fail and fuel_rate_control_step. The number of call sites is included in parentheses. Fail calls Fueling_Mode twice.

Related Topics