Main Content

setGroup

Class: slmetric.metric.ResultDetail
Namespace: slmetric.metric

(To be removed) Set name and identifier for group of slmetric.metric.ResultDetail objects

The Metrics Dashboard user interface, metricdashboard function, slmetric package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.

Description

For a custom-authored metric, set the identifier and name for a group of slmetric.metric.ResultDetail objects. Apply this method from within the part of the metric algorithm that specifies the details for getMetrics objects.

example

setGroup(groupIdentifier,groupName) sets the values of the group name and identifier for an slmetric.metric.ResultDetail object.

Input Arguments

expand all

Specify a value for the identifier for a group of slmetric.metric.ResultDetail objects.

Specify a value for the name of a group of slmetric.metric.ResultDetail objects.

Examples

expand all

Use the setGroup method to group detailed results. When you create a custom model metric, you apply this method as part of the algorithm method.

To collect metric data on models, use instances of slmetric.Engine. Using the getMetrics method, specify the metric that you want to collect. For this example, specify the data store count metric for the sldemo_mdlref_dsm model.

Open the sldemo_mdlref_dsm model.

openExample('sldemo_mdlref_dsm');

Using the createNewMetricClass function, create a metric class named DataStoreCount. This metric counts the number of Data Store Read and Data Store Write blocks and groups them together by the corresponding Data Store Memory block. The createNewMetricClass function creates a file DataStoreCount.m in the current working folder. The file contains a constructor and empty metric algorithm method. For this example, make sure that you are working in a writable folder.

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

To write the metric algorithm, open the DataStoreCount.m file and add the metric to the file. For this example, you can create the metric algorithm by copying this logic into the DataStoreCount.m file.

classdef DataStoreCount < slmetric.metric.Metric
    % Count the number of Data Store Read and Data Store Write
    % blocks and correlate them across components.
    
    methods
        function this = DataStoreCount()
            this.ID = 'DataStoreCount';
            this.ComponentScope = [Advisor.component.Types.Model, ...
                Advisor.component.Types.SubSystem];
            this.AggregationMode = slmetric.AggregationMode.Sum;
            this.CompileContext = 'None';
            this.Version = 1;
            this.SupportsResultDetails = true;
            
            %Textual information on the metric algorithm
            this.Name = 'Data store usage';
            this.Description = 'Metric that counts the number of Data Store Read and Write'; 
                  'blocks and groups them by the corresponding Data Store Memory block.';
            
        end
        
        function res = algorithm(this, component)
            % Use find_system to get all blocks inside this component.
            dswBlocks = find_system(getPath(component), ...
                'SearchDepth', 1, ...
                'BlockType', 'DataStoreWrite');
            dsrBlocks = find_system(getPath(component), ...
                'SearchDepth', 1, ...
                'BlockType', 'DataStoreRead');          
            
            % Create a ResultDetail object for each data store read and write block.
			% Group ResultDetails by the data store name.
            details1 = slmetric.metric.ResultDetail.empty();
            for i=1:length(dswBlocks)
                details1(i) = slmetric.metric.ResultDetail(getfullname(dswBlocks{i}),...
                            get_param(dswBlocks{i}, 'Name'));
		   groupID = get_param(dswBlocks{i},'DataStoreName');
		   groupName = get_param(dswBlocks{i},'DataStoreName');
                details1(i).setGroup(groupID, groupName);                
                details1(i).Value = 1;
            end
            
            details2 = slmetric.metric.ResultDetail.empty();
            for i=1:length(dsrBlocks)
                details2(i) = slmetric.metric.ResultDetail(getfullname(dsrBlocks{i}),...
                   get_param(dsrBlocks{i}, 'Name'));
                groupID = get_param(dsrBlocks{i},'DataStoreName');
				groupName = get_param(dsrBlocks{i},'DataStoreName');
                details2(i).setGroup(groupID, groupName);
                details2(i).Value = 1;
            end
            
            res = slmetric.metric.Result();
            res.ComponentID = component.ID;
            res.MetricID = this.ID;
            res.Value = length(dswBlocks)+ length(dsrBlocks);
            res.Details = [details1 details2];
        end
    end
end

In the DataStoreCount metric class, the SupportsResultDetail method is set to true. The metric algorithm contains the logic for the setGroup method.

Now that your new model metric is defined in DataStoreCount.m, register the new metric.

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

Create a metric engine object and set the analysis root.

metric_engine = slmetric.Engine();
setAnalysisRoot(metric_engine,'Root','sldemo_mdlref_dsm',...
'RootType','Model');

Collect metric data for the Data Store Count metric.

execute(metric_engine);
rc=getMetrics(metric_engine, id_metric);

For each slmetric.metric.Result object, display the ComponentPath. For each slmetric.metric.ResultDetails object, display the Data Store group name and identifier.

for n=1:length(rc.Results)
    if rc.Results(n).Value > 0
	for m=1:length(rc.Results(n).Details)
	  disp(['ComponentPath: ',rc.Results(n).ComponentPath]);
          disp(['Group Name: ',rc.Results(n).Details(m).getGroupName]);
          disp(['Group Identifier: ',rc.Results(n).Details(m).getGroupIdentifier]);
        end
    else
        disp(['No results for ComponentPath: ',rc.Results(n).ComponentPath]);
    end
    disp(' ');
end

Here are the results.

ComponentPath: sldemo_mdlref_dsm
Group Name: ErrorCond
Group Identifier: ErrorCond
 
No results for ComponentPath: sldemo_mdlref_dsm/More Info1
 
ComponentPath: sldemo_mdlref_dsm_bot
Group Name: RefSignalVal
Group Identifier: RefSignalVal
 
ComponentPath: sldemo_mdlref_dsm_bot2
Group Name: ErrorCond
Group Identifier: ErrorCond
 
ComponentPath: sldemo_mdlref_dsm_bot/PositiveSS
Group Name: RefSignalVal
Group Identifier: RefSignalVal
 
ComponentPath: sldemo_mdlref_dsm_bot/NegativeSS
Group Name: RefSignalVal
Group Identifier: RefSignalVal

For this example, unregister the data store count metric.

slmetric.metric.unregisterMetric(id_metric);

Close the model.

bdclose('sldemo_mdlref_dsm');

Version History

Introduced in R2017b

collapse all

R2022a: Metrics Dashboard will be removed

The Metrics Dashboard user interface, metricdashboard function, slmetric package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.