Main Content

execute

Collect metric results

Since R2020b

Description

example

execute(metricEngine,metricIDs) collects results in the specified metric.Engine object for the metrics that you specify in metricIDs.

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

example

execute(metricEngine,metricIDs,'ArtifactScope',scope) collects 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 design artifacts in a project.

Open a project containing models that you want to analyze. For this example, in the MATLAB® Command Window, enter:

openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample");
openProject("cc_CruiseControl");

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

metric_engine = metric.Engine();

Collect results for the metric slcomp.OverallCyclomaticComplexity by executing the metric engine. For more information on the metric, see Model Maintainability Metrics.

execute(metric_engine,'slcomp.OverallCyclomaticComplexity');

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

results = getMetrics(metric_engine,'slcomp.OverallCyclomaticComplexity');

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

for n = 1:length(results)
    disp(['Model: ',results(n).Scope.Name])
    disp(['  Overall Design Cyclomatic Complexity: ',num2str(results(n).Value)])
end
Model: cc_DriverSwRequest
  Overall Design Cyclomatic Complexity: 9
Model: cc_ThrottleController
  Overall Design Cyclomatic Complexity: 4
Model: cc_ControlMode
  Overall Design Cyclomatic Complexity: 22
Model: cc_CruiseControl
  Overall Design Cyclomatic Complexity: 1
Model: cc_LightControl
  Overall Design Cyclomatic Complexity: 4

For more information on how to collect metrics for design artifacts, see Collect Model Maintainability Metrics Programmatically.

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:

openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample");
openProject("cc_CruiseControl");

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 a model and collect metrics for only the artifacts that trace to the model.

Open the project that contains the model. For this example, in the MATLAB Command Window, enter:

openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample");
openProject("cc_CruiseControl");

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 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

Input Arguments

collapse all

Metric engine object for which you want to collect 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'}

Alternative Functionality

App

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

Version History

Introduced in R2020b