主要内容

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

getMetrics

类: slmetric.Engine
命名空间: slmetric

(待移除)访问模型度量数据

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

说明

从指定的模型度量引擎访问模型度量数据。当您调用 execute 时,度量引擎会收集度量数据。返回的度量数据基于已定义的架构组件。组件是以下 Simulink 对象:

  • 模型

  • Subsystem 模块

  • MATLAB Function 模块

  • 受保护模型

Results = getMetrics(metric_engine) 返回度量引擎执行的所有度量的度量数据。

示例

Results = getMetrics(metric_engine,MetricIDs) 返回指定度量标识符的度量数据。

Results = getMetrics(metric_engine,MetricIDs,'AggregationDepth',ad) 返回指定度量标识符的度量数据,并指定如何聚合数据。

输入参数

全部展开

当您调用 execute 时,metric_engine 会收集所有可用的 MathWorks 度量或指定的 MetricIDs 指标的度量数据。调用 getMetrics 可访问 metric_engine 中收集的度量数据。

模型度量或您创建的自定义模型度量的度量标识符。您可以指定一个或多个度量标识符。您可以通过调用 slmetric.metric.getAvailableMetrics 获得度量标识符。

示例: 'mathworks.metrics.DescriptiveBlockNames'

getMetrics 度量数据的组件中的深度或级别,以名称-值对参量的形式指定。数值为以下几种之一:

  • All - getMetrics 将详细结果聚合到组件级别。然后,通过遍历组件层次结构,利用组件级结果计算聚合值。getMetrics 仅返回组件级结果。

  • None - 请勿聚合度量和值。如果指定此选项,getMetrics 将返回度量算法收集的度量值。例如,如果度量算法返回详细结果,则返回的详细结果不经过聚合处理。返回的 slmetric.metric.Result 对象的 AggregatedValueAggregatedMeasures 属性为空。

示例: 'AggregationDepth','None'

数据类型: char

输出参量

全部展开

来自度量引擎的度量数据。

示例

全部展开

收集和访问模型 sldemo_mdlref_basic 的模型度量数据。

打开模型

openExample('sldemo_mdlref_basic'); 

创建一个 slmetric.Engine 对象,并设置要进行分析的模型的根。

metric_engine = slmetric.Engine();

% Include referenced models and libraries in the analysis.
% These properties are on by default.
metric_engine.ModelReferencesSimulationMode = 'AllModes';
metric_engine.AnalyzeLibraries = 1;

setAnalysisRoot(metric_engine, 'Root',  'sldemo_mdlref_basic');

收集模型度量数据

execute(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

获取返回一个 slmetric.metric.ResultCollection 对象数组 res_col 的模型度量数据。

res_col = getMetrics(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

显示 mathworks.metrics.SimulinkBlockCount 度量的结果。

for n=1:length(res_col)
    if res_col(n).Status == 0
        result = res_col(n).Results;
        
        for m=1:length(result)
            disp(['MetricID: ',result(m).MetricID]);
            disp(['  ComponentPath: ', result(m).ComponentPath]);
            disp(['  Value: ', num2str(result(m).Value)]);
            disp(['  AggregatedValue: ', num2str(result(m).AggregatedValue)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end

版本历史记录

在 R2016a 中推出

全部折叠