主要内容

本页采用了机器翻译。点击此处可查看英文原文。

getGroupIdentifier

类: slmetric.metric.ResultDetail
命名空间: slmetric.metric

(待删除)获取一组 slmetric.metric.ResultDetail 对象的标识符

以后的版本中将会删除度量仪表板用户界面、metricdashboard 函数、slmetric 包 API 以及相应的自定义项。有关详细信息,请参阅从度量盘迁移到模型可维护性仪表盘

说明

获取一组 slmetric.metric.ResultDetail 对象的标识符。调用 execute 方法收集度量数据。调用 getMetrics 可访问 slmetric.metric.Result 对象,其中包括 slmetric.metric.ResultDetail 对象。将 getGroupIdentifier 方法应用于 slmetric.metric.ResultDetail 对象。

groupIdentifier = getGroupIdentifier(mrd) 获取 slmetric.metric.ResultDetail 对象 mrd 的组标识符。

示例

输入参数

全部展开

调用 slmetric.Engine.execute 方法会创建 slmetric.metric.Result 对象,其中包括 slmetric.metric.ResultDetail 对象。

输出参量

全部展开

一组 slmetric.metric.ResultDetail 对象的标识符。

示例

全部展开

使用 getGroupNamegetGroupIdentfier 方法获取一组克隆的名称和标识符。

打开示例模型 ex_clone_detection.slx,并将模型保存到当前工作文件夹。

openExample('slcheck/EnableSubsystemReuseWithCloneExample','supportingfile','ex_clone_detection');

调用 execute 方法。对 mathworks.metric.CloneDetection 度量应用 getMetrics 方法。

metric_engine = slmetric.Engine();
setAnalysisRoot(metric_engine,'Root','ex_clone_detection','RootType','Model');
execute(metric_engine);
rc = getMetrics(metric_engine,'mathworks.metrics.CloneDetection');

对于每个 slmetric.metric.Result 对象,显示 ComponentPath。对于每个 slmetric.metric.ResultDetail 对象,显示克隆组名称和标识符。

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

结果显示,该模型包含一个克隆组,CloneGroup1,其中包含两个克隆。

关闭模型。

bdclose('ex_clone_detection');

使用 setGroup 方法对详细结果进行分组。创建自定义模型度量时,您可以将此方法作为 algorithm 方法的一部分应用。

打开 sldemo_mdlref_dsm 模型。

openExample('sldemo_mdlref_dsm');

使用 createNewMetricClass 函数创建一个名为 DataStoreCount 的新度量类。该度量统计 Data Store ReadData Store Write 块的数量,并按相应的 Data Store Memory 模块将它们分组在一起。createNewMetricClass 函数会在当前工作文件夹中创建一个名为 DataStoreCount.m 的文件。该文件包含一个构造函数和一个空的度量算法方法。在这个示例中,请确保您是在可写文件夹中工作。

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

要编写度量算法,请打开 DataStoreCount.m 文件并将度量添加到该文件中。在这个示例中,您可以将此逻辑复制到 DataStoreCount.m 文件中来创建度量算法。

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

DataStoreCount 度量类中,SupportsResultDetail 方法设置为 true。度量算法包含 setGroup 方法的逻辑。

现在您的新模型度量已在 DataStoreCount.m 中定义,请在度量存储库中注册新度量。

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

要收集模型的度量数据,请使用 slmetric.Engine 的实例。使用 getMetrics 方法,指定要收集的度量。在本例中,为 sldemo_mdlref_dsm 模型指定数据存储计数度量。

创建度量引擎对象并设置分析根。

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

收集数据存储计数度量的度量数据。

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

对于每个 slmetric.metric.Result 对象,显示 ComponentPath。对于每个 slmetric.metric.ResultDetails 对象,显示数据存储组名称和标识符。

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

结果如下:

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

在本例中,取消注册数据存储计数度量。

slmetric.metric.unregisterMetric(id_metric);

关闭模型。

bdclose('sldemo_mdlref_dsm');

版本历史记录

在 R2017b 中推出

全部折叠