Main Content

socFunctionAnalyzer

Estimate number of operations in MATLAB function

Since R2020a

Description

socFunctionAnalyzer(functionName) generates a report with the estimated number of operations in the MATLAB® function specified by functionName.

The function generates the report as a Microsoft® Excel® spreadsheet and a MAT-file. The function also provides a link to view the report in a separate dialog box.

The report includes information for each mathematical or logical operator in the function, with individual lines for each operator and data type. For example, multiplication with data type double and multiplication with data type uint32 are listed separately. The report lists each instance of the operator as a separate line. The report includes these fields.

  • Path – The path to the operator within the structural hierarchy of the top function

  • Count – The number of times the operator is executed in the design

  • Operator – The operator used

  • DataType – The data type used for the output of the operator

  • Link – A link to the location of the operator in the function

For more information, see Using the Algorithm Analyzer Report.

example

socFunctionAnalyzer(functionName,Name=Value) specifies options using one or more name-value arguments. For example, IncludeOperator='+' specifies that the generated report only includes '+' operator counts.

example

report = socFunctionAnalyzer(___) returns a structure of tables that contain report information. Specify any of the input argument combinations from previous syntaxes.

example

[report,y1,...,yn] = socFunctionAnalyzer(___) returns the outputs y1,...,yn of the specified function. Specify any of the input argument combinations from previous syntaxes.

example

Examples

collapse all

This example calculates the number of dynamic operations and static operators in the function soc_test_func.m.

Generate Dynamic Report

soc_test_func takes two input arguments of type uint32. Use the FunctionInputs argument to create a report with 10 and 20 as inputs to the soc_test_func function. The dynamic report is generated in a folder named report.

socFunctionAnalyzer('soc_test_func.m',FunctionInputs={10,20},Folder='report');

View Generated Report

After execution, the socFunctionAnalyzer function provides a link to the generated report. Click the link titled Open report viewer. The report opens in a separate window:

The result shows that the ADD operator is used 50 times with data type double. The call to myloop executes once with data type uint32, and the MUL operator is used 50 times with data type uint32.

Generate Static Report

To statically calculate the number of operators in the function (and not the number of operations performed during simulation), use the AnalysisMethod name-value pair argument.

socFunctionAnalyzer('soc_test_func.m',AnalysisMethod='static',FunctionInputs={10,20},Folder='report');

To view the static analysis report, click the link titled Open report viewer. The report opens in a separate window:

Input Arguments

collapse all

MATLAB function to analyze, specified as a character vector or string scalar that indicates the function name or file name.

Example: 'soc_analyze_FFT_tb.m'

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: socFunctionAnalyzer('mySocFunction.m','Folder'='report_sym')

Option for static of dynamic analysis, specified as 'static' or 'dynamic'. This value specifies the method that the function uses to analyze the MATLAB function.

  • 'dynamic' – Dynamic analysis provides the number of operations that the function executes during a given simulation time.

  • 'static' – Static analysis provides the number of operators in an algorithm.

Inputs for the function to be analyzed, specified as a cell array. The socFunctionAnalyzer function evaluates the function to be analyzed, functionName, with these specified values as inputs. If you do not specify this name-value argument, then socFunctionAnalyzer passes no arguments to functionName.

If functionName expects input arguments, then you must specify this name-value pair argument. Otherwise, the socFunctionAnalyzer function errors.

Example: FunctionInputs={10,fi(20)}

Folder location of generated report, specified as a character vector or string scalar indicating the folder path. Specify the path to the location for the generated output reports as a full path or relative path.

Example: Folder='C:/Work/mydir'

Operators to include in the generated report , specified as a character vector or string scalar to specify one operator. Use cell array of character vectors or string scalars to specify multiple operators. When you do not specify this name-value pair argument, the socFunctionAnalyzer function includes all operators, except for the operators specified by the ExcludeOperator name-value pair argument.

Example: IncludeOperator='+'

Example: IncludeOperator={'+','IF','MUL'}

Operators to exclude from the generated report, specified as a character vector or string scalar to specify one operator. Use cell array of character vectors or string scalars to specify multiple operators. When you do not specify this name-value pair argument, the socFunctionAnalyzer function includes all operators in the report.

Example: ExcludeOperator='-'

Example: ExcludeOperator={'-','CALL'}

Functions to include in generated report, specified as a character vector or string scalar to specify one function or file name. Use cell array of character vectors or string scalars to specify multiple functions or file names. If you do not specify this name-value pair argument, the socFunctionAnalyzer function includes all functions in the report, except for the functions specified by the 'ExcludeFunction' name-value pair argument. Use the 'IncludeFunction' name-value pair when you have a testbench function, and you only want to analyze one of the functions it calls.

Example: IncludeFunction='myFunc.m'

Example: IncludeFunction={'myFunc.m','func2'}

Functions to include in generated report, specified as a character vector or string scalar to specify one function or file name. Use cell array of character vectors or string scalars to specify multiple functions or file names. If you do not specify this name-value pair argument, the socFunctionAnalyzer function includes all functions in the report.

Example: ExcludeFunction='myFunc.m'

Example: ExcludeFunction={'myFunc.m','func2'}

Display verbose messages, specified as on, off, or quiet. When you set Verbose to:

  • on — the function displays detailed messages during the different stages of execution.

  • off — the function displays messages during the first and last stages of execution.

  • quiet — the function does not display messages about execution. Select this option if you want to silence all messages.

Example: Verbose='on'

Output Arguments

collapse all

Function operator count, returned as a structure of five tables:

  • OperatorDetailedReport – A fully detailed report per operator

  • OperatorAggregatedReport – An aggregated operator view, with one line for each type of operator

  • OperatorHierarchicalReport – A hierarchical operator view

  • PathAggregatedReport – An aggregated model view

  • PathHierarchicalReport – A Hierarchical model view

Each table contains raw data from which the function generates an HTML view, and a link to view the data in a report window. The generated Excel file has five sheets, containing the information from the five tables. For more information about the generated report, see Using the Algorithm Analyzer Report.

Analyzed function output, returned as an output the functionName input function.

Version History

Introduced in R2020a

expand all