对于非虚块计数创建一个自定义模式公制

这个例子说明了如何使用模型度量API来创建自定义模型度量模型中的计数非虚块。创建度量标准后,您可以为度量标准,获得的结果收集数据,并输出结果。

创建度量类

要创建自定义模型指标,使用slmetric.metric.createNewMetricClass函数来创建从基类派生的新度量类slmetric.metric.Metric。该slmetric.metric.createNewMetricClass函数创建一个包含一个构造函数和一个空的度量方法,算法文件。

1.在这个例子中,请确保你在一个可写文件夹,并新建一个名为指标类nonvirtualblockcount

的className ='nonvirtualblockcount';slmetric.metric.createNewMetricClass(类名);

2.写度量算法进slmetric.metric.Metric方法,算法。该算法计算由指定的度量数据Advisor.component.Component类。该Advisor.component.Types类指定类型,您可根据度量数据模型对象。在这个例子中,该文件nonvirtualblockcount_orig.m包含创建度量计数的非虚块的逻辑。将此文件复制到该nonvirtualblockcount.m文件。

拷贝文件nonvirtualblockcount_orig.mnonvirtualblockcount.mF

在创建自定义指标,您必须设置slmetric.metric.Metric类的以下特性:

  • ID:独特的度量标识符检索新的度量数据。

  • 名称:十进制算法的名称。

  • ComponentScope:模型组件的量,度量计算。

  • CompileContext:编译模式度量计算。如果您的模型需要的模型编译,指定PostCompile。收集度量数据的编制模式会降低性能。

  • ResultCheckSumCoverage:指定是否要度量数据再生,如果源文件和没有改变。

  • AggregationMode:如何度量算法聚合度量数据

或者,您可以设置这些附加属性:

  • 描述:度量的说明。

  • :公制。

3.现在你的新模式度量在nonvirtualblockcount.m定义,你可以注册在度量存储库中的新指标。

[id_metric,ERR_MSG] = slmetric.metric.registerMetric(类名);

收集度量数据

收集模型度量数据,使用实例slmetric.Engine。使用getMetrics方法,指定要收集的度量标准。在这个例子中,指定非虚块计数度量的sldemo_mdlref_bus模型。

1.装入sldemo_mdlref_bus模型。

模型='sldemo_mdlref_bus';load_system(模型);

2.创建度量引擎对象,并设置分析根。

metric_engine = slmetric.Engine();setAnalysisRoot(metric_engine,'根',模型,'RootType''模型');

对于非虚块3.收集度量数据计数度量。

执行(metric_engine);RC = getMetrics(metric_engine,id_metric);

显示和导出结果

要访问度量模型,使用实例slmetric.metric.Result。在这个例子中,显示用于sldemo_mdlref_bus模型的非虚块计数度量。对于每一个结果,显示MetricID,ComponentPath,和价值。

对于N = 1:长度(RC)如果RC(n)的.STATUS == 0结果= RC(n)的。结果;对于m = 1时:长度(结果)DISP(['MetricID:',结果(米).MetricID]);DISP(['ComponentPath:',结果(米).ComponentPath]);DISP([“值:”,num2str(结果(米)。价值)]);DISP(“”);结束其他DISP([“无结果”,RC(n)的.MetricID]);结束DISP(“”);结束
MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_bus值:13 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_bus /更多INFO3数值:0 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_bus /更多信息4值:0 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_bus /更多信息1数值:0 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_bus /更多信息2值:0 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus值:2 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器值:6 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器/计数器值:3 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器/计数器/ ResetCheck值:4 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器/计数器/ ResetCheck / NORESET值:2 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器/计数器/ ResetCheck /复位值:3 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器/计数器/ SaturationCheck值:5 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /计数器/ LimitsProcess值:1 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus /更多信息1数值:0 MetricID:nonvirtualblockcount ComponentPath:sldemo_mdlref_counter_bus/更多信息2值:0

为了度量结果导出到一个XML文件,使用exportMetrics方法。对于每个度量结果,XML文件包括的ComponentIDComponentPathMetricIDAggregatedValue测量

文件名='MyMetricData.xml';exportMetrics(metric_engine,文件名);

对于这个例子,注销非虚块计数度量。

slmetric.metric.unregisterMetric(id_metric);

关闭模型。

明确;bdclose('所有');

限制

自定义指标的算法不支持组件对象的路径属性:万博1manbetx

  • 链接Stateflow图

  • MATLAB功能块

自定义指标的算法不遵守图书馆的链接。

版权所有2019 MathWorks公司

也可以看看

|||||

相关话题