Main Content

metric.Engine

Collect metric results

Since R2020b

Description

A metric.Engine object represents the metric engine that you can execute with the execute object function to collect metric results. Use getMetrics to access the metric results and return an array of metric.Result objects. Use the metric results to assess the status and quality of your design. Use the model maintainability metrics to analyze the maintainability and complexity of the design. Use the model and code testing metrics to analyze artifacts such as requirements, test results, and coverage results. For additional metrics, see Design Cost Model Metrics (Fixed-Point Designer).

Creation

Description

example

metric_engine = metric.Engine() creates a metric engine object that collects metric results on the current project.

example

metric_engine = metric.Engine(projectPath) opens the project projectPath and creates a metric engine object that collects metric results on the project.

Input Arguments

expand all

Path of the project for which you want to collect metric results, specified as a character vector or string scalar.

Properties

expand all

This property is read-only.

Project for which the engine collects metric results, returned as a string.

Object Functions

executeCollect metric results
generateReportGenerate report file containing metric results
getArtifactErrorsReturn errors that occurred during artifact tracing
getArtifactIssuesReturn issues that occur during artifact analysis
getAvailableMetricIdsReturn metric identifiers for available metrics
getMetricsAccess metric results
openArtifactOpen traced artifact from metric result
updateArtifactsUpdate trace information for pending artifact changes in the project

Examples

collapse all

Use a metric.Engine object to 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.

Use a metric.Engine object to 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

Version History

Introduced in R2020b