This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

execute

Class: slmetric.Engine
Package: slmetric

Collect metric data

Syntax

execute(metric_engine)
execute(slmetric_obj,MetricIDs)

Description

Collect model metric data for the specified metric engine object. The model metric data is based on defined architectural components. The components are these Simulink objects:

  • Model

  • Subsystem block

  • Chart

  • MATLAB Function block

  • Protected model

example

execute(metric_engine) collects metric data for available model metrics, which can include MathWorks metrics and custom metrics.

example

execute(slmetric_obj,MetricIDs) collects metric data for only the specified metrics, which can be MathWorks metrics or custom metrics.

Input Arguments

expand all

Create a slmetric.Engine object.

metric_engine = slmetric.Engine();

Metric identifier for Model Metrics or custom model metrics that you create. You can specify one or multiple metric identifiers. You can get metric identifiers by calling slmetric.metric.getAvailableMetrics.

Example: 'mathworks.metrics.DescriptiveBlockNames'

Examples

expand all

Collect and access model metric data for the model sldemo_mdlref_basic.

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.AnalyzeModelReferences = 1;
metric_engine.AnalyzeLibraries = 1;

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

Collect model metric data

execute(metric_engine);

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

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

Display the results for the mathworks.metrics.SimulinkBlockCount 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)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end

Collect and access model metric data for the model sldemo_mdlref_basic.

Create an slmetric.Engine object. Include referenced models and libraries in the analysis and set the root in the model for analysis.

metric_engine = slmetric.Engine();
metric_engine.AnalyzeModelReferences = 1;
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)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end

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.

Introduced in R2016a