Main Content

sldiagnostics

Display diagnostic information of Simulink system

    Description

    example

    sldiagnostics(modelName) returns the diagnostic information of a Simulink® model or subsystem in the Command Window with these statistics:

    • Block Count — Names and counts of unique blocks

    • Stateflow® Count — Names and counts of unique Stateflow objects

    • Model Sizes — Counts of states, outputs, inputs, flags for direct feedthrough, and sample times

    • Library Usage Statistics — Names and counts of all the library blocks and referenced libraries

    • Compilation Statistics — Time and memory used to compile each phase

    example

    sldiagnostics(modelName,option1,...,optionN) returns the diagnostic information of a Simulink model or subsystem in the Command Window for the diagnostics listed in option1,...,optionN. For example, using the option CountBlocks lists the names and counts of unique blocks in a model or subsystem.

    example

    [txtRpt,sRpt] = sldiagnostics(___) returns the diagnostic information with any of the previous syntaxes in txtRpt as a formatted text and in sRpt as a structure array.

    Examples

    collapse all

    Generate the diagnostic information of a Simulink model or subsystem and display it in the Command Window.

    Open example BangBangControlUsingTemporalLogicExample and generate diagnostic information of the root model sf_boiler.

    openExample('stateflow/BangBangControlUsingTemporalLogicExample');
    sldiagnostics('sf_boiler')

    If you do not open or load the model, sldiagnostics loads the model and generates the diagnostic information.

    Generate specific diagnostic information of a Simulink model or subsystem and display it in the Command Window.

    Open example BangBangControlUsingTemporalLogicExample and generate diagnostic information related to the numbers of blocks and Stateflow objects in the subsystem sf_boiler/Bang-Bang Controller.

    openExample('stateflow/BangBangControlUsingTemporalLogicExample');
    sldiagnostics('sf_boiler/Bang-Bang Controller','CountBlocks','countSF')

    If you do not open or load the model, sldiagnostics loads the model and generates the diagnostic information.

    Generate diagnostic information of a model and save the results as formatted text and as a and structure array.

    Open example BangBangControlUsingTemporalLogicExample and generate the diagnostic information of the root model sf_boiler. Save these reports in myReport and strucRpt.

    openExample('stateflow/BangBangControlUsingTemporalLogicExample');
    [myReport,strucRpt] = sldiagnostics('sf_boiler');

    If you do not open or load the model, sldiagnostics loads the model and generates the diagnostic information.

    Generate time and memory used by the model to compile and use this information to evaluate the performance of a model.

    Compile Time and Memory Usage Data Collection

    Load the model vdp.

    model = 'vdp';
    load_system(model);

    Generate the compile time diagnostic information of vdp and store the results in txtRpt and strucRpt.

    [txtRpt,strucRpt] = sldiagnostics(model,'CompileStats');

    txtRpt stores the compile time and description of each phase of vdp as formatted text. sRpt stores the compile time and memory used in each phase of vdp as a structure.

    strucRpt
    strucRpt = struct with fields:
             Model: 'vdp'
        Statistics: [1×200 struct]
    
    

    The size of the strucRpt.Statistics array indicates the number of compile and build phases executed during compilation. Find the compile time and memory usage statistics for phase 20.

    strucRpt.Statistics(20)
    ans = struct with fields:
                Description: 'Finding and refreshing Model blocks'
                    CPUTime: 0
              WallClockTime: 0.0010
            ProcessMemUsage: 0.0430
        ProcessMemUsagePeak: 0
              ProcessVMSize: 0
    
    

    The reported information includes:

    CPUTime -Time in seconds the CPU takes to actively process a Simulink phase.

    WallClockTime - The real-time elapsed in seconds to complete a single phase of the Simulink process. WallClockTime is a sum of the CPUtime, input-output time, and programming delays.

    ProcessMemUsage - The working set size in megabytes used to execute a Simulink phase of operation. The working set size of a process is the amount of memory physically mapped to its process context.

    ProcessMemUsagePeak - The peak working set size in megabytes used to execute a Simulink phase of operation.

    ProcessVMSize - The amount of virtual memory or address space committed to the MATLAB™ process at the start of the phase of operation.

    Performance Analysis of a Model

    Use the following key metrics to analyze the performance of vdp:

    • Total Elapsed Time - Sum of the wall-clock time for each phase of vdp.

    • Total Memory - Sum of the memory used in each phase of vdp.

    • Peak Memory - The maximum memory used in a phase out of all phases of vdp.

    ElapsedTime = sum([strucRpt.Statistics(:).WallClockTime])
    ElapsedTime = 10.1960
    
    TotalMemory = sum([strucRpt.Statistics(:).ProcessMemUsage])
    TotalMemory = 153.1289
    
    PeakMemory = max([strucRpt.Statistics(:).ProcessMemUsagePeak])
    PeakMemory = 35.0273
    

    Considerations

    • The CompileStats diagnostic option should be used when the model is loaded for the first time. Otherwise, sldiagnostics reuses the previously compiled objects of the model and reports a lower time and memory usage for a model.

    • Memory usage statistics are available only on the Microsoft® Windows® platform.

    Input Arguments

    collapse all

    Name of a Simulink model or path to a subsystem to generate diagnostic information for, specified as a character vector or string.

    Example: 'sf_boiler', 'sf_boiler/Bang-Bang Controller'

    Data Types: char | string

    Diagnostic options that represents specific sets of diagnostic information, specified as a character vector or string. Some diagnostic options work only with root models. The table lists the diagnostic options, compatible input system types, and expected output.

    Diagnostic Option

    Input System Type

    Output

    'CountBlocks'

    root model, library, or subsystem

    Names and counts of unique blocks used in the system. This includes blocks that are nested in masked subsystems or are hidden.

    'CountSF'

    root model, library, or subsystem

    Names and counts of unique Stateflow objects used in the system.

    'Sizes'

    root model

    Counts of states, outputs, inputs, flags for direct feedthrough, and sample times used in the model.

    'Libs'

    root model, library, or subsystem

    Names and counts of all library blocks and unique libraries referenced in the system.

    'CompileStats'

    root model

    Time and memory used to compile each phase of the model. This information helps users troubleshoot model compilation speed and memory issues.

    'RTWBuildStats'

    root model

    Simulink Coder™ build statistics and all statistics returned when using the CompileStats option.

    You must explicitly specify this option, because it is not a part of the default analysis.

    'All'

    root model

    All diagnostics, including those provided by RTWBuildStats.

    sldiagnostics issues a warning when:

    • The diagnostic option and input system type are incompatible.

    • The input system type is a Simulink library. For such systems, sldiagnostics cannot generate diagnostics for options that require a model compilation, such as Update Diagram.

    Example: 'CountBlocks'

    Data Types: char | string

    Output Arguments

    collapse all

    Diagnostic report that stores the diagnostic information of the Simulink system as a formatted text, returned as a character vector.

    Diagnostic report that stores the diagnostic information of the Simulink system, returned as a structure array. The structure array has these fields corresponding to the diagnostic options:

    • blocks

    • stateflow

    • sizes

    • links

    • compilestats

    • rtwbuildstats

    Data Types: struct

    Version History

    Introduced in R2006a