Skip to content

Commit

Permalink
- Add more realtime timers and an internal scripting query so we can …
Browse files Browse the repository at this point in the history
…ask for approximate timing in a mos-file even if the API call does not return the times

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11078 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 10, 2012
1 parent bf8cf55 commit 535053d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 35 deletions.
3 changes: 3 additions & 0 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -47,6 +47,9 @@ public import HashTable4;
public import HashTableCG;

public constant String partialDerivativeNamePrefix="$pDER";
public constant Integer RT_PROFILER0=6;
public constant Integer RT_PROFILER1=7;
public constant Integer RT_PROFILER2=8;
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES=12;
public constant Integer RT_CLOCK_EXECSTAT_JACOBIANS=13;
public constant Integer RT_CLOCK_EXECSTAT_JACOBIANS_MODULES=14;
Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -6558,14 +6558,14 @@ public function profilerinit
algorithm
setGlobalRoot(Global.profilerTime1Index, 0.0);
setGlobalRoot(Global.profilerTime2Index, 0.0);
System.realtimeTick(8);
System.realtimeTick(BackendDAE.RT_PROFILER0);
end profilerinit;

public function profilerresults
protected
Real tg,t1,t2;
algorithm
tg := System.realtimeTock(8);
tg := System.realtimeTock(BackendDAE.RT_PROFILER0);
t1 := getGlobalRoot(Global.profilerTime1Index);
t2 := getGlobalRoot(Global.profilerTime2Index);
print("Time all: "); print(realString(tg)); print("\n");
Expand All @@ -6575,19 +6575,19 @@ end profilerresults;

public function profilerstart1
algorithm
System.realtimeTick(9);
System.realtimeTick(BackendDAE.RT_PROFILER1);
end profilerstart1;

public function profilerstart2
algorithm
System.realtimeTick(10);
System.realtimeTick(BackendDAE.RT_PROFILER2);
end profilerstart2;

public function profilerstop1
protected
Real t;
algorithm
t := System.realtimeTock(9);
t := System.realtimeTock(BackendDAE.RT_PROFILER1);
setGlobalRoot(Global.profilerTime1Index,
realAdd(getGlobalRoot(Global.profilerTime1Index),t));
end profilerstop1;
Expand All @@ -6596,7 +6596,7 @@ public function profilerstop2
protected
Real t;
algorithm
t := System.realtimeTock(10);
t := System.realtimeTock(BackendDAE.RT_PROFILER2);
setGlobalRoot(Global.profilerTime2Index,
realAdd(getGlobalRoot(Global.profilerTime2Index),t));
end profilerstop2;
Expand Down
42 changes: 21 additions & 21 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -961,20 +961,20 @@ protected
Absyn.ComponentRef a_cref;
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
algorithm
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BACKEND);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScript.getFileDir(a_cref, p);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_SIMCODE);
(libs, includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
createFunctions(dae, inBackendDAE, functionTree, className);
simCode := createSimCode(functionTree, outIndexedBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
Debug.execStat("SimCode",CevalScript.RT_CLOCK_BUILD_MODEL);
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_SIMCODE);
Debug.execStat("SimCode",CevalScript.RT_CLOCK_SIMCODE);

System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_TEMPLATES);
callTargetTemplatesFMU(simCode, Config.simCodeTarget());
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_TEMPLATES);
end generateModelCodeFMU;


Expand Down Expand Up @@ -1016,13 +1016,13 @@ algorithm
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),filenameprefix,addDummy, inSimSettingsOpt)
equation
/* calculate stuff that we need to create SimCode data structure */
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_FRONTEND);
//(cache,Values.STRING(filenameprefix),SOME(_)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st),NONE(), msg);
ptot = Dependency.getTotalProgram(className,p);
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_FRONTEND);
System.realtimeTick(CevalScript.RT_CLOCK_BACKEND);
funcs = Env.getFunctionTree(cache);
dae = DAEUtil.transformationsBeforeBackend(cache,dae);
funcs = Env.getFunctionTree(cache);
Expand Down Expand Up @@ -1086,27 +1086,27 @@ protected
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
list<JacobianMatrix> LinearMatrices;
algorithm
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BACKEND);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScript.getFileDir(a_cref, p);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_SIMCODE);
(libs, includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
createFunctions(dae, inBackendDAE, functionTree, className);
simCode := createSimCode(functionTree, outIndexedBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, simSettingsOpt, recordDecls, literals, args);

timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
Debug.execStat("SimCode",CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_SIMCODE);
Debug.execStat("SimCode",CevalScript.RT_CLOCK_SIMCODE);
System.realtimeTick(CevalScript.RT_CLOCK_LINEARIZE);

LinearMatrices := createJacobianLinearCode(functionTree,outIndexedBackendDAE);
simCode := addJacobianstoSimCode(simCode, LinearMatrices);
timeJacobian := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
Debug.execStat("Linearization",CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
timeJacobian := System.realtimeTock(CevalScript.RT_CLOCK_LINEARIZE);
Debug.execStat("Linearization",CevalScript.RT_CLOCK_LINEARIZE);
System.realtimeTick(CevalScript.RT_CLOCK_TEMPLATES);

callTargetTemplates(simCode,inBackendDAE,Config.simCodeTarget());
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_TEMPLATES);
end generateModelCode;

// TODO: use another switch ... later make it first class option like -target or so
Expand Down Expand Up @@ -1243,13 +1243,13 @@ algorithm
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),filenameprefix,addDummy, inSimSettingsOpt,args)
equation
// calculate stuff that we need to create SimCode data structure
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_FRONTEND);
//(cache,Values.STRING(filenameprefix),SOME(_)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st),NONE(), msg);
ptot = Dependency.getTotalProgram(className,p);
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_FRONTEND);
System.realtimeTick(CevalScript.RT_CLOCK_BACKEND);
dae = DAEUtil.transformationsBeforeBackend(cache,dae);
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae,funcs,true);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/Uncertainties.mo
Expand Up @@ -127,13 +127,13 @@ algorithm

print("* Calling modelEquationsUC\n");
// calculate stuff that we need to create SimCode data structure
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_UNCERTAINTIES);
//(cache,Values.STRING(filenameprefix),SOME(_)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st),NONE(), msg);
ptot = Dependency.getTotalProgram(className,p);
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_UNCERTAINTIES);
System.realtimeTick(CevalScript.RT_CLOCK_BACKEND);
dae = DAEUtil.transformationsBeforeBackend(cache,dae);
funcs = Env.getFunctionTree(cache);

Expand Down
29 changes: 29 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -825,6 +825,35 @@ record CheckSettingsResult
annotation(preferredView="text");
end CheckSettingsResult;

package Internal

package Time

/* From CevalScript */
constant Integer RT_CLOCK_SIMULATE_TOTAL = 8;
constant Integer RT_CLOCK_SIMULATE_SIMULATION = 9;
constant Integer RT_CLOCK_BUILD_MODEL = 10;
constant Integer RT_CLOCK_EXECSTAT_MAIN = 11;
constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES = 12;
constant Integer RT_CLOCK_FRONTEND = 13;
constant Integer RT_CLOCK_BACKEND = 14;
constant Integer RT_CLOCK_SIMCODE = 15;
constant Integer RT_CLOCK_LINEARIZE = 16;
constant Integer RT_CLOCK_TEMPLATES = 17;

function readTimer
input Integer index;
output Real elapsed;
external "builtin";
annotation(Documentation(info="<html>
Reads the internal timer with the given index.
</html>"),preferredView="text");
end readTimer;

end Time;

end Internal;

function checkSettings "Display some diagnostics"
output CheckSettingsResult result;
external "builtin";
Expand Down
24 changes: 21 additions & 3 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -109,8 +109,15 @@ protected import Uncertainties;
public constant Integer RT_CLOCK_SIMULATE_TOTAL = 8;
public constant Integer RT_CLOCK_SIMULATE_SIMULATION = 9;
public constant Integer RT_CLOCK_BUILD_MODEL = 10;
public constant Integer RT_CLOCK_EXECSTAT_MAIN = Inst.RT_CLOCK_EXECSTAT_MAIN;
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES = BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES;
public constant Integer RT_CLOCK_EXECSTAT_MAIN = Inst.RT_CLOCK_EXECSTAT_MAIN /* 11 */;
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES = BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES /* 12 */;
public constant Integer RT_CLOCK_FRONTEND = 13;
public constant Integer RT_CLOCK_BACKEND = 14;
public constant Integer RT_CLOCK_SIMCODE = 15;
public constant Integer RT_CLOCK_LINEARIZE = 16;
public constant Integer RT_CLOCK_TEMPLATES = 17;
public constant Integer RT_CLOCK_UNCERTAINTIES = 18;
public constant list<Integer> buildModelClocks = {RT_CLOCK_SIMULATE_TOTAL,RT_CLOCK_BUILD_MODEL,RT_CLOCK_TEMPLATES,RT_CLOCK_LINEARIZE,RT_CLOCK_SIMCODE,RT_CLOCK_BACKEND,RT_CLOCK_FRONTEND};

protected constant DAE.Type simulationResultType_rtest = DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationResult")),{
DAE.TYPES_VAR("resultFile",DAE.ATTR(SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.VAR(),Absyn.BIDIR(),Absyn.NOT_INNER_OUTER()),SCode.PUBLIC(),DAE.T_STRING_DEFAULT,DAE.UNBOUND(),NONE()),
Expand Down Expand Up @@ -763,7 +770,7 @@ algorithm
Absyn.ComponentRef cr_1;
Integer size,length,resI,timeStampI,i,n;
list<String> vars_1,vars_2,args,strings,strVars,strs,visvars;
Real t1,t2,time,timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2;
Real t1,t2,time,timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r;
Interactive.Statements istmts;
Boolean bval, b, b1, b2, externalWindow, legend, grid, logX, logY, points, gcc_res, omcfound, rm_res, touch_res, uname_res, extended, insensitive,ifcpp, sort, builtin, showProtected;
Env.Cache cache;
Expand Down Expand Up @@ -1213,6 +1220,8 @@ algorithm

case (cache,env,"buildModel",vals,st,msg)
equation
List.map_0(buildModelClocks,System.realtimeTick);
print("init'ed clocks\n");
(cache,compileDir,executable,method_str,outputFormat_str,st,initfilename,_) = buildModel(cache,env, vals, st, msg);
executable = Util.if_(not Config.getRunningTestsuite(),compileDir +& executable,executable);
then
Expand Down Expand Up @@ -1465,6 +1474,15 @@ algorithm
then
(cache,Values.INTEGER(resI),st);

case (cache,env,"readTimer",{Values.INTEGER(i)},st,msg)
equation
r = System.realtimeTock(i);
then
(cache,Values.REAL(r),st);

case (cache,env,"readTimer",_,st,msg)
then (cache,Values.REAL(-1.0),st);

case (cache,env,"regularFileExists",{Values.STRING(str)},st,msg)
equation
b = System.regularFileExists(str);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/System.mo
Expand Up @@ -642,14 +642,14 @@ end configureCommandLine;

public function realtimeTick
"Tock returns the time since the last tock; undefined if tick was never called.
The clock index is 0-15. The function fails if the number is out of range."
The clock index is 0-31. The function fails if the number is out of range."
input Integer clockIndex;
external "C" System_realtimeTick(clockIndex) annotation(Library = "omcruntime");
end realtimeTick;

public function realtimeTock
"Tock returns the time since the last tock, undefined if tick was never called.
The clock index is 0-15. The function fails if the number is out of range."
The clock index is 0-31. The function fails if the number is out of range."
input Integer clockIndex;
output Real outTime;
external "C" outTime = System_realtimeTock(clockIndex) annotation(Library = "omcruntime");
Expand Down

0 comments on commit 535053d

Please sign in to comment.