Main Content

slmetric.Engine class

Package: slmetric

(To be removed) Collect metric data on models or model components

slmetric.Engine will be removed in a future release. For size, architecture, and complexity metrics, use the metric.Engine API and the model maintainability metrics instead. For more information, see metric.Engine and Collect Model Maintainability Metrics Programmatically.


Use a slmetric.Engine object to collect metric data on models by calling execute. Use getMetrics to access the metric data and return an array of slmetric.metric.ResultCollection objects. This metric data is persistent in the simulation cache folder. Future instantiations of the slmetric.Engine object for the same model can access the cached metric data without regenerating the metric data.


metric_engine = slmetric.Engine() creates a metric engine object.


expand all

Name of root model or subsystem on which to collect metric data, as specified by the slmetric.Engine.setAnalysisRoot method. This property is read-only.

Specify if the metric engine analyzes library-linked subsystems in the root model, including libraries inside referenced models under the root. Metric analysis does not include linked blocks to Simulink built-in libraries. Set this parameter to false or 0 to not include libraries in the metric analysis.

Data Types: logical

Specify if the metric engine analyzes referenced models in your root model. Choose from these values:

'None'Metric engine does not collect metric data for referenced models.
'NormalModeOnly'Metric engine collects metric data only for referenced models running in normal simulation mode.
'AllModes'Metric engine collects metric data for referenced models running in normal and accelerated simulation modes.

Data Types: char


execute(To be removed) Collect metric data
exportMetricsExport model metrics
getAnalysisRootMetricGet metric data for one metric for analysis root only
getErrorLog(To be removed) Get error log
getMetricDistributionGet metric distribution
getMetricMetaInformation Obtain metric metadata
getMetrics(To be removed) Access model metric data
getStatisticsGet statistics on metric data
setAnalysisRootSpecify model or subsystem for metric analysis


collapse all

Collect and access model metric data for the model sldemo_mdlref_basic.

Open the model.


Create an slmetric.Engine object and set the root in the model for analysis.

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');

Collect model metric data

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

Get the model metric data that returns an array of slmetric.metric.ResultCollection objects, res_col.

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

Display the results for the mathworks.metrics.ExplicitIOCount metric.

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

Here are the results:

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

For the ComponentPath: sldemo_mdlref_basic, the value is 3 because there are 3 outputs. The three outputs are in the second element of the Measures array. The slmetric.metric.AggregationMode is Max, so the AggregatedValue is 4 which is the number of inputs and outputs to sldemo_mdlref_counter. The AggregratedMeasures array contains the maximum number of inputs and outputs for a component or subcomponent.

Version History

Introduced in R2016a

expand all