Profile and analyze the initialization (compile) phase of a Simulink model. Use when the user asks to profile model initialization, diagnose slow model loading/compiling, or analyze existing init profiling data files (out_after.mat, perfTracer.mat, profilerResults.mat, modelCompileDiary.txt).
You are an expert in profiling and analyzing the initialization (compile) phase of Simulink models. You help users either collect profiling data or analyze existing profiling results to identify bottlenecks.
out_after.mat, perfTracer.mat, profilerResults.mat, modelCompileDiary.txtBefore running any analysis scripts, run the setup function located in the skill's scripts/ folder. This self-locating script adds its own folder to the MATLAB path regardless of where the skill is installed or which AI agent is used.
run('SCRIPTS_FOLDER/setup.m')
Replace SCRIPTS_FOLDER with the absolute path to this skill's scripts/ directory (derived from the <skill_files> entries below — use the parent folder of any listed .m file).
This makes the following functions available:
collectInitProfiling — run the profiling harness on a loaded modelanalyzeTimingOverview — display timing breakdown from SimulationOutputanalyzePerfTracer — display Performance Tracer phase durationsanalyzeProfilerResults — display user vs shipping code profiler resultscheckModelRefRebuild — check ModelRefRebuild setting from diarygenerateFlamegraph — generate a standalone interactive HTML flamegraphgenerateInitProfilingReport — generate a combined HTML report with flamegraphs.mat/.txt files), skip to Step 2.The model must be loaded in Simulink. Run the collectInitProfiling script:
collectInitProfiling('ModelName')
If no model name is provided, it uses bdroot. This produces four files in the current directory:
p)It also creates a timestamped .zip archive of all four files.
analyzeTimingOverview('out_after.mat')
Report the total wall time and how it breaks down between initialization, execution, and termination. For a StopTime=0 run, nearly all time should be in initialization.
Run the analyzePerfTracer script:
analyzePerfTracer('perfTracer.mat')
This parses PerformanceTracingRawDataVector using a stack-based approach to match nested start/end phase pairs, and displays a table of all phases with duration and percentage of total wall time.
Run the analyzeProfilerResults script:
analyzeProfilerResults('profilerResults.mat')
This computes self time (TotalTime minus children time) for each function, separates shipping code (under matlabroot) from user code, and displays two ranked tables:
Run the checkModelRefRebuild script:
checkModelRefRebuild('modelCompileDiary.txt')
This checks the ModelRefRebuild parameter value recorded in the diary:
'IfOutOfDate': Good — recommended value ("If changes in known dependencies detected").'AssumeUpToDate': Informational — skips all rebuild checks. Fast, but risks stale targets.'IfOutOfDateOrStructuralChange' or 'Force': Inefficient — flag to user and recommend changing.Generate a combined HTML report with interactive flamegraphs:
generateInitProfilingReport() % uses files in current directory
generateInitProfilingReport('path/to/data') % specify data directory
generateInitProfilingReport('path/to/data', 'report.html') % specify output path
This produces a self-contained HTML file with:
To generate only a standalone flamegraph from Performance Tracer data:
generateFlamegraph('perfTracer.mat') % saves flamegraph_perfTracer.html
generateFlamegraph('perfTracer.mat', 'output.html') % specify output path
Present a structured summary with:
'IfOutOfDate')Focus recommendations on what the user can actually change. For shipping-code bottlenecks, mention them for awareness but note they are internal to MATLAB.