主要内容

metric.Engine

收集度量结果

说明

metric.Engine 对象表示度量引擎,您可以使用 execute 对象函数执行该引擎来收集度量结果。使用 getMetrics 访问度量结果,并返回由 metric.Result 对象组成的数组。使用度量结果来评估设计的状态和质量。使用模型可维护性度量来分析设计的可维护性和复杂性。使用模型和代码测试度量来分析需求、测试结果和覆盖率结果等工件。有关其他度量,请参见 Design Cost Model Metrics (Fixed-Point Designer)

创建对象

描述

metric_engine = metric.Engine() 创建一个度量引擎对象,用于收集当前工程的度量结果。

示例

metric_engine = metric.Engine(projectPath) 打开工程 projectPath,并创建一个用于收集工程的度量结果的度量引擎对象。

示例

输入参量

全部展开

要收集其度量结果的工程的路径,指定为字符向量或字符串标量。

属性

全部展开

此 属性 为只读。

引擎收集其度量结果的工程,以字符串形式返回。

对象函数

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

示例

全部折叠

使用 metric.Engine 对象收集工程中设计工件的度量结果。

打开一个包含要分析的模型的工程。对于此示例,在 MATLAB® 命令行窗口中,输入:

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

创建一个 metric.Engine 对象。您可以使用 metric.Engine 对象来收集当前工程的度量结果。

metric_engine = metric.Engine();

通过执行度量引擎,收集度量 slcomp.OverallCyclomaticComplexity 的结果。有关该度量的详细信息,请参阅Model Maintainability Metrics

execute(metric_engine,'slcomp.OverallCyclomaticComplexity');

使用函数 getMetrics 访问结果。将结果对象数组赋值给 results 变量。

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

通过使用 results 数组中 metric.Result 对象的属性来访问度量结果数据。

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

有关如何收集设计工件度量的详细信息,请参阅Collect Model Maintainability Metrics Programmatically

使用 metric.Engine 对象收集工程中基于需求的测试工件的度量结果。

打开一个包含模型和测试工件的工程。对于此示例,在 MATLAB 命令行窗口中,输入:

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

创建一个 metric.Engine 对象。您可以使用 metric.Engine 对象来收集当前工程的度量结果。

metric_engine = metric.Engine();

更新 metric_engine 的追溯信息,确保工件信息是最新的。

updateArtifacts(metric_engine)

通过对 metric.Engine 对象使用 execute 函数,收集 'RequirementsPerTestCase' 度量的结果。

execute(metric_engine,'RequirementsPerTestCase');

使用函数 getMetrics 访问结果。将结果对象数组赋值给 results 变量。

results = getMetrics(metric_engine,'RequirementsPerTestCase');

通过使用数组中 metric.Result 对象的属性来访问度量结果数据。

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

版本历史记录

在 R2020b 中推出