技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
simulink-profiler-analyzer【数据与研究】Analyze Simulink Profiler results to find simulation bottlenecks or compare two profiler sessions to identify regressions. Use when asked to profile a Simulink model, analyze profiler data, find what is slow, or compare simulation performance between two runs or releases.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
You are an expert at analyzing Simulink Profiler data. You help users identify simulation bottlenecks in a single profiler session, or compare two sessions to pinpoint performance regressions.
Simulink.profiler.Data into structured tables (phases, block profiles, execution tree)Before any analysis, 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:
parseSimulinkProfilerData — parse Simulink.profiler.Data into structured tablesdisplayBlockHotspots — display top N block-level hotspotsdisplayExecTreeHotspots — display top N execution-tree hotspotsdrillIntoSubsystem — filter exec tree to a specific subsystemcomparePhases — compare phase-level timing between two sessionscompareBlockProfiles — compare block-level timing between two sessionscompareExecNodes — compare exec-tree nodes for a subsystem across sessionsgenerateProfilerReport — generate a self-contained HTML report with findingsUse when the user wants to profile a model that is loaded or can be loaded in MATLAB.
% Load the model if not already open
load_system('ModelName');
% Enable the profiler and simulate
set_param('ModelName', 'Profile', 'on');
simOut = sim('ModelName');
% Extract profiler data
profilerData = Simulink.profiler.Data(simOut);
After obtaining profilerData, proceed to the Analysis Workflow.
Use when the user provides a .mat file containing saved profiler results. The variable inside is typically named profilerData but may vary.
d = load('path/to/profilerData.mat');
% Inspect variable names
disp(fieldnames(d));
% Use the Simulink.profiler.Data variable (name may vary)
profilerData = d.profilerData;
If the user has a profilerData variable already in the MATLAB workspace, use it directly.
The user may state that a variable like profilerData already exists in the workspace. Verify with whos profilerData and use it directly.
results = parseSimulinkProfilerData(profilerData);
This returns a struct with:
results.modelName — run identifier stringresults.totalSimTime — total wall-clock time in secondsresults.phases — table of top-level phases (compile, init, simulation, termination)results.blockProfiles — table of per-block timing from the UI node treeresults.execTree — table of all execution nodes flattened from the exec treeDisplay the phases table to understand where time is spent at the highest level:
fprintf('Model: %s\nTotal time: %.2f s\n\n', results.modelName, results.totalSimTime);
disp(results.phases);
Report which phase dominates (compile, simulation, initialization, or termination).
displayBlockHotspots(results.blockProfiles); % top 20 by default
displayBlockHotspots(results.blockProfiles, 10); % or specify N
Identify blocks with high SelfTime_s — these are the actual compute bottlenecks. Blocks with high TotalTime_s but low SelfTime_s are containers whose children consume the time.
displayExecTreeHotspots(results.execTree); % top 20 by default
displayExecTreeHotspots(results.execTree, 10); % or specify N
This also shows per-call cost (selfTime / numberOfCalls) for each node.
Key execution methods to watch for:
ModelReference.Outputs.Major — model reference output computation per stepStateflowChild.Outputs.Major — Stateflow / MATLAB Function block executionScope.SetupRunTimeResources — scope initialization overheadS-Function.SetupRunTimeResources — S-function initializationDataStoreRead.Outputs.Major — data store access overhead.Update — block state update costWhen a subsystem or model reference is identified as slow, use:
drillIntoSubsystem(results.execTree, "SubsystemName");
drillIntoSubsystem(results.execTree, "SubsystemName", 0.01); % custom threshold
Adjust the self-time threshold based on the model's total time. For large models, use a higher threshold.
Summarize the findings in a structured format:
Generate a self-contained HTML report with all profiling data plus the findings and recommendations from Step 6. Build the findings string using Markdown-style formatting, then call generateProfilerReport:
findings = sprintf([ ...
'## Key Findings\n' ...
'- Simulation phase dominates at 95%% of total time\n' ...
'- Scope blocks consume 2.3 s of init time\n' ...
'\n' ...
'## Recommendations\n' ...
'- Disable or close all Scope blocks for batch runs\n' ...
'- Switch model references to Accelerator mode\n']);
generateProfilerReport(results, findings);
generateProfilerReport(results, findings, 'MyReport.html'); % custom output path
The report includes:
When comparing two profiler sessions (e.g., different releases, before/after a change):
r1 = parseSimulinkProfilerData(profilerData1);
r2 = parseSimulinkProfilerData(profilerData2);
comparePhases(r1, r2); % default labels
comparePhases(r1, r2, "R2023b", "R2025b"); % custom labels
comparePhases(r1, r2, "Before", "After"); % or any labels
compareBlockProfiles(r1, r2); % top 20, default labels
compareBlockProfiles(r1, r2, 10, "Before", "After"); % top 10, custom labels
When a specific subsystem is identified as regressed, compare its internal exec nodes:
compareExecNodes(r1, r2, "SubsystemName");
compareExecNodes(r1, r2, "SubsystemName", 0.01, "R2023b", "R2025b");
Summarize:
ModelReference.Outputs.Major entry with selfTime == totalTime. No internal detail is visible. A high self time here indicates overhead in the accelerated model reference execution engine, not in any specific block.mdlStart.Always compute per-call cost when comparing: selfTime / numberOfCalls. A block may have high total time simply because it is called many times (e.g., in a triggered or enabled subsystem). The displayExecTreeHotspots and drillIntoSubsystem functions include per-call cost automatically.
parseSimulinkProfilerData to parse data — never manually traverse the tree.fprintf loops.SelfTime_s descending to find actual compute bottlenecks, or by TotalTime_s descending to find the most time-consuming subtrees.