gusucode.com > target工具箱matlab源码程序 > target/extensions/processor/shared/ti/utils/generateHTML_TItarget.m
function fileName = generateHTML_TItarget(S,P,profileTime) % Generate custom HTML for this profile report and export to a file in the % tempdir. % Copyright 2001-2012 The MathWorks, Inc. title = 'Profile Report'; invalidDataMsg = ['<br>Your application has not executed properly for ' ... 'measurement of profile statistics. No further results ' ... 'can be reported. Please execute a DSP/BIOS application ' ... 'for a period of time before attempting to obtain profile ' ... 'statistics. <br><br>']; % Populate text buffer with lines % (to be written out later, all at once) TXT{1} = '<!doctype html public "-//w3c//dtd html 4.0 transitional//en">'; TXT{end+1} = '<html>'; TXT{end+1} = '<head>'; TXT{end+1} = ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; TXT{end+1} =[' <title>' title ' </title>']; TXT{end+1} = '</head>'; TXT{end+1} = '<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">'; TXT{end+1} = '<center><b><font size=+3>'; TXT{end+1} = title; TXT{end+1} = '<br></font></b>'; TXT{end+1} = '</center>'; % Report body begins here TXT = showReportHeader (TXT, S, profileTime); if S.validData && S.containsSimulinkSystems, TXT = showOverallStatistics (TXT, S); end if ~S.validData, TXT{end+1} = invalidDataMsg; elseif S.containsSimulinkSystems, TXT = showSubsystemStatistics (TXT, S, P); end TXT = showFootnotes (TXT, S); % Report body ends here TXT{end+1} = '</body>'; TXT{end+1} = '</html>'; % - - - - - - - - - - - - - - - - - - - - - % Write TXT to file if isfield(S,'pwd'), destDir = S.pwd; else rtwGenSettings = ccslink_getRtwGenSettings; destDir = fullfile(pwd,[bdroot rtwGenSettings.BuildDirSuffix]); end if ~exist(destDir,'dir'), destDir = tempdir; end fileName = fullfile(destDir,'profileReport.html'); if exist(fileName,'file') try delete(fileName); catch ME %#ok<NASGU> end end fid = fopen(fileName,'wt','n','UTF-8'); if (fid < 0) DAStudio.error('TARGETSHARED:codegen:generateHTMLTItargetErrorOpeningFile'); end formatStr = '%s\n'; for k = 1:length(TXT), fprintf(fid,formatStr,TXT{k}); end fclose(fid); % ------------------------------------------------ function TXT = showReportHeader (TXT, S, profileTime) TXT{end+1} = '<center>'; TXT{end+1} = '<br><font><b>'; if S.containsSimulinkSystems, TXT{end+1} = ['Simulink model: ' ... '<A href = "matlab:try,open_system(''' S.modelName ''')' ... ',end">' S.modelName '.mdl</A><br>']; TXT{end+1} = ['Target: <b>' S.BoardType '</b><br>']; end TXT{end+1} = '<br></b></font>'; TXT{end+1} = 'Report of profile data from Code Composer Studio (tm)<br>'; TXT{end+1} = [datestr(profileTime) '<br>']; TXT{end+1} = '</center>'; % ------------------------------------------------ function TXT = showOverallStatistics (TXT, S) TXT{end+1} = '<br><hr><br>'; TXT{end+1} = '<center><b><font size=+1>'; TXT{end+1} = 'Timing constants <br><br>'; TXT{end+1} = '</font></b>'; TXT{end+1} = '<table BORDER CELLPADDING=2>'; TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>Base sample time</b></td>'; TXT{end+1} = ['<td>' timeFmt(S.timeBetweenInterrupts) '</td>']; TXT{end+1} = '</tr>'; TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>CPU clock speed</b><sup>1</sup></td>'; TXT{end+1} = ['<td>' num2str(S.CpuClkSpeed/1e6) ' MHz</td>']; TXT{end+1} = '</tr>'; TXT{end+1} = '</table></center>'; TXT{end+1} = '<br>'; % ------------------------------------------------ function TXT = showSubsystemStatistics (TXT, S, P) srtOrder = sortSystemsByTime(S); TXT{end+1} = '<hr><br><center>'; TXT{end+1} = '<b><font size=+1>'; if length(S.sys)>1, TXT{end+1} = 'Profiled Simulink Subsystems'; else TXT{end+1} = 'Profiled Simulink Subsystem'; end TXT{end+1} = '<br><br></font></b>'; for k = 1:length(S.sys) % Display the subsystem name with hyperlinks TXT{end+1} = '<table BORDER CELLPADDING=2 COLS=2 WIDTH="550">'; %#ok<*AGROW> TXT{end+1} = '<tr>'; TXT{end+1} = '<td WIDTH="43%"><b><font size=+1>System name</font></b></td>'; TXT{end+1} = '<td>'; TXT{end+1} = openSystemHyperlink( ... S.modelName, ... S.sys(srtOrder(k)).name,S.sys(srtOrder(k)).simName); TXT{end+1} = '</td>'; TXT{end+1} = '</tr>'; if S.sys(srtOrder(k)).OutputUpdateCombined, TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>STS object</b></td>'; TXT{end+1} = ['<td>' ... P.obj(S.sys(srtOrder(k)).stsObj(1).P_index).name ... '</td>']; TXT{end+1} = '</tr>'; else TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>STS objects</b></td>'; TXT{end+1} = ['<td>' ... P.obj(S.sys(srtOrder(k)).stsObj(1).P_index).name ... ', ' ... P.obj(S.sys(srtOrder(k)).stsObj(2).P_index).name ... '</td>']; TXT{end+1} = '</tr>'; end if S.sys(srtOrder(k)).validData, % check if the system is a for iterator subsystem try IsForIteratorSystem = ~isempty(find_system(S.sys(srtOrder(k)).simName, 'SearchDepth',1, 'BlockType','ForIterator')); catch ME DAStudio.error('TARGETSHARED:codegen:generateHTMLTItargetModelClosed'); end %IsForIteratorSystem = ~isempty(find_system(S.sys(srtOrder(k)).simName, 'SearchDepth',1, 'BlockType','ForIterator')); % if the system is for iterator, we display measurements % per iteration. if ~IsForIteratorSystem TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>Maximum time spent in this subsystem</b></td>'; TXT{end+1} = ['<td>' ... timeFmt(S.sys(srtOrder(k)).maxTime) ... ' (' percentFmt(S.sys(srtOrder(k)).maxPercentOfInterruptTime) ... ' of base interval)</td>']; TXT{end+1} = '</tr>'; %TXT{end+1} = '<tr>'; %TXT{end+1} = ['<td><b>Max percent of base interval</b></td>']; %TXT{end+1} = ['<td>' ... % percentFmt(S.sys(srtOrder(k)).maxPercentOfInterruptTime) ... % '</td>']; %TXT{end+1} = '</tr>'; TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>Average time spent in this subsystem</b></td>'; TXT{end+1} = ['<td>' ... timeFmt(S.sys(srtOrder(k)).avgTime) ... ' (' percentFmt(S.sys(srtOrder(k)).avgPercentOfInterruptTime) ... ' of base interval)</td>']; TXT{end+1} = '</tr>'; %TXT{end+1} = '<tr>'; %TXT{end+1} = ['<td><b>Average percent of base interval</b></td>']; %TXT{end+1} = ['<td>' ... % percentFmt(S.sys(srtOrder(k)).avgPercentOfInterruptTime) ... % '</td>']; %TXT{end+1} = '</tr>'; TXT{end+1} = '<tr>'; TXT{end+1} = '<td><b>Number of iterations counted</b></td>'; TXT{end+1} = ['<td>' ... num2str(P.obj(S.sys(srtOrder(k)).stsObj(1).P_index).count) ... '</td>']; TXT{end+1} = '</tr>'; else TXT{end+1} = ['<tr><td>This is a "For iterator" system.' ... ' Profiler does not report a valid' ... ' statistics for "For iterator" systems.</td></tr>']; end else % not valid data TXT{end+1} = ['<tr><td>This system has not reported valid profile ' ... 'statistics.</td></tr>']; end TXT{end+1} = '</table>'; if (k < length(S.sys)) TXT{end+1} = '<br><br>'; end end TXT{end+1} = '</center>'; % ------------------------------------------------ function TXT = showFootnotes (TXT, S) n = 0; if S.containsSimulinkSystems, TXT{end+1} = '<br><br><hr>'; TXT{end+1} = '<center><b><font size=+1>Notes</b></font></center>'; TXT{end+1} = '<br>'; TXT{end+1} = '<font>'; % CPU Clock speed note n = n+1; ns = num2str(n); TXT{end+1} = [ns '. The CPU clock speed is assumed to be ' ... num2str(S.CpuClkSpeed/1e6) ' MHz. ' ... 'If your board uses a different ' ... 'clock speed, then you must specify the ' ... 'correct CPU clock speed in the model settings.<br>']; TXT{end+1} = '<br>'; % Explanation of timer clicks vs. cpu cycles n = n+1; ns = num2str(n); TXT{end+1} = [ns '. STS timing objects associated with subsystem profiling ' ... 'are configured for a host-side ' ... 'operation of ' ... sprintf('%d', S.lowResClkDivider) ... '*x, reflecting the numerical relationship between ' ... 'CPU clock cycles and high-resolution timer clicks. Therefore, ' ... 'STS Max, Total, and Average measurements are correctly reported in ' ... 'units of "instructions" or "CPU clock cycles".<br>']; TXT{end+1} = '<br>'; % Multitasking note if S.isMultiTasking, n = n+1; ns = num2str(n); TXT{end+1} = [ns '. The model is in multi-tasking mode; ' ... 'only systems executing at the base rate ' ... 'have been profiled. Systems executing at ' ... 'slower rates are not profiled, because they ' ... 'can be preempted.<br>']; TXT{end+1} = '<br>'; end % Help browser note n = n+1; ns = num2str(n); TXT{end+1} = [ns '. This page is best viewed with the MATLAB Help Browser, ' ... 'which allows the system names to link to the corresponding ' ... 'subsystems in the Simulink model.<br>']; TXT{end+1} = '<br></font>'; TXT{end+1} = '<center><A href = "matlab:' ; TXT{end+1} = ['helpview([docroot ''/toolbox/ecoder/helptargets.map''], ' ... '''profiling_code'')']; TXT{end+1} = ['"><b>HELP</b> on Profiling with Target for ' ... 'TI C6000?</A></center>']; TXT{end+1} = '<br>'; TXT{end+1} = '<hr>'; end % ------------------------------------------------ function str = timeFmt(num) numDigits = 4; htmlMu = 'µ'; if (num >= 1), num2 = num; prefixStr = ''; elseif (num < 1) && (num >= 0.001), % milliseconds num2 = num*1000; prefixStr = 'm'; elseif (num < 0.001) && (num >= 1e-6), % microseconds num2 = num*1e6; prefixStr = htmlMu; elseif (num < 1e-6) && (num >= 1e-9), % nanoseconds num2 = num*1e9; prefixStr = 'n'; elseif (num < 1e-9) && (num >= 1e-12), % picoseconds num2 = num*1e12; prefixStr = 'p'; else % Zero. % Or really, really, really, really small: % sprintf will produce scientific notation here num2 = num; prefixStr = ''; end str = [sprintf(['%0.' num2str(numDigits) 'g'],num2) ' ' prefixStr 's']; % ------------------------------------------------ function str = percentFmt(num) numDigits = 3; pct = 100*num; if (pct >= 50), str = [num2str(floor(pct)) '%']; else str = [sprintf(['%0.' num2str(numDigits) 'g'],pct) '%']; end % ------------------------------------------------ function str = openSystemHyperlink(modelName, sysName, linkText) % Replace newlines with '\n' in system name for matlab command sysName2 = strrep(sysName,sprintf('\n'),'\n'); % Replace newlines with '' in link text linkText2 = strrep(linkText,sprintf('\n'),''); % Generate hyperlink if strcmp(sysName,'<Root>'), str = ['<A href = "matlab:' ... 'open_system(''' modelName '''), ' ... '">' linkText2 '</A>']; else str = ['<A href = "matlab:' ... 'load_system(''' modelName '''), ' ... 'pause(.1), ' ... 'open_system(sprintf(''' sysName2 '''),''force''), ' ... '">' linkText2 '</A>']; end % ------------------------------------------------ function srtOrder = sortSystemsByTime(S) for k = 1:length(S.sys), t = S.sys(k).maxTime; if isempty(t), t = -1; end times(k) = t; end [y ,srtOrderIncr] = sort(times); %#ok<ASGLU> srtOrder = fliplr(srtOrderIncr); % EOF generateHTML_TItarget.m