1 classdef ProfileManager<handle
2 properties (Access=
private)
7 profSave(SProfileInfo, dirName)
8 activeBrowser=profView(varargin)
18 self.profMode=profMode;
21 function resTime=runAndProcess(self,fRun,varargin)
24 [reg,~,nRuns,useMedianTime]=...
26 {
'nRuns',
'useMedianTime';1,
false;...
27 'isreal(x)&&isscalar(x)',
'islogical(x)&&isscalar(x)'},...
28 [0,1],
'propRetMode',
'separate');
31 profCaseName=
'default';
36 isnDetailed=any(strcmpi(
self.profMode,{
'none',
'off'}));
39 resTimeVec=zeros(1,nRuns);
42 curProfileInfoObj.
tic();
44 resTimeVec(iRun)=curProfileInfoObj.toc();
46 resTime=median(resTimeVec);
53 resTime=profileInfoObj.process();
67 resTime=profileInfoObj.process(...
68 profCaseName,
'profileMode',
self.profMode,...
70 'profileDir',
self.profDir);
75 function profSave(SProfileInfo, dirName)
78 dirName =
'profile_results';
81 pathStr = fileparts(dirName);
84 fullDirname = fullfile(cd,dirName);
86 fullDirname = dirName;
93 for iFunc = 0:numel(SProfileInfo.FunctionTable)
94 htmlStr = profview(iFunc,SProfileInfo);
96 htmlStr = regexprep(htmlStr,'<a href="matlab: profview\((\d+)\);">',...
97 '<a href="file$1.html">');
99 htmlStr = regexprep(htmlStr,'<a href="matlab:.*?>(.*?)</a>','$1');
101 htmlStr = regexprep(htmlStr,'<form.*?</form>','');
103 insertStr = ['<body bgcolor="
#F8F8F8"><strong>',... 104 'This is a static copy of a profile report</strong><p>' ...
105 '<a href="file0.html">Home</a><p>'];
106 htmlStr = strrep(htmlStr,
'<body>',insertStr);
108 fileName = fullfile(fullDirname,sprintf(
'file%d.html',iFunc));
109 [idFile,errMsg] = fopen(fileName,
'w',
'n',
'utf8');
111 fprintf(idFile,
'%s',htmlStr);
115 'Unable to open file %s, reason: %s',fileName,errMsg);
118 function activeBrowser=profView(varargin)
120 persistent profInfoMap browserMap
122 {
'titlePrefix',
'keepCache',
'cacheKey'});
126 isTitlePrefixSpec=
false;
128 isCacheKeySpec=
false;
130 switch lower(prop{k})
132 titlePrefix=prop{k+1};
133 if ~(ischar(titlePrefix)&&
mxberry.
core.isrow(titlePrefix))
135 'titlePrefix property is expected to be a string');
137 isTitlePrefixSpec=
true;
139 isCacheKept=prop{k+1};
140 if ~(islogical(isCacheKept)&&numel(isCacheKept)==1)
142 'cacheKept property is expected to be a logical scalar');
146 if ~(ischar(cacheKey)&&
mxberry.
core.isrow(cacheKey))
148 'cacheKey property is expected to be a string');
154 if isempty(browserMap)
155 browserMap=containers.Map();
158 if browserMap.isKey(cacheKey)
159 activeBrowser=browserMap(cacheKey);
162 'Oops, we shouldn''t be here');
165 activeBrowser=createBrowser();
166 cacheKey=num2str(activeBrowser.hashCode());
167 browserMap(cacheKey)=activeBrowser;
170 if ~isTitlePrefixSpec
174 if isempty(profInfoMap)
175 profInfoMap=containers.Map();
178 if (profInfoMap.isKey(cacheKey)&&~isCacheKept)||~profInfoMap.isKey(cacheKey)
179 profInfo=profile(
'info');
180 profInfoMap(cacheKey)=profInfo;
182 profInfo=profInfoMap(cacheKey);
188 reg=[reg,{profInfo}];
191 htmlOut=profview(reg{:});
192 funcRepStr=
'mxberry.dev.prof.ProfileManager.profView';
193 funcRepArgStr=[
'''keepCache
'',
true,
''cacheKey
'',
''',cacheKey,
''',
']; 195 htmlOut=strrep(htmlOut,'<title>
',['<title>
',titlePrefix,',
']); 196 funcRepArgStr=[funcRepArgStr,'''titlePrefix
'',
''',titlePrefix,
''',
']; 199 htmlOut=strrep(htmlOut,'profview(
',['profview(
',funcRepArgStr]); 201 htmlOut=strrep(htmlOut,'profview
',funcRepStr); 204 activeBrowser.setHtmlText(htmlOut); 207 function activeBrowser=createBrowser() 209 com.mathworks.mde.webbrowser.WebBrowser.createBrowser(true,true); 210 if isempty(activeBrowser) 211 throwerror('wrongCall
',... 212 'Browser window
for profiler can not be created
'); function tic(in self)
TIC starts a stopwatch timer and begins profiling.
function tic(in self)
TIC starts a stopwatch timer and begins profiling.
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function parseparext(in args, in propNameValMat, in varargin)
PARSEPAREXT behaves in the same way as mxberry.core.parseparams but returns property values in a more...
function checkvar(in x, in typeSpec, in varargin)
CHECKVAR checks a generic condition provided by typeSpec string in the following format: 'isnumeric(x...
PROFILEINFO contains profiling info obtaining during exectution of some code.
function isfunction(in inpArray)
PROFILEINFODETAILED contains detailed profiling info obtaining during exectution of some code...