Monitor Design Complexity Using Model Maintainability Dashboard
The Model Maintainability Dashboard collects metric data from the model design artifacts in a project to help you assess the size, architecture, and complexity of your design.
The dashboard analyzes different aspects of model maintainability from model design artifacts like Simulink® models, Stateflow® charts, and MATLAB® code. The model maintainability metrics help you determine if parts of a design are too complex and need to be refactored. A less complex design is easier to read, maintain, and test.
This example shows how to collect and explore the maintainability metric data for a project. As you update and development your design artifacts, use the dashboard to assess the impact on complexity and maintainability.
Open Model Maintainability Dashboard for Project
1. Open a project that contains design artifacts. For this example, in the MATLAB Command Window, enter:
openProject("cc_CruiseControl");
The project includes several models, tests, and requirements files. For more information, see Create Project to Use Model Design and Model Testing Dashboards.
2. The Model Maintainability Dashboard is a model design dashboard that displays maintainability metrics. To open the Model Maintainability Dashboard, use one of these approaches:
On the Project tab, in the Tools section, click Model Design Dashboard.
Open a model in the project and, in the Apps gallery, click Model Design Dashboard.
In the Command Window, enter:
modelDesignDashboard
The dashboard app launches and opens a new Model Maintainability tab for the software unit cc_ControlMode
. The Model Maintainability Dashboard shows metric results for the size, architecture, and complexity of the unit.
Explore Artifacts
On the left side of the dashboard app is the Project panel which displays artifacts in the project that are compatible with the currently selected dashboard. You can use the Project panel to open the dashboard for the different artifacts in your project. The Model Maintainability Dashboard can collect metric results for Units and Components in your project. To control what the dashboard classifies as a unit or component, see Categorize Models in Hierarchy as Components or Units.
When you select an artifact in the Project panel, the Artifacts panel on the shows the related artifacts that trace to that artifact. For example, when you select cc_ControlMode in the Project panel, the Artifacts panel displays the artifacts that trace to the unit cc_ControlMode
. The Functional Requirements, Design, Tests, and Test Results folders contain the artifacts the dashboard traced to the current artifact.
3. In the Artifacts panel, expand the Design folder. For the unit cc_ControlMode
, the Design folder shows the associated data dictionary, model, and subsystem references.
In the toolstrip for the dashboard app, you can click the Legend button to view a list of the icons for artifacts that the dashboard traces.
Explore Maintainability Metrics
When you open a Model Maintainability Dashboard, the dashboard automatically collects the metric data and displays the results in the six main sections of the dashboard:
Component Structure
Component Interface
Design Cyclomatic Complexity Breakdown
Halstead Difficulty Breakdown
Simulink Architecture
Stateflow Architecture
MATLAB Architecture
Each section of the dashboard contains widgets that help you interact with the metric data.
4. In the Component Structure section of the dashboard, point to the Complexity widget. Three dots appears in the top-right corner of the widget.
Point to the three dots and click the Help icon to view more information about the metric and how the dashboard calculates the metric value.
5. In the Simulink Architecture section, in the Signal Lines row and Distribution column, the metric results show an outlier in the signal line distribution.
The dashboard sorted most of the metric data into the three distribution bins on the left. The rightmost distribution bin contains metric data that is outside of that range.
6. Point to the rightmost distribution bin. The tooltip indicates that there is one layer in the model hierarchy containing between 60 and 69 Simulink signals.
The other layers of the model contain fewer signal lines. For example, the leftmost distribution bin shows nine model layers containing fewer than 10 Simulink signals.
7. Click the rightmost distribution bin to explore the metric data in more detail.
The dashboard opens the Metric Details for the widget with a table of metric values and hyperlinks to each related artifact. The table shows that the artifact Control_Mode_StateMachine contains 60 signal lines.
Note that there is a breadcrumb trail from the Metric Details back to the main Model Maintainability results for cc_ControlMode.
8. In the Artifact column, click on Control_Mode_StateMachine to open the artifact in Simulink.
In this example, the artifact Control_Mode_StateMachine
is a subsystem in the model cc_ControlMode
. If the 60 signal lines at the top layer of the subsystem make the design hard to read, refactor the model layer to improve readability.
See Also
Model Maintainability Metrics | metric.Engine