%if EXISTS("_PROF_") == 0
%assign _PROF_ = 1
%function SLibSetupProf() void
%if EXISTS(ProfileIncludePath) && ProfileIncludePath != ""
%addincludepath ProfileIncludePath
%endif
%if EXISTS(ProfileGenCode) && ProfileGenCode && ...
EXISTS(ProfilerTLC)
%if !FILE_EXISTS(ProfilerTLC)
%assign tmpStr = "fileparts(which('%<ProfilerTLC>'))"
%assign fPath = FEVAL("eval", tmpStr)
%if ISEMPTY(fPath)
%assign errTxt = "%<ProfilerTLC> does not exist. You must add " ...
"this file to the MATLAB path"
%<LibReportError(errTxt)>
%else
%addincludepath fPath
%endif
%endif
%if IsModelReferenceSimTarget()
%assign ::ProfilerTLC = ""
%assign warnMsg = "The Model Reference simulation target does not support " ...
"profiling. No profiling code is generated"
%warning %<warnMsg>
%else
%generatefile ProfilerType "%<ProfilerTLC>"
%endif
%else
%assign ::ProfilerTLC = ""
%endif
%createrecord ::ProfilerRecord { /
Type "ProfilerType"; /
ProfTLCFile ProfilerTLC /
}
%endfunction
%function ProfilerFunctionExists(fcnName) void
%assign retVal = TLC_FALSE
%if ::ProfilerRecord.ProfTLCFile != ""
%assign retVal = GENERATE_FUNCTION_EXISTS(::ProfilerRecord, fcnName)
%endif
%return retVal
%endfunction
%function GetNumEffectiveSystems()
%with ::CompiledModel
%if IsModelReferenceTarget()
%assign numSS = NumSystems-1
%else
%assign numSS = NumSystems
%endif
%endwith
%return numSS
%endfunction
%function SLibGetProfCache(system) void
%<LibReportWarning("SLibGetProfCache is obsolete. Use LibGetProfCache instead.")>
%if ISFIELD(system,"ProfCache")
%return system.ProfCache
%else
%return ""
%endif
%endfunction
%function LibGetProfCache(system) void
%if ISFIELD(system,"ProfCache")
%return system.ProfCache
%else
%return ""
%endif
%endfunction
%function SLibSetProfCache(system, rec) void
%<LibReportWarning("SLibSetProfCache is obsolete. Use LibSetProfCache instead.")>
%addtorecord system ProfCache rec
%endfunction
%function LibSetProfCache(system, rec) void
%addtorecord system ProfCache rec
%endfunction
%function () void
%assign hdr = ""
%if ProfilerFunctionExists("ProfilerHeaders")
%assign hdr = GENERATE(::ProfilerRecord, "ProfilerHeaders")
%endif
%if !ISEMPTY(hdr)
%assign s = SIZE(hdr)
%assign numHdr = s[1]
%foreach hIdx = numHdr
%<LibAddToCommonIncludes(hdr[hIdx])>
%endforeach
%endif
%endfunction
%function SLibGenProfTypeDef() Output
%if ProfilerFunctionExists("ProfilerTypeDefs")
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerTypeDefs")
%<tmp>
%endif
%endfunction
%function SLibGenProfGlbExtData() Output
%if ProfilerFunctionExists("ProfilerGlobalExterns")
%with ::CompiledModel
%assign numSS = GetNumEffectiveSystems()
%foreach idx = numSS
%assign sys = System[idx]
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerGlobalExterns", sys)
%<tmp>
%endforeach
%endwith
%endif
%endfunction
%function SLibGenProfGlbData() Output
%if ProfilerFunctionExists("ProfilerGlobalData")
%with ::CompiledModel
%assign numSS = GetNumEffectiveSystems()
%foreach idx = numSS
%assign sys = System[idx]
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerGlobalData", sys)
%<tmp>
%endforeach
%endwith
%endif
%endfunction
%function SLibGenProfSysDeclare(system, fcn)
%if ProfilerFunctionExists("ProfilerSystemDecls")
%openfile tmpBuff
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerSystemDecls", system, fcn)
%if LibSystemIsInlined(system) && !ISEMPTY(tmp)
{
%endif
%<tmp>
%closefile tmpBuff
%return tmpBuff
%else
%return ""
%endif
%endfunction
%function SLibGenProfSysStart(system, fcn)
%if ProfilerFunctionExists("ProfilerSystemStart")
%openfile tmpBuff
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerSystemStart", system, fcn)
%<tmp>
%closefile tmpBuff
%return tmpBuff
%else
%return ""
%endif
%endfunction
%function SLibGenProfSysEnd(system, fcn)
%if ProfilerFunctionExists("ProfilerSystemFinish")
%openfile tmpBuff
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerSystemFinish", system, fcn)
%<tmp>
%if LibSystemIsInlined(system)
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerSystemDecls", system, fcn)
%if !ISEMPTY(tmp)
}
%endif
%endif
%closefile tmpBuff
%return tmpBuff
%else
%return ""
%endif
%endfunction
%function SLibGenProfSysTerminate(system)
%if ProfilerFunctionExists("ProfilerSystemTerminate")
%openfile tmpBuff
%assert IsBaseSystem(system)
%with ::CompiledModel
%assign numSS = GetNumEffectiveSystems()
%foreach idx = numSS
%assign sys = System[idx]
%assign tmp = GENERATE(::ProfilerRecord, "ProfilerSystemTerminate", sys)
%<tmp>
%endforeach
%closefile tmpBuff
%endwith
%return tmpBuff
%else
%return ""
%endif
%endfunction
%endif