モデル メトリクス データの集計
集計されたモデル メトリクス データを解析することにより、モデルおよびそのコンポーネントのサイズ、複雑度、可読性をよりよく理解できます。集計されたメトリクス データは、slmetric.metric.Result
オブジェクトの AggregatedValue
プロパティと AggregatedMeasures
プロパティにあります。AggregatedValue
プロパティはメトリクスのスカラー値を集計します。AggregatedMeasures
プロパティはメトリクス測定内容 (つまり、メトリクス値に関する詳細情報) を集計します。
モデル メトリクスの集計方法
モデル メトリクスの実装によって、メトリクスがコンポーネント階層全体でデータを集計する方法が定義されます。MathWorks のモデル メトリクスでは、slmetric.metric.Metric
クラスがモデル メトリクスの集計を定義します。このクラスには AggregationMode
プロパティが含まれ、このプロパティには次のオプションがあります。
Sum
:コンポーネント階層全体での、Value
プロパティとその子コンポーネントのValue
プロパティの合計を返します。コンポーネント階層全体での、Meaures
プロパティとその子コンポーネントのMeasures
プロパティの合計を返します。Max
:コンポーネント階層全体での、Value
プロパティとその子コンポーネントのValue
プロパティの最大値を返します。コンポーネント階層全体での、Measures
プロパティとその子コンポーネントのMeasures
プロパティの最大値を返します。None
:メトリクス値の集計はありません。
MathWorks のモデル メトリクスとその AggregationMode
プロパティの設定についての説明は、モデル メトリクスに記載されています。カスタム メトリクスの場合は、algorithm
メソッドの一部として、メトリクスによるデータの集計方法を定義できます。詳細については、非バーチャル ブロックをカウントするカスタム モデル メトリクスの作成を参照してください。
次の図に、モデルの階層構造にある複数のコンポーネントにわたってソフトウェアがメトリクス データを集計する方法を示します。親モデルが階層の最上位にあります。コンポーネントは以下の可能性があります。
モデル
Subsystem ブロック
チャート
MATLAB Function ブロック
保護モデル
この図では、AggregationMode
は Sum
であり、モデルと階層内のコンポーネントのそれぞれに Value
と AggregatedValue
があります。親モデルまたは親コンポーネントの AggregatedValue
は、その Value
と直接の子である各コンポーネントの AggregatedValue
の合計です。たとえば、この図では、親モデルの AggregatedValue
は 75
です。親モデルの AggregatedValue
は、親モデルの Value
の値 6
に直接の子である各コンポーネントの AggregatedValue
の値 33
、17
、19
を加えた合計として計算されます。
集計されたメトリクス データへのアクセス
この例では、メトリクス エンジンでプログラムによってメトリクス データを収集し、集計されたメトリクス データにアクセスする方法を説明します。
sldemo_auto_climatecontrol
モデルを読み込みます。openExample('sldemo_auto_climatecontrol')
slmetric.Engine
オブジェクトを作成し、解析ルートを設定します。metric_engine = slmetric.Engine(); setAnalysisRoot(metric_engine,'Root',... 'sldemo_auto_climatecontrol','RootType','Model');
モデルの入出力メトリクス データを収集します。
execute(metric_engine,'mathworks.metrics.IOCount');
モデル メトリクス データを取得して、
slmetric.metric.ResultCollection
オブジェクトの配列res_col
を返します。入力引数AggregationDepth
を指定します。res_col = getMetrics(metric_engine,'mathworks.metrics.IOCount',... 'AggregationDepth','All');
入力引数
AggregationDepth
には、All
とNone
の 2 つのオプションがあります。getMetrics
メソッドで測定内容および値を集計しない場合は、None
を指定します。結果を表示します。
metricData ={'MetricID','ComponentPath','Value',... 'AggregatedValue','Measures','AggregatedMeasures'}; cnt = 1; for n=1:length(res_col) if res_col(n).Status == 0 results = res_col(n).Results; for m=1:length(results) disp(['MetricID: ',results(m).MetricID]); disp([' ComponentPath: ',results(m).ComponentPath]); disp([' Value: ',num2str(results(m).Value)]); disp([' Aggregated Value: ',num2str(results(m).AggregatedValue)]); disp([' Measures: ',num2str(results(m).Measures)]); disp([' Aggregated Measures: ',... num2str(results(m).AggregatedMeasures)]); metricData{cnt+1,1} = results(m).MetricID; metricData{cnt+1,2} = results(m).ComponentPath; metricData{cnt+1,3} = results(m).Value; tdmetricData{cnt+1,4} = results(m).Measures; metricData{cnt+1,5} = results(m).AggregatedMeasures; cnt = cnt + 1; end else disp(['No results for:',res_col(n).MetricID]); end disp(' '); end
結果は次のようになります。
MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol Value: 0 Aggregated Value: 9 Measures: 0 0 0 0 Aggregated Measures: 5 4 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/AC Control Value: 6 Aggregated Value: 6 Measures: 5 1 0 0 Aggregated Measures: 5 1 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/External Temperature in Celsius Value: 1 Aggregated Value: 1 Measures: 0 1 0 0 Aggregated Measures: 0 1 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/Heat from occupants Value: 1 Aggregated Value: 1 Measures: 0 1 0 0 Aggregated Measures: 0 1 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/Heater Control Value: 8 Aggregated Value: 8 Measures: 5 3 0 0 Aggregated Measures: 5 3 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/Interior Dynamics Value: 3 Aggregated Value: 3 Measures: 2 1 0 0 Aggregated Measures: 2 1 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/More Info Value: 0 Aggregated Value: 0 Measures: 0 0 0 0 Aggregated Measures: 0 0 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/Subsystem Value: 2 Aggregated Value: 2 Measures: 1 1 0 0 Aggregated Measures: 1 1 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/Subsystem1 Value: 2 Aggregated Value: 2 Measures: 1 1 0 0 Aggregated Measures: 1 1 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/Temperature Control Chart Value: 9 Aggregated Value: 9 Measures: 5 4 0 0 Aggregated Measures: 5 4 0 0 MetricID: mathworks.metrics.IOCount ComponentPath: sldemo_auto_climatecontrol/User Setpoint in Celsius Value: 1 Aggregated Value: 1 Measures: 0 1 0 0 Aggregated Measures: 0 1 0 0
入出力メトリクスの場合、AggregationMode
は Max
です。各コンポーネントの AggregatedValue
プロパティと AggregatedMeasures
プロパティは、コンポーネント自体およびその子コンポーネントの最大入出力数です。たとえば、sldemo_auto_climatecontrol
の AggregatedValue
プロパティは 9
であり、これは sldemo_auto_climatecontrol/Temperature Control Chart
コンポーネントの値です。
参考
slmetric.metric.Metric
| slmetric.Engine
| slmetric.metric.Result
| slmetric.metric.ResultCollection