主要内容

metric.Engine

R2026b

收集度量结果

描述

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

创建对象

描述

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

示例

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

示例

输入参量

全部展开

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

属性

全部展开

此 属性 为只读。

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

对象函数

deleteAllMetricsDelete all metric results
deleteMetricsDelete specific metric results
executeCollect metric results
executeDashboardMetricsCollect metrics for specific dashboard
generateReportGenerate report file containing metric results
getArtifactErrorsView errors from artifact analysis
getArtifactIssuesView issues from artifact analysis
getAvailableMetricIdsReturn metric identifiers for available metrics
getMetricsAccess metric results
getThresholdSetsGet available threshold sets for project
openArtifact从度量结果打开追溯的工件
updateArtifactsUpdate trace information for pending artifact changes in the project

示例

全部折叠

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

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

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

创建一个 metric.Engine 对象。要收集当前工程的度量结果,请使用 metric.Engine 对象。

metricEngine = metric.Engine();

要收集模型设计度量的结果,请执行度量引擎。execute 函数会返回已收集的结果。有关模型设计度量的详细信息,请参阅Model Design Metrics和Model Maintainability Metrics。

results = execute(metricEngine,"sldesignlayer.SimulinkDesignInfo")
results =

  1x45 Result array with properties:

    UserData
    Value
    MetricID
    Artifacts
    ScopeId
    ScopeAlias
    ThresholdOutcomes
    Diagnostics

要访问度量结果数据,请使用 results 数组中 metric.Result 对象的属性。对于此度量,Value 属性是一个结构体,包含模型中每个组件的设计信息。

v = results(1).Value
v =

  struct with fields:

            Blocks: 7
         Decisions: 4
             Gotos: 0
    InterfacePorts: [1x1 struct]
       SignalLines: 18
          Halstead: [1x1 struct]
v.InterfacePorts
ans =

  struct with fields:

     In: 3
    Out: 1
v.Halstead
ans =

  struct with fields:

     TotalOperators: 11
    UniqueOperators: 7
      TotalOperands: 15
     UniqueOperands: 12
             Volume: 110.4461
         Difficulty: 4.3750

通过基于结果构建表格,显示跨所有模型层的特定设计信息。

modelLayers = [results.ScopeAlias].';
values = [results.Value].';
signalLines = [values.SignalLines].';
T = table(modelLayers,signalLines,VariableNames=["Model Layer","Signal Lines"])
T =

  45×2 table

                 Model Layer                 Signal Lines
    _____________________________________    ____________

    "Target_Speed_Calculator"                     18     
    "Switch Case Action↵Subsystem3"                1     
    "Transitions_From_THROTTLE_OVERRIDE"          14   
    ...

要在执行后访问已收集的结果或这些结果的子集,请使用 getMetrics。

results = getMetrics(metricEngine,"sldesignlayer.SimulinkDesignInfo");

模型设计度量提供有关模型的简要设计信息。模型可维护性度量提供更详细的度量结果。有关如何收集设计工件度量的详细信息,请参阅Collect Model Maintainability Metrics Programmatically。

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

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

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

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

metricEngine = metric.Engine();

通过执行度量引擎,收集模型测试度量的结果。execute 函数会返回已收集的结果。

results = execute(metricEngine,"modeltesting.TestAnalysis[]")
results =

  1x44 Result array with properties:

    UserData
    Value
    MetricID
    Artifacts
    ScopeId
    ScopeAlias
    ThresholdOutcomes
    Diagnostics

使用 getMetrics 访问所收集结果的一个子集。例如,仅获取每个测试的需求比例的结果。

reqsPerTest = getMetrics(metricEngine,"modeltesting.TestAnalysis[slcomp.RequirementsPerTestRatio]")
reqsPerTest =

  1x4 Result array with properties:

    UserData
    Value
    MetricID
    Artifacts
    ScopeId
    ScopeAlias
    ThresholdOutcomes
    Diagnostics

通过使用数组中 metric.Result 对象的属性来访问度量结果数据。对于此度量,Value 属性是一个结构体,包含总需求数、已链接需求数和未链接需求数。

reqsPerTest(1).Value
ans =

  struct with fields:

       Total: 37
      Linked: 37
    Unlinked: 0
reqsPerTest(1).ScopeAlias
ans =

    "cc_ControlMode"

显示工程中每个单元模型的每个测试的需求比例。

models = [reqsPerTest.ScopeAlias].';
values = [reqsPerTest.Value].';
total = [values.Total].';
linked = [values.Linked].';
unlinked = [values.Unlinked].';
T = table(models,total,linked,unlinked,VariableNames=["Model","Total","Linked","Unlinked"])
T =

  4x4 table

           Model              Total    Linked    Unlinked
    ____________________      _____    ______    ________

    "cc_ControlMode"           37        37         0
    "cc_LightControl"           5         5         0
    "cc_DriverSwRequest"       10        10         0
    "cc_ThrottleController"     0         0         0

有关如何收集测试工件度量的详细信息,请参阅以编程方式收集模型测试工件的度量。

版本历史记录

在 R2020b 中推出