exponenta event banner

setGroup

Класс: slmetric.metric.ResultDetail
Пакет: slmetric.metric

Установка имени и идентификатора для группы slmetric.metric.ResultDetail объекты

Описание

Для пользовательской метрики задайте идентификатор и имя для группы slmetric.metric.ResultDetail объекты. Применить этот метод из части алгоритма метрики, которая задает сведения для getMetrics объекты.

пример

setGroup(groupIdentifier,groupName) устанавливает значения имени и идентификатора группы для slmetric.metric.ResultDetail объект.

Входные аргументы

развернуть все

Укажите значение идентификатора для группы slmetric.metric.ResultDetail объекты.

Укажите значение для имени группы slmetric.metric.ResultDetail объекты.

Примеры

развернуть все

Используйте setGroup способ группирования подробных результатов. При создании пользовательской метрики модели этот метод применяется как часть algorithm способ.

Использование createNewMetricClass функция, создайте метрический класс с именем DataStoreCount. Эта метрика подсчитывает количество блоков чтения хранилища данных и записи хранилища данных и группирует их с помощью соответствующего блока памяти хранилища данных. createNewMetricClass функция создает файл DataStoreCount.m в текущей рабочей папке. Файл содержит конструктор и метод алгоритма пустой метрики. В этом примере убедитесь, что вы работаете в папке с возможностью записи.

className = 'DataStoreCount';
slmetric.metric.createNewMetricClass(className);

Чтобы записать алгоритм метрики, откройте DataStoreCount.m и добавьте метрику в файл. Для этого примера можно создать алгоритм метрики, скопировав эту логику в DataStoreCount.m файл.

classdef DataStoreCount < slmetric.metric.Metric
    % Count the number of Data Store Read and Data Store Write
    % blocks and correlate them across components.
    
    methods
        function this = DataStoreCount()
            this.ID = 'DataStoreCount';
            this.ComponentScope = [Advisor.component.Types.Model, ...
                Advisor.component.Types.SubSystem];
            this.AggregationMode = slmetric.AggregationMode.Sum;
            this.CompileContext = 'None';
            this.Version = 1;
            this.SupportsResultDetails = true;
            
            %Textual information on the metric algorithm
            this.Name = 'Data store usage';
            this.Description = 'Metric that counts the number of Data Store Read and Write'; 
                  'blocks and groups them by the corresponding Data Store Memory block.';
            
        end
        
        function res = algorithm(this, component)
            % Use find_system to get all blocks inside this component.
            dswBlocks = find_system(getPath(component), ...
                'SearchDepth', 1, ...
                'BlockType', 'DataStoreWrite');
            dsrBlocks = find_system(getPath(component), ...
                'SearchDepth', 1, ...
                'BlockType', 'DataStoreRead');          
            
            % Create a ResultDetail object for each data store read and write block.
			% Group ResultDetails by the data store name.
            details1 = slmetric.metric.ResultDetail.empty();
            for i=1:length(dswBlocks)
                details1(i) = slmetric.metric.ResultDetail(getfullname(dswBlocks{i}),...
                            get_param(dswBlocks{i}, 'Name'));
		   groupID = get_param(dswBlocks{i},'DataStoreName');
		   groupName = get_param(dswBlocks{i},'DataStoreName');
                details1(i).setGroup(groupID, groupName);                
                details1(i).Value = 1;
            end
            
            details2 = slmetric.metric.ResultDetail.empty();
            for i=1:length(dsrBlocks)
                details2(i) = slmetric.metric.ResultDetail(getfullname(dsrBlocks{i}),...
                   get_param(dsrBlocks{i}, 'Name'));
                groupID = get_param(dsrBlocks{i},'DataStoreName');
				groupName = get_param(dsrBlocks{i},'DataStoreName');
                details2(i).setGroup(groupID, groupName);
                details2(i).Value = 1;
            end
            
            res = slmetric.metric.Result();
            res.ComponentID = component.ID;
            res.MetricID = this.ID;
            res.Value = length(dswBlocks)+ length(dsrBlocks);
            res.Details = [details1 details2];
        end
    end
end

В DataStoreCount метрический класс, SupportsResultDetail метод имеет значение true. Алгоритм метрики содержит логику для setGroup способ.

Теперь, когда новая метрика модели определена в DataStoreCount.m, зарегистрируйте новую метрику.

[id_metric,err_msg] = slmetric.metric.registerMetric(className);

Для сбора метрических данных о моделях используйте экземпляры slmetric.Engine. Использование getMetrics укажите метрику, которую требуется собрать. В этом примере укажите метрику количества хранилищ данных для sldemo_mdlref_dsm модель.

Загрузить sldemo_mdlref_dsm модель.

model = 'sldemo_mdlref_dsm';
load_system(model);

Создайте объект метрического механизма и задайте корень анализа..

metric_engine = slmetric.Engine();
setAnalysisRoot(metric_engine,'Root',model,'RootType','Model');

Сбор метрических данных для метрики счетчика хранилища данных.

execute(metric_engine);
rc=getMetrics(metric_engine, id_metric);

Для каждого slmetric.metric.Result объект, отображение ComponentPath. Для каждого slmetric.metric.ResultDetails отображение имени и идентификатора группы хранилища данных.

for n=1:length(rc.Results)
    if rc.Results(n).Value > 0
	for m=1:length(rc.Results(n).Details)
	  disp(['ComponentPath: ',rc.Results(n).ComponentPath]);
          disp(['Group Name: ',rc.Results(n).Details(m).getGroupName]);
          disp(['Group Identifier: ',rc.Results(n).Details(m).getGroupIdentifier]);
        end
    else
        disp(['No results for ComponentPath: ',rc.Results(n).ComponentPath]);
    end
    disp(' ');
end

Вот результаты.

ComponentPath: sldemo_mdlref_dsm
Group Name: ErrorCond
Group Identifier: ErrorCond
 
No results for ComponentPath: sldemo_mdlref_dsm/More Info1
 
ComponentPath: sldemo_mdlref_dsm_bot
Group Name: RefSignalVal
Group Identifier: RefSignalVal
 
ComponentPath: sldemo_mdlref_dsm_bot2
Group Name: ErrorCond
Group Identifier: ErrorCond
 
ComponentPath: sldemo_mdlref_dsm_bot/PositiveSS
Group Name: RefSignalVal
Group Identifier: RefSignalVal
 
ComponentPath: sldemo_mdlref_dsm_bot/NegativeSS
Group Name: RefSignalVal
Group Identifier: RefSignalVal

В этом примере отмените регистрацию метрики счетчика хранилища данных.

slmetric.metric.unregisterMetric(id_metric);

Закройте модель.

clear;
bdclose('all');
Представлен в R2017b