Main Content

execute

クラス: slmetric.Engine
名前空間: slmetric

(削除予定) メトリクス データを収集する

メトリクス ダッシュボード ユーザー インターフェイス、関数 metricdashboardslmetric パッケージ API、および対応するカスタマイズは将来のリリースで削除される予定です。詳細については、Migrating from Metrics Dashboard to Model Maintainability Dashboardを参照してください。

説明

指定したメトリクス エンジン オブジェクトに対してモデル メトリクス データを収集します。モデル メトリクス データは、定義されているアーキテクチャ コンポーネントに基づきます。コンポーネントは以下の Simulink オブジェクトです。

  • モデル

  • Subsystem ブロック

  • チャート

  • MATLAB Function ブロック

  • 保護モデル

execute(metric_engine) は、使用可能なモデル メトリクスのメトリクス データを収集します。これには、MathWorks メトリクスおよびカスタム メトリクスが含まれる可能性があります。

execute(slmetric_obj,MetricIDs) は、指定したメトリクスのみのメトリクス データを収集します。MathWorks メトリクスまたはカスタム メトリクスを指定できます。

入力引数

すべて展開する

slmetric.Engine オブジェクトを作成します。

metric_engine = slmetric.Engine();

モデル メトリクスまたは作成したカスタム モデル メトリクスのメトリクス識別子。1 つ以上のメトリクス識別子を指定できます。slmetric.metric.getAvailableMetricsを呼び出してメトリクス識別子を取得できます。

例: 'mathworks.metrics.DescriptiveBlockNames'

すべて展開する

モデル sldemo_mdlref_basic のモデル メトリクス データを収集してそのデータにアクセスします。

モデルを開きます。

openExample('sldemo_mdlref_basic'); 

slmetric.Engine オブジェクトを作成し、解析用にモデル内のルートを設定します。

metric_engine = slmetric.Engine();

% Include referenced models and libraries in the analysis.
% These properties are on by default.
metric_engine.ModelReferencesSimulationMode = 'AllModes';
metric_engine.AnalyzeLibraries = 1;

setAnalysisRoot(metric_engine, 'Root',  'sldemo_mdlref_basic');

モデル メトリクス データの収集

execute(metric_engine);

モデル メトリクス データを取得して、slmetric.metric.ResultCollection オブジェクトの配列 res_col を返します。

res_col = getMetrics(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

mathworks.metrics.SimulinkBlockCount メトリクスの結果を表示します。

for n=1:length(res_col)
    if res_col(n).Status == 0
        result = res_col(n).Results;
        
        for m=1:length(result)
            disp(['MetricID: ',result(m).MetricID]);
            disp(['  ComponentPath: ', result(m).ComponentPath]);
            disp(['  Value: ', num2str(result(m).Value)]);
            disp(['  AggregatedValue: ', num2str(result(m).AggregatedValue)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end

モデル sldemo_mdlref_basic のモデル メトリクス データを収集してそのデータにアクセスします。

モデルを開きます。

openExample('sldemo_mdlref_basic'); 

slmetric.Engine オブジェクトを作成します。参照モデルおよびライブラリを解析に含め、解析用にモデル内のルートを設定します。

metric_engine = slmetric.Engine();
metric_engine.ModelReferencesSimulationMode = 'AllModes';
metric_engine.AnalyzeLibraries = 1;
setAnalysisRoot(metric_engine, 'Root',  'sldemo_mdlref_basic');

モデル メトリクス データの収集

execute(metric_engine, 'mathworks.metrics.ExplicitIOCount');

モデル メトリクス データを取得して、slmetric.metric.ResultCollection オブジェクトの配列 res_col を返します。

res_col = getMetrics(metric_engine, 'mathworks.metrics.ExplicitIOCount');

mathworks.metrics.ExplicitIOCount メトリクスの結果を表示します。

for n=1:length(res_col)
    if res_col(n).Status == 0
        result = res_col(n).Results;
        
        for m=1:length(result)
            disp(['MetricID: ',result(m).MetricID]);
            disp(['  ComponentPath: ', result(m).ComponentPath]);
            disp(['  Value: ', num2str(result(m).Value)]);
            disp(['  AggregatedValue: ', num2str(result(m).AggregatedValue)]);
            disp(['  Measures: ', num2str(result(m).Measures)]);
            disp(['  AggregatedMeasures: ', num2str(result(m).AggregatedMeasures)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end

結果は次のようになります。

MetricID: mathworks.metrics.ExplicitIOCount
  ComponentPath: sldemo_mdlref_basic
  Value: 3
  AggregatedValue: 4
  Measures: 0  3
  AggregatedMeasures: 3  3
MetricID: mathworks.metrics.ExplicitIOCount
  ComponentPath: sldemo_mdlref_basic/More Info
  Value: 0
  AggregatedValue: 0
  Measures: 0  0
  AggregatedMeasures: 0  0
MetricID: mathworks.metrics.ExplicitIOCount
  ComponentPath: sldemo_mdlref_counter
  Value: 4
  AggregatedValue: 4
  Measures: 3  1
  AggregatedMeasures: 3  1

ComponentPath: sldemo_mdlref_basic では、出力が 3 つあるため、値は 3 です。3 つの出力は、配列 Measures の 2 番目の要素に入ります。slmetric.metric.AggregationModeMax であるため、AggregatedValue は、sldemo_mdlref_counter への入出力の数である 4 です。配列 AggregratedMeasures には、コンポーネントまたはサブコンポーネントの入力および出力の最大数が含まれます。

バージョン履歴

R2016a で導入

すべて展開する