本示例展示了如何收集和访问模型 sldemo_mdlref_basic 的度量数据。
打开 sldemo_mdlref_basic 模型。
open_system('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
对于 ComponentPath: sldemo_mdlref_basic,其值为 3,因为有三个输出。这三个输出位于 Measures 数组的第二个元素中。slmetric.metric.AggregationMode 是 Max,所以 AggregatedValue 是 4,也就是 sldemo_mdlref_counter 的输入和输出数。AggregatedMeasures 数组包含组件或子组件的最大输入和输出数。