Skip to content

Instantly share code, notes, and snippets.

@hiono
Created September 14, 2022 02:19
Show Gist options
  • Save hiono/8f46ed6844ca57d614038a0dcd90be3e to your computer and use it in GitHub Desktop.
Save hiono/8f46ed6844ca57d614038a0dcd90be3e to your computer and use it in GitHub Desktop.
A tool to convert the MAT format of simulink's ProfilerData results to YAML format.
%%% usage
% diary_name = strcat('prof_', datestr(now, 'yyyymmddHHMMSS'), '.yaml');
% diary_folder = pwd;
% diary(diary_name);
% convProfilerDataMAT2YAML('ProfilerData.mat');
% diary off;
function convProfilerDataMAT2YAML(matfile)
narginchk(1, 1)
mat = load(matfile);
spd = mat.(cell2mat(fieldnames(mat)));
disp(sprintf("- run: '%s'", spd.run));
disp(sprintf("- UserString: '%s'", spd.UserString));
disp(sprintf("- rootUINode:"));
getUINode(spd.rootUINode, 1);
disp(sprintf("- rootExecNode:"));
getExecNode(spd.rootExecNode, 1);
end
function getUINode(obj, indent_lebel)
spc = blanks(indent_lebel*2);
disp(sprintf("%s- totalTime: %f", spc, obj.totalTime));
disp(sprintf("%s- selfTime: %f", spc, obj.selfTime));
disp(sprintf("%s- numberOfCalls: %d", spc, obj.numberOfCalls));
disp(sprintf("%s- path: %s", spc, obj.path));
if length(obj.children) > 1
disp(sprintf("%s- children:", spc));
for i = 1:length(obj.children)
disp(sprintf("%s- %d:", blanks((indent_lebel + 1)*2), i));
chld = obj.children(i);
getUINode(chld, indent_lebel+2)
end
end
end
function getExecNode(obj, indent_lebel)
spc = blanks(indent_lebel*2);
disp(sprintf("%s- totalTime: %f", spc, obj.totalTime));
disp(sprintf("%s- selfTime: %f", spc, obj.selfTime));
disp(sprintf("%s- numberOfCalls: %d", spc, obj.numberOfCalls));
disp(sprintf("%s- location: %s", spc, obj.location));
disp(sprintf("%s- objectPath: %s", spc, obj.objectPath));
if length(obj.children) > 1
disp(sprintf("%s- children:", spc));
for i = 1:length(obj.children)
disp(sprintf("%s- %d:", blanks((indent_lebel + 1)*2), i));
chld = obj.children(i);
getExecNode(chld, indent_lebel+2)
end
end
end
diary_name = strcat('prof_', datestr(now, 'yyyymmddHHMMSS'), '.yaml');
diary_folder = pwd;
diary(diary_name);
readProf('ProfilerData.mat');
diary off;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment