Customize Metrics Dashboard Layout and Functionality

Customize the Metrics Dashboard by using the model metric programming interface. Customizing the dashboard extends your ability to use model metrics to assess that your model and code comply with size, complexity, and readability requirements. You can perform these Metrics Dashboard customizations:

  • Configure compliance metrics to obtain compliance and issues metric data on your Model Advisor configuration.

  • Customize the dashboard layout by adding custom metrics, removing widgets, and configuring existing widgets.

  • Categorize metric data as compliant, warning, and noncompliant by specifying metric threshold values.

Configure Compliance Metrics

Use the Metrics Dashboard and metric APIs to obtain compliance and issues metric data on your Model Advisor configuration or on an existing check group such as the MISRA checks. To set up your own Model Advisor configuration, see Use the Model Advisor Configuration Editor to Customize the Model Advisor. After you have set up your Model Advisor configuration, follow these steps to specify the check groups for which you want to obtain compliance and issues metric data:

1. To open the model, at the MATLAB command prompt, enter this command:

sf_car

2. Open the default configuration (that is, the one that is shipped with the Metrics Dashboard). Add a corresponding slmetric.config.Configuration object to the base workspace.

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

3. Create a cell array consisting of the Check Group IDs that correspond to those check groups. Obtain a Check Group ID by opening the Model Advisor Configuration Editor and selecting the folder that contains the group of checks. The folder contains a Check Group ID parameter.

values = {'maab', 'hisl_do178', '_SYSTEM_By Task_misra_c'};

This cell array specifies MAAB, High-Integrity, and MISRA check groups. The values maab and hisl_do178 correspond to a subset of MAAB and High-Integrity System checks. To include all checks, specify the value for the Check Group ID parameter from the Model Advisor Configuration Editor.

4. To set the configuration, pass the values cell array into the setMetricFamilyParameterValues method. The 'ModelAdvisorStandard' string is a standard string that you must supply to thesetMetricFamilyParameterValues method.

setMetricFamilyParameterValues(metricconfig,'ModelAdvisorStandard', values);

5. Open the default configuration for the Metrics Dashboard layout (that is, the one that ships with the Metrics Dashboard).

dashboardconfig = slmetric.dashboard.Configuration.openDefaultConfiguration();

6. Obtain the slmetric.dashboard.Layoutobject from the slmetric.dashboard.Configuration object.

layout = getDashboardLayout(dashboardconfig);

7. Obtain widget objects that are in the layout object.

layoutWidget = getWidgets(layout);

8. The slmetric.dashboard.Layout object contains these objects:

  • An slmetric.dashboard.Container object that holds an slmetrics.dashboard.Widget object of type SystemInfo. The red number one in the diagram below indicates the SystemInfo widget.

  • An slmetric.dashboard.Groupobject that has the title SIZE.

  • An slmetrics.dashboard.Group object that has the title MODELING GUIDELINE COMPLIANCE.

  • An slmetrics.dashboard.Group object that has the title ARCHITECTURE.

In the diagram, the red numbers 1, 2, 3, and 4 indicate their order in the layoutWidget array. Obtain the compliance group from the layout.

complianceGroup = layoutWidget(3);

9. The modeling guideline compliance group contains two containers. The top container contains the High Integrity and MAAB compliance and check issues widgets. The red numbers 3.1.1, 3.1.2, and 3.1.3 indicate the order of the three widgets in the first container. The second container contains the Code Analyzer Warnings and Diagnostic Warnings widgets.

Remove the High Integrity compliance widget.

complianceContainers = getWidgets(complianceGroup);
complianceContainerWidgets = getWidgets(complianceContainers(1));
complianceContainers(1).removeWidget(complianceContainerWidgets(1)); 

10. Create a custom widget for visualizing MISRA check issues metrics.

misraWidget = complianceContainers(1).addWidget('Custom', 1);
misraWidget.Title=('MISRA'); 
misraWidget.VisualizationType = 'RadialGauge'; 
misraWidget.setMetricIDs('mathworks.metrics.ModelAdvisorCheckCompliance._SYSTEM_By Task_misra_c'); 
misraWidget.setWidths(slmetric.dashboard.Width.Medium);

11. The bar chart widget visualizes the High Integrity and MAAB check groups. Point this widget to the MISRA and MAAB check groups.

setMetricIDs(complianceContainerWidgets(3),...
({'mathworks.metrics.ModelAdvisorCheckIssues._SYSTEM_By Task_misra_c',...
'mathworks.metrics.ModelAdvisorCheckIssues.maab'}));
complianceContainerWidgets(3).Labels = {'MISRA', 'MAAB'};

12. To run the Metrics Dashboard at this point in the example, uncomment out the following lines of code. The save commands serialize the API information to XML files. The slmetric.config.setActiveConfiguration and slmetric.dashboard.setActiveConfiguration commands set the active configuration objects.

% save(metricconfig,'FileName','MetricConfig.xml');
% save(dashboardconfig,'Filename','DashboardConfig.xml');
% slmetric.config.setActiveConfiguration(fullfile(pwd,'MetricConfig.xml'));
% slmetric.dashboard.setActiveConfiguration(fullfile(pwd,'DashboardConfig.xml'));

14. To open the Metrics Dashboard, uncomment this code.

% metricsdashboard sf_car

15. Click the All Metrics button and run all metrics. The Metrics Dashboard displays results for the MISRA checks instead of the High Integrity checks.

16. Close the Metrics Dashboard.

Add a Custom Metric to Dashboard

Create a custom metric that counts nonvirtual blocks. To display this metric on the Metrics Dashboard, specify a widget. Add it to the size group.

1. Using the createNewMetricClass function, create a new metric class named nonvirtualblockcount. The function creates a file, nonvirtualblockcount.m, in the current working folder. The file contains a constructor and empty metric algorithm method. For this example, make sure you are in a writable folder.

className = 'nonvirtualblockcount';
slmetric.metric.createNewMetricClass(className);

2. To write the metric algorithm, open the nonvirtualblockcount.m file and add the metric to the file. For this example, the file nonvirtualblockcount_orig.m contains the logic to create a metric that counts the nonvirtual blocks. Copy this file to the to nonvirtualblockcount.m.

copyfile nonvirtualblockcount_orig.m nonvirtualblockcount.m f

3. Register the new metric in the metric repository.

[id_metric,err_msg] = slmetric.metric.registerMetric(className);

4. Remove the widget that represents the Simulink block count metric. This widget is the first one in the size group. The size group is second in the layoutWidget array.

sizeGroup = layoutWidget(2); 
sizeGroupWidgets = sizeGroup.getWidgets(); 
sizeGroup.removeWidget(sizeGroupWidgets(1));

5. Add a widget that displays the nonvirtual block count metric. For custom widgets, the default visualization type is single value. If you want to use a different visualization type, specify a different value for the VisualizationType property.

newWidget = sizeGroup.addWidget('Custom', 1);
newWidget.Title=('Nonvirtual Block Count'); 
newWidget.setMetricIDs('nonvirtualblockcount');
newWidget.setWidths(slmetric.dashboard.Width.Medium);
newWidget.setHeight(70);

6. Specify whether there are lines separating the custom widget from other widgets in the group. These commands specify that there is a line to the right of the widget.

s.top = false;
s.bottom = false;
s.left= false;
s.right= true;
newWidget.setSeparators([s, s, s, s]);

7. To run the Metrics Dashboard at this point in the example, uncomment out the following lines of code. The save commands serialize the API information to XML files. The slmetric.config.setActiveConfiguration and slmetric.dashboard.setActiveConfiguration commands set the active configuration objects.

% save(metricconfig,'FileName','MetricConfig.xml');
% save(dashboardconfig,'Filename','DashboardConfig.xml');
% slmetric.config.setActiveConfiguration(fullfile(pwd,'MetricConfig.xml'));
% slmetric.dashboard.setActiveConfiguration(fullfile(pwd,'DashboardConfig.xml'));

8. To open the Metrics Dashboard, uncomment this code.

% metricsdashboard sf_car

9. Click the All Metrics button and run all metrics. The Metrics Dashboard displays results for the nonvirtual block count metric instead of the Simulink block count metric.

10. Close the Metrics Dashboard.

Add Metric Thresholds

For the nonvirtual block count and MISRA metrics, specify metric threshold values. Specifying these values enables you to access the quality of your model by categorizing your metric data as follows:

  • Compliant — Metric data that is in an acceptable range.

  • Warning — Metric data that requires review.

  • Noncompliant — Metric data that requires you to modify your model.

1. Access the slmetric.config.ThresholdConfiguration object in the slmetric.config.Configuration object metricconfig. Create the corresponding slmetric.config.ThresholdConfiguration object (TC) in the base workspace.

TC=getThresholdConfigurations(metricconfig);

2. Add two slmetric.config.Threshold objects to TC. Each slmetric.config.Threshold object contains a default slmetric.config.Classification object that is compliant. Specify the compliant metric ranges.

T1=addThreshold(TC,'mathworks.metrics.ModelAdvisorCheckIssues._SYSTEM_By Task_misra_c',...
 'AggregatedValue');
C=getClassifications(T1); 
C.Range.Start=-inf;
C.Range.End=0;
C.Range.IncludeStart=0;
C.Range.IncludeEnd=1;

T2=addThreshold(TC,'mathworks.metrics.ModelAdvisorCheckCompliance._SYSTEM_By Task_misra_c',...
 'AggregatedValue'); 
C=getClassifications(T2); 
C.Range.Start=1;
C.Range.End=inf;
C.Range.IncludeStart=1;
C.Range.IncludeEnd=0;

3. For each slmetric.config.Threshold object, specify the Warning ranges.

C=addClassification(T1,'Warning');
C.Range.Start=0;
C.Range.End=inf;
C.Range.IncludeStart=0;
C.Range.IncludeEnd=1;

C=addClassification(T2,'Warning');
C.Range.Start=-inf;
C.Range.End=1;
C.Range.IncludeStart=0;
C.Range.IncludeEnd=0;

These commands specify that if the MISRA checks have issues, the model status is warning. If there are no issues, the model status is compliant.

4. Add a third slmetric.config.Threshold object to TC. Specify compliant, warning, and noncompliant ranges for this slmetric.config.Threshold object.

T3=addThreshold(TC,'nonvirtualblockcount', 'AggregatedValue');
C=getClassifications(T3); 
C.Range.Start=-inf;
C.Range.End=20;
C.Range.IncludeStart=1;
C.Range.IncludeEnd=1;

C=addClassification(T3, 'Warning');
C.Range.Start=20;
C.Range.End=30;
C.Range.IncludeStart=0;
C.Range.IncludeEnd=1;

C=addClassification(T3, 'NonCompliant');
C.Range.Start=30;
C.Range.End=inf;
C.Range.IncludeStart=0;
C.Range.IncludeEnd=1;

These commands specify that the compliant range is less than or equal to 20. The warning range is from 20 up to but not including 30. The noncompliant range is greater than 30.

5. Save the configuration objects. These commands serialize the API information to XML files.

save(metricconfig,'FileName','MetricConfig.xml');
save(dashboardconfig,'Filename','DashboardConfig.xml');

6. Set the active configurations.

slmetric.config.setActiveConfiguration(fullfile(pwd, 'MetricConfig.xml'));
slmetric.dashboard.setActiveConfiguration(fullfile(pwd, 'DashboardConfig.xml'));

7. For your model, open the Metrics Dashboard.

metricsdashboard sf_car

For the MISRA check compliance issues, the gauge is yellow because 76% of the checks pass. Any percentage less than 100% is a warning. The bar chart also displays a yellow because the model contains three MISRA check issues. Any number greater than zero is a warning.

The Nonvirtual Block Count widget is in the compliant range because there are 15 nonvirtual blocks.

8. To reset the configuration and unregister the metric, uncomment and execute these commands:

% slmetric.metric.unregisterMetric(className); 
% slmetric.dashboard.setActiveConfiguration(''); 
% slmetric.config.setActiveConfiguration('');

See Also

|

Related Topics