主要内容

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

slmetric.Engine 类

命名空间: slmetric

(待删除)收集模型或模型组件的度量数据

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

描述

使用 slmetric.Engine 对象通过调用 execute 来收集模型的度量数据。使用 getMetrics 访问度量数据并返回 slmetric.metric.ResultCollection 对象数组。该度量数据会永久保存在仿真缓存文件夹中。同一模型的 slmetric.Engine 对象的未来实例化可以访问缓存的度量数据,而无需重新生成度量数据。

slmetric.Engine 类是一个 handle 类。

创建对象

描述

metric_engine = slmetric.Engine() 创建一个度量引擎对象。

示例

属性

全部展开

要收集度量数据的根模型或子系统的名称,由 slmetric.Engine.setAnalysisRoot 方法指定。此属性是只读的。

数据类型: char

指定度量引擎是否分析根模型中与库链接的子系统,包括根下引用模型中的库。度量分析不包括链接到 Simulink 内置库的块。将此参数设置为 false0,即可不在度量分析中包含库。

数据类型: logical

指定度量引擎是否分析根模型中引用的模型。请从以下值中选择:

描述
'None'度量引擎不会收集被引用模型的度量数据。
'NormalModeOnly'度量引擎仅收集在正常仿真模式下运行的参考模型的度量数据。
'AllModes'度量引擎收集在正常和加速仿真模式下运行的参考模型的度量数据。

数据类型: 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.ExplicitIOCount');

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

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

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

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)]);
            disp(['  Measures: ', num2str(result(m).Measures)]);
            disp(['  AggregatedMeasures: ', num2str(result(m).AggregatedMeasures)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end

结果如下:

MetricID: mathworks.metrics.ExplicitIOCount
  ComponentPath: sldemo_mdlref_basic
  Value: 3
  AggregatedValue: 4
  Measures: 0  3
  AggregatedMeasures: 3  3
MetricID: mathworks.metrics.ExplicitIOCount
  ComponentPath: sldemo_mdlref_basic/More Info
  Value: 0
  AggregatedValue: 0
  Measures: 0  0
  AggregatedMeasures: 0  0
MetricID: mathworks.metrics.ExplicitIOCount
  ComponentPath: sldemo_mdlref_counter
  Value: 4
  AggregatedValue: 4
  Measures: 3  1
  AggregatedMeasures: 3  1

对于 ComponentPath: sldemo_mdlref_basic,值为 3,因为有 3 个输出。这三个输出位于 Measures 数组的第二个元素中。slmetric.metric.AggregationModeMax,所以 AggregatedValue4,也就是 sldemo_mdlref_counter 的输入和输出数。AggregatedMeasures 数组包含组件或子组件的最大输入和输出数。

版本历史记录

在 R2016a 中推出

全部展开