Main Content

getMetrics

Access metric results

Since R2020b

Description

example

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

Note that there is also a function getMetrics (Fixed-Point Designer) in the Fixed-Point Designer™ documentation.

example

results = getMetrics(metricEngine,metricIDs,'ArtifactScope',scope) returns metric results for the artifacts in the scope that you specify. For example, you can specify the scope to be a unit in your project.

Examples

collapse all

Collect metric results on the requirements-based testing artifacts in a project.

Open a project that contains models and testing artifacts. For this example, in the MATLAB® Command Window, enter:

dashboardCCProjectStart

Create a metric.Engine object. You can use the metric.Engine object to collect metric results for the current project.

metric_engine = metric.Engine();

Update the trace information for metric_engine to ensure that the artifact information is up to date.

updateArtifacts(metric_engine)

Collect results for the metric 'RequirementsPerTestCase' by using the execute function on the metric.Engine object.

execute(metric_engine,'RequirementsPerTestCase');

Use the function getMetrics to access the results. Assign the array of result objects to the results variable.

results = getMetrics(metric_engine,'RequirementsPerTestCase');

Access the metric results data by using the properties of the metric.Result objects in the array.

for n = 1:length(results)
    disp(['Test Case: ',results(n).Artifacts(1).Name])
    disp(['  Number of Requirements: ',num2str(results(n).Value)])
end

Collect metrics for one unit in the project. Specify the unit and collect metrics for only the artifacts that trace to the model.

Open the project that contains the model. At the command line, type dashboardCCProjectStart.

dashboardCCProjectStart

Create a metric.Engine object for the project.

metric_engine = metric.Engine();

Update the trace information for metric_engine to ensure that the artifact information is up to date.

updateArtifacts(metric_engine)

Create a variable that represents the path to the unit model db_DriverSwRequest.

modelPath = fullfile(pwd, 'models', 'db_DriverSwRequest.slx');

Collect results for the metric 'RequirementsPerTestCase' by using the execute function on the engine object and limiting the scope to the db_DriverSwRequest model.

execute(metric_engine,'RequirementsPerTestCase',...
'ArtifactScope',{modelPath, 'db_DriverSwRequest'});

Use the function getMetrics to access the results.

results = getMetrics(metric_engine,'RequirementsPerTestCase');
for n = 1:length(results)
    disp(['Test Case: ',results(n).Artifacts(1).Name])
    disp(['  Number of Requirements: ',num2str(results(n).Value)])
end
Test Case: Set button
  Number of Requirements: 0
Test Case: Resume button
  Number of Requirements: 1
Test Case: Decrement button short
  Number of Requirements: 2
Test Case: Enable button
  Number of Requirements: 1
Test Case: Increment button hold
  Number of Requirements: 1
Test Case: Increment button short
  Number of Requirements: 2
Test Case: Cancel button
  Number of Requirements: 1
Test Case: Decrement button hold
  Number of Requirements: 1

Input Arguments

collapse all

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

Metric identifiers for metrics that you want to collect, specified as a character vector, cell array of character vectors, string, or string array.

You can use the function getAvailableMetricIds to return a list of available metric identifiers.

For information on the metrics and their identifiers, see:

Example: 'slcomp.OverallCyclomaticComplexity'

Example: {'slcomp.OverallMATLABeLOC', 'slcomp.OverallSignalLines'}

Example: 'TestCasesPerRequirementDistribution'

Example: {'slcomp.mt.TestStatus', 'slcomp.mt.CoverageBreakdown'}

Path and identifier of the project file for which you want to collect metric results, specified as a cell array of character vectors or a string array. The first entry is the full path to a project file and the second entry is the identifier of the object inside the project file.

For a unit model, the first entry is the full path to the model file and the second entry is the name of the block diagram. When you use this argument, the metric engine collects the results for the artifacts that trace to specified project file.

Example: {'C:\work\MyModel.slx', 'MyModel'}

Output Arguments

collapse all

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

Alternative Functionality

App

You can also view metric results by using the dashboard user interface.

Version History

Introduced in R2020b