Main Content

Modify, Remove, and Add Metric Thresholds in Metrics Dashboard

The Metrics Dashboard uses metric threshold values to determine how metric data appears in the dashboard.

Based on the metric threshold values, the dashboard categorizes metric data as:

Compliant — Metric data that is in an acceptable range. The metric data appears green in the widget. Widgets that only contain compliant metric data show a green check mark icon .

Warning — Metric data that requires review. The metric data appears yellow in the widget. Widgets that contain warnings, but no noncompliant metric data, show a yellow triangle icon .

NonCompliant — Metric data that requires you to modify your model. The metric data appears red in the widget. Widgets that contain noncompliant metric data show a red circle icon .

You can use the categorized metric data to assess the design status and quality of your model. Some widgets in the dashboard already contain default metric threshold values. If you want to use threshold values other than the default thresholds, you can customize the metric thresholds.

This example shows how you can customize the metric thresholds to help you identify issues and noncompliant metric data for your model.

Get Default Metric Thresholds

The Metrics Dashboard has two types of configurations:

  • slmetric.dashboard.Configuration — Dashboard configuration that specifies the layout and types of widgets shown in the Metrics Dashboard.

  • slmetric.config.Configuration — Metric configuration that specifies thresholds and custom metric families.

In this example, you use an slmetric.config.Configuration object to specify thresholds for the Metrics Dashboard.

1. Open the default metric configuration for the Metrics Dashboard.

metricConfig = slmetric.config.Configuration.openDefaultConfiguration();

2. Get the threshold configuration from the metric configuration.

thresholdConfig = getThresholdConfigurations(metricConfig);

3. Use the function getThresholds to return the default thresholds.

defaultThresholds = getThresholds(thresholdConfig);

The default thresholds include a threshold for the metric mathworks.metrics.CloneContent. The Potential Reuse widget displays the metric data provided by mathworks.metrics.CloneContent. In the Architecture section of the Metrics Dashboard, the Potential Reuse results have a default threshold of 0%. The Metrics Dashboard only categorizes the metric data in the Potential Reuse widget as compliant if the value is less than or equal to 0%.

4. Get the threshold associated with the Potential Reuse results.

potentialReuse = findobj(defaultThresholds,"MetricID","mathworks.metrics.CloneContent")
potentialReuse = 
  Threshold with properties:

     MetricID: 'mathworks.metrics.CloneContent'
    AppliesTo: 'Value'

Modify Existing Metric Threshold

The Metrics Dashboard uses classifications to classify metric data as compliant, warning, or noncompliant for the specified threshold.

Use the function getClassifications to get the classifications that the dashboard uses to categorize the Potential Reuse results against the threshold.

C = getClassifications(potentialReuse);

The Classification array C contains:

  • C(1) — The classification for compliant Potential Reuse results

  • C(2) — The classification for warning Potential Reuse results

Change Compliant Values

1. View the current range for compliant Potential Reuse results.

C(1).Range
ans = 
  MetricRange with properties:

           Start: -Inf
             End: 0
    IncludeStart: 0
      IncludeEnd: 1

With the current classification, metric data are compliant if the Potential Reuse value is greater than negative infinity and less than or equal to zero. Which means that if the Potential Reuse value is 0%, the Metrics Dashboard shows the metric data as compliant. The properties IncludeStart and IncludeEnd determine whether the range is inclusive or exclusive of the Start and End values.

2. Modify the range for compliant Potential Reuse results. For this example, allow Potential Reuse values less than 20% to be compliant.

C(1).Range.End = 0.2;

Note that the metric mathworks.metrics.CloneContent expects the value to be a fraction that represents the total number of subcomponents that are clones, so for this example, the End is specified as 0.2. For more information, see Model Metrics.

Change Warning Values

1. View the current range for warning Potential Reuse results.

C(2).Range
ans = 
  MetricRange with properties:

           Start: 0
             End: Inf
    IncludeStart: 0
      IncludeEnd: 0

With the current classification, the Metrics Dashboard shows a warning if the Potential Reuse value is between zero and infinity. Which means that if the Potential Reuse value is greater than 0%, the Metrics Dashboard shows the metric data with a warning.

2. Modify the range for warning Potential Reuse results. For this example, specify that the Metrics Dashboard only show a warning if the Potential Reuse is greater than 20%.

C(2).Range.Start = 0.2;

3. View the modified threshold ranges for Potential Reuse.

C.Range
ans = 
  MetricRange with properties:

           Start: -Inf
             End: 0.2000
    IncludeStart: 0
      IncludeEnd: 1

ans = 
  MetricRange with properties:

           Start: 0.2000
             End: Inf
    IncludeStart: 0
      IncludeEnd: 0

Now the Metrics Dashboard shows Potential Reuse values less than or equal to 20% as compliant and values greater than 20% with a warning. For the model vdp, the Potential Reuse values are less than 20% and are shown as compliant.

If you want to view the updated Metrics Dashboard thresholds at this point in the example, enter this code in the MATLAB® Command Window:

save(metricConfig,"FileName","MetricConfig.xml");
slmetric.config.setActiveConfiguration(fullfile(pwd,"MetricConfig.xml"));
metricsdashboard vdp

The code saves the updated metric configuration to an XML file, specifies the file as the active configuration, and opens the Metrics Dashboard. In the toolbar of the Metrics Dashboard, click Non-Compile Metrics to collect the metric data and view the metric thresholds.

Remove Metric Threshold

Suppose you want to remove the default threshold. You can remove a threshold from the configuration by using the function removeThreshold.

Remove the threshold for the Potential Reuse results.

removeThreshold(thresholdConfig,potentialReuse);

Now the metric configuration does not contain a threshold for Potential Reuse results, but contains the default thresholds for the other metrics data.

If you want to view the updated Metrics Dashboard thresholds at this point in the example, save the updated metric configuration to an XML file, specify the file as the active configuration, and re-open the Metrics Dashboard. In the toolbar of the Metrics Dashboard, click Non-Compile Metrics to collect the metric data and view the metric thresholds.

Add Metric Threshold

Suppose you do not want a model to contain more than a specific number of blocks. You can add a threshold to the Simulink® block metric mathworks.metrics.SimulinkBlockCount and if a model contains more than the specified number of blocks, the Metrics Dashboard shows the metric data as noncompliant. For this example, you define a threshold so that the Metrics Dashboard shows the block count metric as noncompliant if a model contains more than 11 blocks.

Add a new threshold to the threshold configuration and specify the metric as "mathworks.metrics.SimulinkBlockCount" and the property that the metric applies to as "AggregatedValue".

customThreshold = addThreshold(thresholdConfig,"mathworks.metrics.SimulinkBlockCount","AggregatedValue")
customThreshold = 
  Threshold with properties:

     MetricID: 'mathworks.metrics.SimulinkBlockCount'
    AppliesTo: 'AggregatedValue'

For the function addThreshold, you can specify the threshold property as either "Value" or "AggregatedValue".

In this case, for the metric mathworks.metrics.SimulinkBlockCount:

  • Value — Number of blocks

  • AggregatedValue — Number of blocks for a component and its subcomponents

For information on the Value and AggregatedValue properties for other metrics, see Model Metrics.

Specify Compliant Values

1. Get the default classifications for the custom threshold. The default classification contains a range of values that the threshold considers compliant.

defaultClassification = getClassifications(customThreshold)
defaultClassification = 
  Classification with properties:

    Category: 'Compliant'
       Range: [1×1 slmetric.config.MetricRange]

2. View the Range property in the classification.

defaultClassification.Range
ans = 
  MetricRange with properties:

           Start: -Inf
             End: Inf
    IncludeStart: 0
      IncludeEnd: 0

By default, the classification shows any value as compliant because the range of compliant values is from negative infinity to infinity.

3. Modify the range of compliant values so that only values less than 10 are compliant.

defaultClassification.Range.End = 10;

Specify Warning Values

1. Add a classification for metric data that lead to a warning.

warningClassification = addClassification(customThreshold,"Warning");

2. Modify the range of warning values so that values between 10 and 11 return a warning.

warningClassification.Range.Start = 10;
warningClassification.Range.End = 11;
warningClassification.Range.IncludeStart = 1; % greater than or equal to 10
warningClassification.Range.IncludeEnd = 1; % less than or equal to 11

The range includes the values 10 and 11 because IncludeStart and IncludeEnd are set to 1 (true).

Specify Noncompliant Values

1. Add a classification for noncompliant metric data.

noncompliantClassification = addClassification(customThreshold,"NonCompliant");

2. Modify the range of noncompliant values so that values greater than 11 are noncompliant.

noncompliantClassification.Range.Start = 11;
noncompliantClassification.Range.IncludeStart = 0; % greater than 11 (but not equal to 11)

View Updated Metrics Dashboard

1. Save the updated metric configuration as an XML file that contains the updated threshold and classification information.

save(metricConfig,"FileName","MetricConfig.xml");

2. Set the XML file as the active metric configuration for the Metrics Dashboard.

slmetric.config.setActiveConfiguration(fullfile(pwd,"MetricConfig.xml"));

3. The Metrics Dashboard uses the active configuration the next time you open the dashboard on a model.

metricsdashboard vdp

4. In the toolbar of the Metrics Dashboard, click Non-Compile Metrics to collect the metric data and view the metric thresholds.

Since the model vdp contains more than 11 Simulink blocks, the Metrics Dashboard shows the metric data as noncompliant.

See Also

| |

Related Topics