Skip to content

Commit 535053d

Browse files
committed
- Add more realtime timers and an internal scripting query so we can 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
1 parent bf8cf55 commit 535053d

File tree

7 files changed

+85
-35
lines changed

7 files changed

+85
-35
lines changed

Compiler/BackEnd/BackendDAE.mo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public import HashTable4;
4747
public import HashTableCG;
4848

4949
public constant String partialDerivativeNamePrefix="$pDER";
50+
public constant Integer RT_PROFILER0=6;
51+
public constant Integer RT_PROFILER1=7;
52+
public constant Integer RT_PROFILER2=8;
5053
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES=12;
5154
public constant Integer RT_CLOCK_EXECSTAT_JACOBIANS=13;
5255
public constant Integer RT_CLOCK_EXECSTAT_JACOBIANS_MODULES=14;

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6558,14 +6558,14 @@ public function profilerinit
65586558
algorithm
65596559
setGlobalRoot(Global.profilerTime1Index, 0.0);
65606560
setGlobalRoot(Global.profilerTime2Index, 0.0);
6561-
System.realtimeTick(8);
6561+
System.realtimeTick(BackendDAE.RT_PROFILER0);
65626562
end profilerinit;
65636563

65646564
public function profilerresults
65656565
protected
65666566
Real tg,t1,t2;
65676567
algorithm
6568-
tg := System.realtimeTock(8);
6568+
tg := System.realtimeTock(BackendDAE.RT_PROFILER0);
65696569
t1 := getGlobalRoot(Global.profilerTime1Index);
65706570
t2 := getGlobalRoot(Global.profilerTime2Index);
65716571
print("Time all: "); print(realString(tg)); print("\n");
@@ -6575,19 +6575,19 @@ end profilerresults;
65756575

65766576
public function profilerstart1
65776577
algorithm
6578-
System.realtimeTick(9);
6578+
System.realtimeTick(BackendDAE.RT_PROFILER1);
65796579
end profilerstart1;
65806580

65816581
public function profilerstart2
65826582
algorithm
6583-
System.realtimeTick(10);
6583+
System.realtimeTick(BackendDAE.RT_PROFILER2);
65846584
end profilerstart2;
65856585

65866586
public function profilerstop1
65876587
protected
65886588
Real t;
65896589
algorithm
6590-
t := System.realtimeTock(9);
6590+
t := System.realtimeTock(BackendDAE.RT_PROFILER1);
65916591
setGlobalRoot(Global.profilerTime1Index,
65926592
realAdd(getGlobalRoot(Global.profilerTime1Index),t));
65936593
end profilerstop1;
@@ -6596,7 +6596,7 @@ public function profilerstop2
65966596
protected
65976597
Real t;
65986598
algorithm
6599-
t := System.realtimeTock(10);
6599+
t := System.realtimeTock(BackendDAE.RT_PROFILER2);
66006600
setGlobalRoot(Global.profilerTime2Index,
66016601
realAdd(getGlobalRoot(Global.profilerTime2Index),t));
66026602
end profilerstop2;

Compiler/BackEnd/SimCode.mo

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -961,20 +961,20 @@ protected
961961
Absyn.ComponentRef a_cref;
962962
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
963963
algorithm
964-
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
964+
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BACKEND);
965965
a_cref := Absyn.pathToCref(className);
966966
fileDir := CevalScript.getFileDir(a_cref, p);
967-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
967+
System.realtimeTick(CevalScript.RT_CLOCK_SIMCODE);
968968
(libs, includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
969969
createFunctions(dae, inBackendDAE, functionTree, className);
970970
simCode := createSimCode(functionTree, outIndexedBackendDAE,
971971
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
972-
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
973-
Debug.execStat("SimCode",CevalScript.RT_CLOCK_BUILD_MODEL);
972+
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_SIMCODE);
973+
Debug.execStat("SimCode",CevalScript.RT_CLOCK_SIMCODE);
974974

975-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
975+
System.realtimeTick(CevalScript.RT_CLOCK_TEMPLATES);
976976
callTargetTemplatesFMU(simCode, Config.simCodeTarget());
977-
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
977+
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_TEMPLATES);
978978
end generateModelCodeFMU;
979979

980980

@@ -1016,13 +1016,13 @@ algorithm
10161016
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),filenameprefix,addDummy, inSimSettingsOpt)
10171017
equation
10181018
/* calculate stuff that we need to create SimCode data structure */
1019-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1019+
System.realtimeTick(CevalScript.RT_CLOCK_FRONTEND);
10201020
//(cache,Values.STRING(filenameprefix),SOME(_)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st),NONE(), msg);
10211021
ptot = Dependency.getTotalProgram(className,p);
10221022
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
10231023
(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);
1024-
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
1025-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1024+
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_FRONTEND);
1025+
System.realtimeTick(CevalScript.RT_CLOCK_BACKEND);
10261026
funcs = Env.getFunctionTree(cache);
10271027
dae = DAEUtil.transformationsBeforeBackend(cache,dae);
10281028
funcs = Env.getFunctionTree(cache);
@@ -1086,27 +1086,27 @@ protected
10861086
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
10871087
list<JacobianMatrix> LinearMatrices;
10881088
algorithm
1089-
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
1089+
timeBackend := System.realtimeTock(CevalScript.RT_CLOCK_BACKEND);
10901090
a_cref := Absyn.pathToCref(className);
10911091
fileDir := CevalScript.getFileDir(a_cref, p);
1092-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1092+
System.realtimeTick(CevalScript.RT_CLOCK_SIMCODE);
10931093
(libs, includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
10941094
createFunctions(dae, inBackendDAE, functionTree, className);
10951095
simCode := createSimCode(functionTree, outIndexedBackendDAE,
10961096
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, simSettingsOpt, recordDecls, literals, args);
10971097

1098-
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
1099-
Debug.execStat("SimCode",CevalScript.RT_CLOCK_BUILD_MODEL);
1100-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1098+
timeSimCode := System.realtimeTock(CevalScript.RT_CLOCK_SIMCODE);
1099+
Debug.execStat("SimCode",CevalScript.RT_CLOCK_SIMCODE);
1100+
System.realtimeTick(CevalScript.RT_CLOCK_LINEARIZE);
11011101

11021102
LinearMatrices := createJacobianLinearCode(functionTree,outIndexedBackendDAE);
11031103
simCode := addJacobianstoSimCode(simCode, LinearMatrices);
1104-
timeJacobian := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
1105-
Debug.execStat("Linearization",CevalScript.RT_CLOCK_BUILD_MODEL);
1106-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1104+
timeJacobian := System.realtimeTock(CevalScript.RT_CLOCK_LINEARIZE);
1105+
Debug.execStat("Linearization",CevalScript.RT_CLOCK_LINEARIZE);
1106+
System.realtimeTick(CevalScript.RT_CLOCK_TEMPLATES);
11071107

11081108
callTargetTemplates(simCode,inBackendDAE,Config.simCodeTarget());
1109-
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
1109+
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_TEMPLATES);
11101110
end generateModelCode;
11111111

11121112
// TODO: use another switch ... later make it first class option like -target or so
@@ -1243,13 +1243,13 @@ algorithm
12431243
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),filenameprefix,addDummy, inSimSettingsOpt,args)
12441244
equation
12451245
// calculate stuff that we need to create SimCode data structure
1246-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1246+
System.realtimeTick(CevalScript.RT_CLOCK_FRONTEND);
12471247
//(cache,Values.STRING(filenameprefix),SOME(_)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st),NONE(), msg);
12481248
ptot = Dependency.getTotalProgram(className,p);
12491249
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
12501250
(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);
1251-
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
1252-
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
1251+
timeFrontend = System.realtimeTock(CevalScript.RT_CLOCK_FRONTEND);
1252+
System.realtimeTick(CevalScript.RT_CLOCK_BACKEND);
12531253
dae = DAEUtil.transformationsBeforeBackend(cache,dae);
12541254
funcs = Env.getFunctionTree(cache);
12551255
dlow = BackendDAECreate.lower(dae,funcs,true);

Compiler/BackEnd/Uncertainties.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ algorithm
127127

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

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,35 @@ record CheckSettingsResult
825825
annotation(preferredView="text");
826826
end CheckSettingsResult;
827827

828+
package Internal
829+
830+
package Time
831+
832+
/* From CevalScript */
833+
constant Integer RT_CLOCK_SIMULATE_TOTAL = 8;
834+
constant Integer RT_CLOCK_SIMULATE_SIMULATION = 9;
835+
constant Integer RT_CLOCK_BUILD_MODEL = 10;
836+
constant Integer RT_CLOCK_EXECSTAT_MAIN = 11;
837+
constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES = 12;
838+
constant Integer RT_CLOCK_FRONTEND = 13;
839+
constant Integer RT_CLOCK_BACKEND = 14;
840+
constant Integer RT_CLOCK_SIMCODE = 15;
841+
constant Integer RT_CLOCK_LINEARIZE = 16;
842+
constant Integer RT_CLOCK_TEMPLATES = 17;
843+
844+
function readTimer
845+
input Integer index;
846+
output Real elapsed;
847+
external "builtin";
848+
annotation(Documentation(info="<html>
849+
Reads the internal timer with the given index.
850+
</html>"),preferredView="text");
851+
end readTimer;
852+
853+
end Time;
854+
855+
end Internal;
856+
828857
function checkSettings "Display some diagnostics"
829858
output CheckSettingsResult result;
830859
external "builtin";

Compiler/Script/CevalScript.mo

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ protected import Uncertainties;
109109
public constant Integer RT_CLOCK_SIMULATE_TOTAL = 8;
110110
public constant Integer RT_CLOCK_SIMULATE_SIMULATION = 9;
111111
public constant Integer RT_CLOCK_BUILD_MODEL = 10;
112-
public constant Integer RT_CLOCK_EXECSTAT_MAIN = Inst.RT_CLOCK_EXECSTAT_MAIN;
113-
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES = BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES;
112+
public constant Integer RT_CLOCK_EXECSTAT_MAIN = Inst.RT_CLOCK_EXECSTAT_MAIN /* 11 */;
113+
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES = BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES /* 12 */;
114+
public constant Integer RT_CLOCK_FRONTEND = 13;
115+
public constant Integer RT_CLOCK_BACKEND = 14;
116+
public constant Integer RT_CLOCK_SIMCODE = 15;
117+
public constant Integer RT_CLOCK_LINEARIZE = 16;
118+
public constant Integer RT_CLOCK_TEMPLATES = 17;
119+
public constant Integer RT_CLOCK_UNCERTAINTIES = 18;
120+
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};
114121

115122
protected constant DAE.Type simulationResultType_rtest = DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationResult")),{
116123
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()),
@@ -763,7 +770,7 @@ algorithm
763770
Absyn.ComponentRef cr_1;
764771
Integer size,length,resI,timeStampI,i,n;
765772
list<String> vars_1,vars_2,args,strings,strVars,strs,visvars;
766-
Real t1,t2,time,timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2;
773+
Real t1,t2,time,timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r;
767774
Interactive.Statements istmts;
768775
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;
769776
Env.Cache cache;
@@ -1213,6 +1220,8 @@ algorithm
12131220

12141221
case (cache,env,"buildModel",vals,st,msg)
12151222
equation
1223+
List.map_0(buildModelClocks,System.realtimeTick);
1224+
print("init'ed clocks\n");
12161225
(cache,compileDir,executable,method_str,outputFormat_str,st,initfilename,_) = buildModel(cache,env, vals, st, msg);
12171226
executable = Util.if_(not Config.getRunningTestsuite(),compileDir +& executable,executable);
12181227
then
@@ -1465,6 +1474,15 @@ algorithm
14651474
then
14661475
(cache,Values.INTEGER(resI),st);
14671476

1477+
case (cache,env,"readTimer",{Values.INTEGER(i)},st,msg)
1478+
equation
1479+
r = System.realtimeTock(i);
1480+
then
1481+
(cache,Values.REAL(r),st);
1482+
1483+
case (cache,env,"readTimer",_,st,msg)
1484+
then (cache,Values.REAL(-1.0),st);
1485+
14681486
case (cache,env,"regularFileExists",{Values.STRING(str)},st,msg)
14691487
equation
14701488
b = System.regularFileExists(str);

Compiler/Util/System.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,14 @@ end configureCommandLine;
642642

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

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

0 commit comments

Comments
 (0)