Skip to content

Commit

Permalink
- Add total time taken to BuildModelRecursive.mos
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11086 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 10, 2012
1 parent 0c3dc39 commit 36886ee
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
35 changes: 33 additions & 2 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -840,15 +840,46 @@ constant Integer RT_CLOCK_BACKEND = 14;
constant Integer RT_CLOCK_SIMCODE = 15;
constant Integer RT_CLOCK_LINEARIZE = 16;
constant Integer RT_CLOCK_TEMPLATES = 17;
constant Integer RT_CLOCK_UNCERTAINTIES = 18;
constant Integer RT_CLOCK_USER_RESERVED = 19;

function readTimer
function readableTime
input Real sec;
output String str;
protected
Integer tmp,min,hr;
algorithm
tmp := mod(integer(sec),60);
min := div(integer(sec),60);
hr := div(min,60);
min := mod(min,60);
str := (if hr>0 then String(hr) + "h" else "") + (if min>0 then String(min) + "m" else "") + String(tmp) + "s";
end readableTime;

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

function timerTock
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 timerTock;

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

end Time;

Expand Down
17 changes: 15 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -117,6 +117,7 @@ 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 Integer RT_CLOCK_USER_RESERVED = 19;
public constant list<Integer> buildModelClocks = {RT_CLOCK_BUILD_MODEL,RT_CLOCK_SIMULATE_TOTAL,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")),{
Expand Down Expand Up @@ -1474,14 +1475,26 @@ algorithm
then
(cache,Values.INTEGER(resI),st);

case (cache,env,"readTimer",{Values.INTEGER(i)},st,msg)
case (cache,env,"timerClear",{Values.INTEGER(i)},st,msg)
equation
System.realtimeClear(i);
then
(cache,Values.NORETCALL(),st);

case (cache,env,"timerTick",{Values.INTEGER(i)},st,msg)
equation
System.realtimeTick(i);
then
(cache,Values.NORETCALL(),st);

case (cache,env,"timerTock",{Values.INTEGER(i)},st,msg)
equation
true = System.realtimeNtick(i) > 0;
r = System.realtimeTock(i);
then
(cache,Values.REAL(r),st);

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

case (cache,env,"regularFileExists",{Values.STRING(str)},st,msg)
Expand Down
21 changes: 11 additions & 10 deletions Examples/BuildModelRecursive.mos
@@ -1,9 +1,9 @@
// Note: Run with +g=MetaModelica

OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
log:="BuildModelRecursive.html";
loadModel(Modelica,{"3.1"});

/*
deleteClass(Modelica.Blocks);
deleteClass(Modelica.Electrical);
deleteClass(Modelica.Fluid);
Expand All @@ -12,7 +12,6 @@ deleteClass(Modelica.Mechanics);
deleteClass(Modelica.Media);
deleteClass(Modelica.Thermal);
deleteClass(Modelica.Utilities);
*/

system("rm -f Modelica");
system("ln -fs '"+getInstallationDirectoryPath()+"/lib/omlibrary/Modelica 3.1/' Modelica");
Expand Down Expand Up @@ -50,13 +49,13 @@ if err <> \"\" then
end if;

echo(false);
frontend :=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_FRONTEND);
backend :=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BACKEND);
simcode :=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMCODE);
linearize:=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_LINEARIZE);
templates:=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_TEMPLATES);
total :=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMULATE_TOTAL);
build :=OpenModelica.Scripting.Internal.Time.readTimer(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BUILD_MODEL);
frontend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_FRONTEND);
backend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BACKEND);
simcode :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMCODE);
linearize:=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_LINEARIZE);
templates:=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_TEMPLATES);
total :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMULATE_TOTAL);
build :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BUILD_MODEL);
frontend :=if frontend <> -1.0 then frontend-backend else -1.0;
backend :=if backend <> -1.0 then backend-simcode else -1.0;
simcode :=if simcode <> -1.0 then simcode-linearize else -1.0;
Expand All @@ -81,8 +80,10 @@ getErrorString();
echo(false);
system("rm -f " + log);
str:="<h1>Recursive BuildModel Test</h1><p>Results: " + String(sum(if OpenModelica.Scripting.regularFileExists(s) then 1 else 0 for s in a)) + "/" + String(size(a,1)) + " succeeded</p>
<p>Total time taken: "+OpenModelica.Scripting.Internal.Time.readableTime(OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED))+"</p>
<p>OpenModelica Version: "+getVersion()+"</p>
<p>Tested Library: Modelica "+getVersion(Modelica)+"</p>";
<p>Tested Library: Modelica "+getVersion(Modelica)+"</p>
";
writeFile(log,"<html><head><title>BuildModel Results</title></head><body>" + str);
writeFile(log,"<table><tr><th>Model</th><th>Total time</th><th>Frontend</th><th>Backend</th><th>SimCode</th><th>Templates</th><th>Linearize</th><th>Compile</th>",append=true);getErrorString();
writeFile(log,sum(readFile(s + ".stat") + "\n" for s in a),append=true);getErrorString();
Expand Down

0 comments on commit 36886ee

Please sign in to comment.