Main Content

getMetrics

Class: slmetric.Engine
Namespace: slmetric

(To be removed) Access model metric data

The Metrics Dashboard user interface, metricdashboard function, slmetric package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.

Description

Access model metric data from the specified model metric engine. When you call execute, the metric engine collects the metric data. The returned metric data is based on defined architectural components. The components are these Simulink objects:

  • Model

  • Subsystem block

  • Chart

  • MATLAB Function block

  • Protected model

Results = getMetrics(metric_engine) returns metric data for all metrics that the metric engine executed.

example

Results = getMetrics(metric_engine,MetricIDs) returns metric data for the specified metric identifiers.

Results = getMetrics(metric_engine,MetricIDs,'AggregationDepth',ad) returns metric data for the specified metric identifiers and specifying how to aggregate data.

Input Arguments

expand all

When you call execute, metric_engine collects metric data for all available MathWorks metrics or for the specified MetricIDs. Calling getMetrics accesses the collected metric data in metric_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'

Depth or level in the component for which getMetrics aggregates the metric data, specified as a name-value pair argument. Values are one of the following:

  • AllgetMetrics aggregates the detailed results to the component level. Then, the component level results are used to calculate the aggregated values by traversing the component hierarchy. getMetrics returns only the component-level results.

  • None — Do not aggregate measures and values. If you specify this option, getMetrics returns metric values as collected by the metric algorithm. For example, if the metric algorithm returns detailed results, the detailed results are returned without aggregation. AggregatedValue and AggregatedMeasures properties of the returned slmetric.metric.Result objects are empty.

Example: 'AggregationDepth','None'

Data Types: char

Output Arguments

expand all

Metric data from the metric engine.

Examples

expand all

Collect and access model metric data for the model sldemo_mdlref_basic.

Open the model

openExample('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.ModelReferencesSimulationMode = 'AllModes';
metric_engine.AnalyzeLibraries = 1;

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

Collect model metric data

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

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

Version History

Introduced in R2016a

collapse all

R2022a: Metrics Dashboard will be removed

The Metrics Dashboard user interface, metricdashboard function, slmetric package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.