gusucode.com > target工具箱matlab源码程序 > target/extensions/processor/shared/ti/utils/ti_profreport.m

    function returnVal = ti_profreport(varargin)
%TI_PROFREPORT(ACTION, [...])   Generate html report containing
% information from the ticcs profile method and analysis of Simulink
% subsystems designated for profiling.  The user interface for this
% function is the TICCS PROFILE method.

%   Copyright 2003-2011 The MathWorks, Inc.

returnVal = [];

persistent S

action = varargin{1};
% All cases terminate in this switchyard except 'report'.
if strcmp(action,'clear')
    S = [];
    S.modelName = varargin{2};
    saveProfileInfo(S);
    return
elseif strcmp(action,'regSystemInfo')
    S.containsSimulinkSystems = true;
    systemInfo = varargin(2:end);
    S = regSysInfo_TItarget(S,systemInfo);
    saveProfileInfo(S);
    return
elseif strcmp(action,'getStsObjectNames')
    if isempty(S),
        S = loadProfileInfo(S);
    end
    if isfield(S,'sys'),
        targetInfo = varargin{2};
        irInfo = varargin{3};
        S = parseSlInfo_TItarget(S, targetInfo, irInfo);
        returnVal = S.stsObjNames;
        saveProfileInfo(S);
    else
        returnVal = {};
    end
    return
elseif strcmp(action,'report')
    if length(varargin)~=2,
        DAStudio.error('TARGETSHARED:utils:TIProfReportWrongArguments');
    end
    cc = varargin{2};
    % Continue below
else
    DAStudio.error('TARGETSHARED:utils:TIProfReportInvalidSyntax');
end

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Report generator

% Obtain profile data via CCS Link. If the loaded program is not a BIOS
% program, this statement will error out.
P = profile_with_STS(cc, 'raw');
profileTime = now;

if isempty(S) || ~isfield(S,'containsSimulinkSystems') || ...
        ~S.containsSimulinkSystems,
    S = loadProfileInfo(S);
    if isempty(S) || ~isfield(S,'containsSimulinkSystems'),
        S.containsSimulinkSystems = false;
    end
end

if ~S.containsSimulinkSystems,
    % Assume data is valid.
    S.validData = true;
end

% Analyze the contents of S and P; populate S with more info.
if S.containsSimulinkSystems,
    [S,P] = analyzeStats_TItarget(S,P);
end

% Invoke custom html report generator
fileName = generateHTML_TItarget(S,P,profileTime);

% Display in browser
web(fileName);

returnVal = fileName;


%----------------------------------------------------------------
function saveProfileInfo(S)

wd = pwd;
rtwGenSettings = ccslink_getRtwGenSettings;
rtwDir = [S.modelName rtwGenSettings.BuildDirSuffix];
if isempty(findstr(pwd,rtwDir)),
    if exist(rtwDir)==7,
        cd(rtwDir);
    else
        return  % Can't do anything
    end
end
S.pwd = pwd;
try
    save profileInfo S
end
cd(wd)

%----------------------------------------------------------------
function S = loadProfileInfo(S)
% Preserves existing S if not loaded

wd = pwd;
rtwGenSettings = ccslink_getRtwGenSettings;
if (isfield(S, 'modelName'))
    rtwDir = [S.modelName rtwGenSettings.BuildDirSuffix];
else
    rtwDir = [bdroot rtwGenSettings.BuildDirSuffix];
end
if isempty(findstr(pwd,rtwDir)),
    if exist(rtwDir)==7,
        cd(rtwDir);
    else
        return  % Can't do anything
    end
end
try
    load profileInfo
end
cd(wd)

% EOF  ti_profreport.m