getGroupName
Class: slmetric.metric.ResultDetail
Namespace: slmetric.metric
(To be removed) Obtain name for a group of
slmetric.metric.ResultDetail
objects
The Metrics Dashboard user interface, metricdashboard
function, slmetric
package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.
Description
Obtain the name of a group of slmetric.metric.ResultDetail
objects.
Calling the execute
method collects metric data. Calling getMetrics
accesses the slmetric.metric.Result
objects which include the slmetric.metric.ResultDetail
objects. Apply
the getGroupName
method to the
slmetric.metric.ResultDetail
object.
Input Arguments
mrd
— slmetric.metric.ResultDetail
object
character vector
Calling the slmetric.Engine.execute
method creates the
slmetric.metric.Result
objects, which include the
slmetric.metric.ResultDetail
objects.
Output Arguments
groupName
— Group name
character vector
Name for a group of slmetric.metric.ResultDetail
objects
Examples
Obtain Clone Group Names and Identifiers
Use the getGroupName
and
getGroupIdentifier
methods to obtain the name and
identifier for a group of clones.
Open the example model ex_clone_detection.slx
and save
the model to your current working folder.
openExample('slcheck/EnableSubsystemReuseWithCloneExample','supportingfile','ex_clone_detection');
Call the execute
method. Apply the getMetrics
method for the
mathworks.metric.CloneDetection
metrics.
metric_engine = slmetric.Engine(); setAnalysisRoot(metric_engine,'Root','ex_clone_detection','RootType','Model'); execute(metric_engine); rc = getMetrics(metric_engine,'mathworks.metrics.CloneDetection');
For each slmetric.metric.Result
object, display the
ComponentPath
. For each
slmetric.metric.ResultDetail
object, display the
clone group name and identifier.
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
The results show that the model contains one clone group,
CloneGroup1
, which contains two clones.
Set Group Names and Group Identifiers for a Custom Model Metric
Use the setGroup
method to group detailed
results. When you create a custom model metric, you apply this method as part of
the algorithm
method.
Open the sldemo_mdlref_dsm
model.
openExample('sldemo_mdlref_dsm');
Using the createNewMetricClass
function, create a
metric class named DataStoreCount
. This metric counts the
number of Data Store Read and Data Store Write
blocks and groups them together by the corresponding Data Store Memory
block. The createNewMetricClass
function creates a file,
DataStoreCount.m
, in the current working folder. The
file contains a constructor and empty metric algorithm method. For this
example, make sure that you are working in a writable folder.
className = 'DataStoreCount';
slmetric.metric.createNewMetricClass(className);
To write the metric algorithm, open the
DataStoreCount.m
file and add the metric to the file.
For this example, you can create the metric algorithm by copying this logic
into the DataStoreCount.m
file.
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
In the DataStoreCount
metric class, the
SupportsResultDetail
method is set to true. The
metric algorithm contains the logic for the setGroup
method.
Now that your new model metric is defined in
DataStoreCount.m
, register the new
metric.
[id_metric,err_msg] = slmetric.metric.registerMetric(className);
To collect metric data on models, use instances of
slmetric.Engine
. Using the
getMetrics
method, specify the metric that you want
to collect. For this example, specify the data store count metric for
thesldemo_mdlref_dsm
model.
Load the sldemo_mdlref_dsm
model.
model = 'sldemo_mdlref_dsm';
load_system(model);
Create a metric engine object and set the analysis root.
metric_engine = slmetric.Engine(); setAnalysisRoot(metric_engine,'Root',model,'RootType','Model');
Collect metric data for the Data Store Count metric.
execute(metric_engine); rc=getMetrics(metric_engine, id_metric);
For each slmetric.metric.Result
object, display the
ComponentPath
. For each
slmetric.metric.ResultDetails
object, display the
Data Store group name and identifier.
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
Here are the results.
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
For this example, unregister the data store count metric.
slmetric.metric.unregisterMetric(id_metric);
Close the model.
bdclose(model);
Version History
Introduced in R2017bR2022a: Metrics Dashboard will be removed
The Metrics Dashboard user interface, metricdashboard
function, slmetric
package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)