socFunctionAnalyzer

Estimate number of operations in MATLAB function

Description

example

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 pair 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.

Examples

collapse all

This example calculates the number of operators in the function soc_test_func.m.

Analyze Function

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 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.

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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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

Inputs for the function to be analyzed, specified as the comma-separated pair consisting of 'FunctionInputs' and a cell array. The socFunctionAnalyzer function evaluates the function to be analyzed, functionName, with these values as inputs. If you do not specify this name-value pair argument, then no arguments are passed 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 the comma-separated pair consisting of 'Folder' and 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 the comma-separated pair consisting of 'IncludeOperator' and 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 the comma-separated pair consisting of 'ExcludeOperator' and 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 the comma-separated pair consisting of 'IncludeFunction' and 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 test bench 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 the comma-separated pair consisting of 'ExcludeFunction' and 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 the comma-separated pair consisting of 'Verbose' and 0 (false) or 1 (true). When this value is 1 (true), the function displays detailed information during the different stages of execution.

Example: 'Verbose',true

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.

Introduced in R2020a