Main Content

getMetrics

R2026b

Access metric data for model testing artifacts

Since R2022a

Description

results = getMetrics(metricEngine,metricIDs) returns metric results for the specified metric.Engine object for the metrics specified by metricIDs. To collect metric results for the metricEngine object, use the execute function. Then, to access the results, use the getMetrics function.

example

results = getMetrics(metricEngine,metricIDs,ScopeId=scopeId) gets metric results for a specific unit or component in your project.

Examples

collapse all

Use a metric.Engine object to collect design cost metric data on a model reference hierarchy in a project.

To open the project, use this command.

openExample('simulink/VisualizeModelReferenceHierarchiesExample')

The project contains sldemo_mdlref_depgraph, which is the top-level model in a model reference hierarchy. This model reference hierarchy represents one design unit.

Create a metric.Engine object.

metric_engine = metric.Engine();

Update the trace information for metric_engine to reflect any pending artifact changes.

updateArtifacts(metric_engine)

Create an array of metric identifiers for the metrics you want to collect. For this example, create a list of all available design cost estimation metrics.

metric_Ids = getAvailableMetricIds(metric_engine,...
    App="DesignCostEstimation")
metric_Ids =

  1×2 string array

    "DataSegmentEstimate"    "OperatorCount"

To collect results, execute the metric engine.

execute(metric_engine,metric_Ids);

Because you executed the engine without specifying a ScopeId, the engine collects metrics for the entire sldemo_mdlref_depgraph model reference hierarchy.

Use the getMetrics function to access the high-level design cost metric results.

results_OpCount = getMetrics(metric_engine,"OperatorCount");
results_DataSegmentEstimate = getMetrics(metric_engine,"DataSegmentEstimate");

disp(['Unit:  ', results_OpCount.Artifacts.Name])
disp(['Total Cost:  ', num2str(results_OpCount.Value)])

disp(['Unit:  ', results_DataSegmentEstimate.Artifacts.Name])
disp(['Data Segment Size (bytes):  ', num2str(results_DataSegmentEstimate.Value)])
Unit:  sldemo_mdlref_depgraph
Total Cost:  57

Unit:  sldemo_mdlref_depgraph
Data Segment Size (bytes):  228

The results show that for the sldemo_mdlref_depgraph model, the estimated total cost of the design is 57 and the estimated data segment size is 228 bytes.

Use the generateReport function to access detailed metric results in a PDF report. Name the report "MetricResultsReport.pdf".

reportLocation = fullfile(pwd,"MetricResultsReport.pdf");
generateReport(metric_engine,...
    App="DesignCostEstimation",...
    Type="pdf",...
    Location=reportLocation);

The report contains a detailed breakdown of the operator count and data segment estimate metric results.

Table of contents for generated report.

Input Arguments

collapse all

Metric engine object for which to access metric results, specified as a metric.Engine object.

Metric identifiers for metrics to access, specified as a character vector, cell array of character vectors, string, or string array. For a list of design cost metrics and their identifiers, see Design Cost Model Metrics. For a list of requirements-based model testing metrics and their identifiers, see Model Testing Metrics (Simulink Check).

Example: "DataSegmentEstimate"

Example: ["DataSegmentEstimate", "OperatorCount"]

Digital thread URI for the artifact whose metric results you want to get, specified as a string scalar.

A digital thread URI is a stable identifier for an artifact, such as a model file, or a sub-file artifact, such as a block. The digital thread uses these URIs as a consistent way to refer to artifacts across tools and inside metric results. Use digitalthread.uri.simulink.fromObject to get the URI for a model or element in a model. ScopeId does not support file-level URIs from digitalthread.uri.fromFilePath.

Note

If you specify both ScopeId and ArtifactScope, ScopeId takes precedence.

Example: "mwdigitalthread://myProject/myModel.slx#addr=myModel/###"

Data Types: string

Output Arguments

collapse all

Metric results, returned as an array of metric.Result objects.

Version History

Introduced in R2022a

expand all