-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from monikajaskolka/first-commit
First commit
- Loading branch information
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# SimulinkProfiler-To-Excel | ||
Convert Simulink Profiler data into an Excel spreadsheet. | ||
#### Convert Simulink Profiler data into an Excel spreadsheet. | ||
|
||
<img src="imgs/Cover.png" width="750"> | ||
|
||
Converts [Simulink Profiler](https://www.mathworks.com/help/simulink/slref/introduction-to-profiling-models.html) data into an Excel spreadsheet. Currently, the Simulink Profiler only supports exporting data to a MAT file. After loading the profiler data into the base workspace, you can use this script to convert it into an Excel file. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
function profilerToExcel(profileData, filename) | ||
% PROFILERTOEXCEL Convert Simulink Profiler data into an Excel spreadsheet. | ||
% Currently, the Simulink Profiler only supports exporting data to a MAT file. | ||
% You can load the MAT data into your workspace, and then use this script to | ||
% convert it into an Excel file. | ||
% | ||
% For more information about the Simulink Profiler, see: | ||
% https://www.mathworks.com/help/simulink/slref/simulinkprofiler.html | ||
% | ||
% Inputs: | ||
% profileData Simulink.profiler.Data object. | ||
% filename Desired Excel filename. | ||
% | ||
% Outputs: | ||
% N/A | ||
% | ||
% Side Effects: | ||
% Excel file created in the present working directory. | ||
% | ||
% Example: | ||
% profilerToExcel(profileData, 'text.xlsx'); | ||
% | ||
% Author: | ||
% Monika Jaskolka | ||
|
||
% Add extension if not provided | ||
[~, ~, ext] = fileparts(filename); | ||
if isempty(ext) | ||
filename = [filename '.xlsx']; | ||
end | ||
|
||
header = {'Name', 'Total Time (s)', 'Self Time (s)', 'Number of Calls'}; | ||
[name, totalTime, selfTime, numberOfCalls] = profilerDataToCells(profileData); | ||
data = horzcat(name', num2cell(totalTime)', num2cell(selfTime)', num2cell(numberOfCalls)'); | ||
|
||
exceldata = vertcat(header, data); | ||
xlswrite(filename, exceldata); | ||
end | ||
|
||
function [name, totalTime, selfTime, numberOfCalls] = profilerDataToCells(profilerData) | ||
% PROFILERDATATOCELLS Extract the profilng data as cell arrays. | ||
rootnode = profilerData; | ||
rootnode = rootnode.rootUINode; | ||
[name, totalTime, selfTime, numberOfCalls] = recurseProfilerData(rootnode); | ||
end | ||
|
||
function [name, totalTime, selfTime, numberOfCalls] = recurseProfilerData(node) | ||
% RECURSEPROFILERDATA Find the data of profile nodes. | ||
|
||
%% Node path | ||
nodepath = node.path; | ||
|
||
% If the block path has nested Models, then there are multiple paths. | ||
% Combine the paths into one, w.r.t. the top-most model. | ||
p_fixed = ''; | ||
if numel(nodepath) > 1 | ||
p_fixed = char(nodepath(1)); | ||
for i = 2:numel(nodepath) | ||
p = char(nodepath(i)); | ||
slash = strfind(p, '/'); | ||
if isempty(slash) | ||
endOfModelName = length(p); | ||
else | ||
endOfModelName = slash - 1; | ||
end | ||
mdlname = p(1:endOfModelName); | ||
p = strrep(p, mdlname, [' (' mdlname ')']); | ||
p_fixed = [p_fixed, p]; | ||
end | ||
|
||
name = p_fixed; | ||
else | ||
name = char(nodepath); | ||
end | ||
name = {name}; % Convert to a cell so we can concatenate as an array | ||
|
||
%% Node time | ||
totalTime = node.totalTime; | ||
selfTime = node.selfTime; | ||
numberOfCalls = node.numberOfCalls; | ||
|
||
%% Base case | ||
if ~hasChildren(node) | ||
return; | ||
end | ||
|
||
%% Recursion | ||
for j = 1:length(node.children) | ||
[n, t, s, c] = recurseProfilerData(node.children(j)); | ||
|
||
% Append | ||
name = horzcat(name, n); | ||
totalTime = [totalTime, t]; | ||
selfTime = [selfTime, s]; | ||
numberOfCalls = [numberOfCalls, c]; | ||
end | ||
end | ||
|
||
function c = hasChildren(node) | ||
% HASCHILDREN Determine if the node has children. | ||
% | ||
% Inputs: | ||
% node UINode object. | ||
% | ||
% Outputs: | ||
% c Whether the node has children(1) or not(0). | ||
|
||
try | ||
c = ~isempty(node.children); | ||
catch | ||
c = false; | ||
end | ||
end |