Skip to content

Commit e55546c

Browse files
committed
- Added better output when doing time measurements of simulations.
- For now, I use xsltproc and gnuplot for transforming an xml representation of the time measurement (in addition to png thumbnails and svg plots) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8051 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 42a3a82 commit e55546c

16 files changed

+529
-322
lines changed

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,76 +1166,5 @@ function plotParametric2 "Plots the y-variables as a function of the x-variable.
11661166
external "builtin";
11671167
end plotParametric2;
11681168

1169-
function getBuiltinAttribute
1170-
input String attribute;
1171-
input VariableName var;
1172-
input TypeName cl;
1173-
output String value;
1174-
external "builtin";
1175-
end getBuiltinAttribute;
1176-
1177-
function getUnit
1178-
input VariableName var;
1179-
input TypeName cl;
1180-
output String unit;
1181-
external "builtin" unit=getBuiltinAttribute("unit",cl,var);
1182-
end getUnit;
1183-
1184-
function getQuantity
1185-
input VariableName var;
1186-
input TypeName cl;
1187-
output String quantity;
1188-
external "builtin" quantity=getBuiltinAttribute("quantity",cl,var);
1189-
end getQuantity;
1190-
1191-
function getDisplayUnit
1192-
input VariableName var;
1193-
input TypeName cl;
1194-
output String displayUnit;
1195-
external "builtin" displayUnit=getBuiltinAttribute("displayUnit",cl,var);
1196-
end getDisplayUnit;
1197-
1198-
function getMin
1199-
input VariableName var;
1200-
input TypeName cl;
1201-
output String min;
1202-
external "builtin" min=getBuiltinAttribute("min",cl,var);
1203-
end getMin;
1204-
1205-
function getMax
1206-
input VariableName var;
1207-
input TypeName cl;
1208-
output String max;
1209-
external "builtin" max=getBuiltinAttribute("max",cl,var);
1210-
end getMax;
1211-
1212-
function getStart
1213-
input VariableName var;
1214-
input TypeName cl;
1215-
output String start;
1216-
external "builtin" start=getBuiltinAttribute("start",cl,var);
1217-
end getStart;
1218-
1219-
function getFixed
1220-
input VariableName var;
1221-
input TypeName cl;
1222-
output String fixed; // Boolean?
1223-
external "builtin" fixed=getBuiltinAttribute("fixed",cl,var);
1224-
end getFixed;
1225-
1226-
function getNominal
1227-
input VariableName var;
1228-
input TypeName cl;
1229-
output String nominal; // Real?
1230-
external "builtin" nominal=getBuiltinAttribute("nominal",cl,var);
1231-
end getNominal;
1232-
1233-
function getStateSelect
1234-
input VariableName var;
1235-
input TypeName cl;
1236-
output String stateSelect; // StateSelect output?
1237-
external "builtin" stateSelect=getBuiltinAttribute("stateSelect",cl,var);
1238-
end getStateSelect;
1239-
12401169
end Scripting;
12411170
end OpenModelica;

Compiler/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PROG = omc
3434
PROGD = omcd
3535
PROGP = omcp
3636

37-
SCRIPT_FILES = Compile doPlot openmodelica.lefty convert_lines.pl
37+
SCRIPT_FILES = Compile doPlot openmodelica.lefty convert_lines.pl default_profiling.xsl
3838

3939
#SUBDIRS= ast runtime
4040
SUBDIRS = runtime modpar

Compiler/Script/CevalScript.mo

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,13 +1424,6 @@ algorithm
14241424
Values.STRING(confcmd)};
14251425
then (cache,Values.RECORD(Absyn.IDENT("OpenModelica.Scripting.CheckSettingsResult"),vals,vars_1,-1),st);
14261426

1427-
case (cache,env,"getBuiltinAttribute",{Values.STRING(str),Values.CODE(Absyn.C_VARIABLENAME(cr_1)),Values.CODE(Absyn.C_TYPENAME(path))},st,msg)
1428-
equation
1429-
(cache,v,st_1) = getBuiltinAttribute(cache,path,ComponentReference.toExpCref(cr_1),str,st);
1430-
then
1431-
(cache,v,st_1);
1432-
1433-
14341427
case (cache,env,"readSimulationResult",{Values.STRING(filename),Values.ARRAY(valueLst=cvars),Values.INTEGER(size)},st,msg)
14351428
equation
14361429
vars_1 = Util.listMap(cvars, ValuesUtil.printCodeVariableName);
@@ -3000,125 +2993,6 @@ algorithm
30002993
end matchcontinue;
30012994
end selectIfNotEmpty;
30022995

3003-
protected function getBuiltinAttribute "function: getBuiltinAttribute
3004-
Retrieves a builtin attribute of a variable in a class by instantiating
3005-
the class and retrieving the attribute value from the flat variable."
3006-
input Env.Cache inCache;
3007-
input Absyn.Path classname;
3008-
input DAE.ComponentRef inComponentRef2;
3009-
input String inString3;
3010-
input Interactive.InteractiveSymbolTable inInteractiveSymbolTable4;
3011-
output Env.Cache outCache;
3012-
output Values.Value outValue;
3013-
output Interactive.InteractiveSymbolTable outInteractiveSymbolTable;
3014-
algorithm
3015-
(outCache,outValue,outInteractiveSymbolTable):=
3016-
matchcontinue (inCache,classname,inComponentRef2,inString3,inInteractiveSymbolTable4)
3017-
local
3018-
DAE.DAElist dae,dae1;
3019-
list<Env.Frame> env,env_1,env3,env4;
3020-
DAE.ComponentRef cref_1,cref;
3021-
DAE.Attributes attr;
3022-
tuple<DAE.TType, Option<Absyn.Path>> ty;
3023-
DAE.Exp exp;
3024-
String str,n,attribute;
3025-
Interactive.InteractiveSymbolTable st;
3026-
Absyn.Program p,ptot;
3027-
list<SCode.Class> sp,p_1;
3028-
list<Interactive.InstantiatedClass> ic,ic_1;
3029-
list<Interactive.InteractiveVariable> vars;
3030-
list<Interactive.CompiledCFunction> cf;
3031-
SCode.Class c;
3032-
Boolean encflag;
3033-
SCode.Restriction r;
3034-
ClassInf.State ci_state,ci_state_1;
3035-
Connect.Sets csets_1;
3036-
list<DAE.Var> tys;
3037-
Values.Value v;
3038-
Env.Cache cache;
3039-
list<Interactive.LoadedFile> lf;
3040-
AbsynDep.Depends aDep;
3041-
case (cache,classname,cref,"stateSelect",
3042-
(st as Interactive.SYMBOLTABLE(
3043-
ast = p,
3044-
explodedAst = sp,
3045-
instClsLst = ic,
3046-
lstVarVal = vars,
3047-
compiledFunctions = cf)))
3048-
equation
3049-
Interactive.INSTCLASS(_,dae,env) = Interactive.getInstantiatedClass(ic, classname);
3050-
cref_1 = ComponentReference.joinCrefs(cref, ComponentReference.makeCrefIdent("stateSelect",DAE.ET_OTHER(),{}));
3051-
(cache,attr,ty,DAE.EQBOUND(exp,_,_,_),_,_,_,_,_) = Lookup.lookupVar(cache, env, cref_1);
3052-
str = ExpressionDump.printExpStr(exp);
3053-
then
3054-
(cache,Values.STRING(str),st);
3055-
3056-
case (cache,classname,cref,"stateSelect",
3057-
Interactive.SYMBOLTABLE(
3058-
ast = p,
3059-
depends = aDep,
3060-
explodedAst = sp,
3061-
instClsLst = ic,
3062-
lstVarVal = vars,
3063-
compiledFunctions = cf,
3064-
loadedFiles = lf))
3065-
equation
3066-
ptot = Dependency.getTotalProgram(classname,p);
3067-
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
3068-
(cache,env) = Inst.makeEnvFromProgram(cache,p_1, Absyn.IDENT(""));
3069-
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env,classname,true);
3070-
env3 = Env.openScope(env_1, encflag, SOME(n), SOME(Env.CLASS_SCOPE()));
3071-
ci_state = ClassInf.start(r, Env.getEnvName(env3));
3072-
(cache,env4,_,_,dae1,csets_1,ci_state_1,tys,_,_,_,_) = Inst.instClassIn(cache,env3, InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
3073-
ci_state, c, false, {}, false, Inst.INNER_CALL(), ConnectionGraph.EMPTY,NONE());
3074-
cref_1 = ComponentReference.crefPrependIdent(cref, "stateSelect",{},DAE.ET_OTHER());
3075-
(cache,attr,ty,DAE.EQBOUND(exp,_,_,_),_,_,_,_,_) = Lookup.lookupVar(cache, env4, cref_1);
3076-
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dae1,env4));
3077-
str = ExpressionDump.printExpStr(exp);
3078-
then
3079-
(cache,Values.STRING(str),Interactive.SYMBOLTABLE(p,aDep,sp,ic_1,vars,cf,lf));
3080-
3081-
case (cache,classname,cref,attribute,
3082-
(st as Interactive.SYMBOLTABLE(
3083-
ast = p,
3084-
explodedAst = sp,
3085-
instClsLst = ic,
3086-
lstVarVal = vars,
3087-
compiledFunctions = cf)))
3088-
equation
3089-
Interactive.INSTCLASS(_,dae,env) = Interactive.getInstantiatedClass(ic, classname);
3090-
cref_1 = ComponentReference.crefPrependIdent(cref, attribute,{},DAE.ET_OTHER());
3091-
(cache,attr,ty,DAE.VALBOUND(v,_),_,_,_,_,_) = Lookup.lookupVar(cache, env, cref_1);
3092-
then
3093-
(cache,v,st);
3094-
3095-
case (cache,classname,cref,attribute,
3096-
(st as Interactive.SYMBOLTABLE(
3097-
ast = p,
3098-
depends = aDep,
3099-
explodedAst = sp,
3100-
instClsLst = ic,
3101-
lstVarVal = vars,
3102-
compiledFunctions = cf,
3103-
loadedFiles = lf)))
3104-
equation
3105-
ptot = Dependency.getTotalProgram(classname,p);
3106-
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
3107-
(cache,env) = Inst.makeEnvFromProgram(cache,p_1, Absyn.IDENT(""));
3108-
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env,classname,true);
3109-
env3 = Env.openScope(env_1, encflag, SOME(n), SOME(Env.CLASS_SCOPE()));
3110-
ci_state = ClassInf.start(r, Env.getEnvName(env3));
3111-
(cache,env4,_,_,dae1,csets_1,ci_state_1,tys,_,_,_,_) = Inst.instClassIn(cache,env3, InnerOuter.emptyInstHierarchy, UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
3112-
ci_state, c, false, {}, false, Inst.INNER_CALL(), ConnectionGraph.EMPTY,NONE());
3113-
cref_1 = ComponentReference.crefPrependIdent(cref,attribute,{},DAE.ET_OTHER());
3114-
(cache,attr,ty,DAE.VALBOUND(v,_),_,_,_,_,_) = Lookup.lookupVar(cache, env4, cref_1);
3115-
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dae1,env4));
3116-
then
3117-
(cache,v,Interactive.SYMBOLTABLE(p,aDep,sp,ic_1,vars,cf,lf));
3118-
3119-
end matchcontinue;
3120-
end getBuiltinAttribute;
3121-
31222996
protected function setBuildTime "sets the build time of a class.
31232997
This is done using traverseClasses and not using updateProgram,
31242998
because updateProgram updates edit times"
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE xsl:stylesheet [
4+
<!ENTITY nbsp "&#xa0;"> <!--known for HTML output, not in XML-->
5+
]>
6+
7+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" >
8+
9+
<xsl:template match="/simulation">
10+
<html>
11+
<head>
12+
<title>TITLE</title>
13+
<style type="text/css">
14+
table {border-style: solid;border-spacing: 0;}
15+
th {
16+
padding: 6px;
17+
text-align: right;
18+
border-style: solid;
19+
border-width: 0 0 1px 1px;
20+
}
21+
th.name {text-align: left;}
22+
td {
23+
padding: 6px;
24+
text-align: right;
25+
border-style: solid;
26+
border-width: 0 0 1px 1px;
27+
}
28+
td.name {text-align: left;}
29+
img.thumb {width: 32px;}
30+
abbr {border-bottom:1px dotted;}
31+
a img {border: 1px solid black;}
32+
</style>
33+
</head>
34+
35+
<body>
36+
<h1>Model information for <xsl:value-of select="modelinfo/name"/></h1>
37+
38+
<h2>Information</h2>
39+
<p>All times are measured using a real-time wall clock. This means context switching produces bad worst-case execution times (max times) for blocks. If you want better results, use a CPU-time clock or run the command using real-time priviliges (avoiding context switches).</p>
40+
<p>Note that for blocks where the individual execution time is close to the accuracy of the real-time clock, the maximum measured time may deviate a lot from the average.</p>
41+
<p>For more details, see <a href="{modelinfo/prefix}_prof.csv"><xsl:value-of select="modelinfo/name"/>_prof.csv</a>.</p>
42+
43+
<h2>Summary</h2>
44+
<p>What solver/settings were used?</p>
45+
<table>
46+
<tr><th class="name">Task</th><th>Time</th><th><abbr title="Fraction of total simulation time">Fraction</abbr></th></tr>
47+
<tr><td class="name"><abbr title="Choosing solver, allocating data structures, etc (does not include reading the parameter start-values from file)">Pre-Initialization</abbr></td><td><xsl:value-of select="modelinfo/preinitTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/preinitTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
48+
<tr><td class="name">Initialization</td><td><xsl:value-of select="modelinfo/initTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/initTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
49+
<tr><td class="name">Event-handling</td><td><xsl:value-of select="modelinfo/eventTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/eventTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
50+
<tr><td class="name">Creating output file</td><td><xsl:value-of select="modelinfo/outputTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/outputTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
51+
<tr><td class="name">Linearization</td><td><xsl:value-of select="modelinfo/linearizeTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/linearizeTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
52+
<tr><td class="name">Time steps (incl.integration?)</td><td><xsl:value-of select="modelinfo/totalStepsTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/totalStepsTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
53+
<tr><td class="name">Overhead</td><td><xsl:value-of select="modelinfo/overheadTime"/></td><td><xsl:value-of select="format-number(100 * modelinfo/overheadTime div modelinfo/totalTime,'##0.00')"/>%</td></tr>
54+
<tr><td class="name">Unknown</td><td><xsl:value-of select="modelinfo/totalTime - modelinfo/overheadTime - modelinfo/totalStepsTime - modelinfo/linearizeTime - modelinfo/outputTime - modelinfo/eventTime - modelinfo/initTime"/></td>
55+
<td><xsl:value-of select="format-number(100 * (modelinfo/totalTime - modelinfo/overheadTime - modelinfo/totalStepsTime - modelinfo/linearizeTime - modelinfo/outputTime - modelinfo/eventTime - modelinfo/initTime - modelinfo/preinitTime) div modelinfo/totalTime,'##0.00')"/>%</td></tr>
56+
<tr><td class="name">Total simulation time</td><td><xsl:value-of select="modelinfo/totalTime"/></td><td>100.00%</td></tr>
57+
</table>
58+
59+
<h2>Global Steps</h2>
60+
<table>
61+
<tr><th>&nbsp;</th><th>Steps</th><th>Total Time</th><th><abbr title="Fraction of total simulation time">Fraction</abbr></th><th>Average Time</th><th><abbr title="The maximum accumulated time of this action during a single time step">Max Time</abbr></th><th><abbr title="Deviation from average execution time">Deviation</abbr></th></tr>
62+
<tr>
63+
<td><a href="{modelinfo/prefix}_prof.999.svg"><img class="thumb" src="{modelinfo/prefix}_prof.999.thumb.png" alt="Graph thumbnail" /></a></td>
64+
<td><xsl:value-of select="modelinfo/numStep"/></td>
65+
<td><xsl:value-of select="modelinfo/totalStepsTime"/></td>
66+
<td><xsl:value-of select="format-number(100 * modelinfo/totalStepsTime div modelinfo/totalTime,'##0.00')"/>%</td>
67+
<td><xsl:value-of select="modelinfo/totalStepsTime div modelinfo/numStep"/></td>
68+
<td><xsl:value-of select="modelinfo/maxTime"/></td>
69+
<td><xsl:value-of select="format-number((modelinfo/numStep * modelinfo/maxTime div modelinfo/totalStepsTime)-1,'##0.00')"/>x</td>
70+
</tr>
71+
</table>
72+
73+
<h2>Measured Function Calls</h2>
74+
<table>
75+
<tr><th>&nbsp;</th><th class="name">Name</th><th>Calls</th><th>Time</th><th><abbr title="Fraction of total simulation time">Fraction</abbr></th><th><abbr title="The maximum accumulated time of this action during a single time step">Max Time</abbr></th><th><abbr title="Deviation from average execution time">Deviation</abbr></th></tr>
76+
<xsl:for-each select="functions/function">
77+
<tr>
78+
<td><a href="{//simulation/modelinfo/prefix}_prof.{@id}.svg"><img class="thumb" src="{//simulation/modelinfo/prefix}_prof.{@id}.thumb.png" alt="Graph thumbnail" /></a></td>
79+
<td class="name"><a href="{info/@filename}#line={info/@startline}"><xsl:value-of select="name"/></a></td>
80+
<td><xsl:value-of select="ncall"/></td>
81+
<td><xsl:value-of select="time"/></td>
82+
<td><xsl:value-of select="format-number(100 * time div /simulation/modelinfo/totalTime,'##0.00')"/>%</td>
83+
<td><xsl:value-of select="maxTime"/></td>
84+
<td><xsl:value-of select="format-number((ncall * maxTime div time)-1,'##0.00')"/>x</td>
85+
</tr>
86+
</xsl:for-each>
87+
</table>
88+
89+
<h2>Measured Blocks</h2>
90+
<table>
91+
<tr><th>&nbsp;</th><th class="name">Name</th><th>Calls</th><th>Time</th><th><abbr title="Fraction of total simulation time">Fraction</abbr></th><th><abbr title="The maximum accumulated time of this action during a single time step">Max Time</abbr></th><th><abbr title="Deviation from average execution time">Deviation</abbr></th></tr>
92+
<xsl:for-each select="profileblocks/profileblock">
93+
<tr>
94+
<td><a href="{//simulation/modelinfo/prefix}_prof.{ref/@refid}.svg"><img class="thumb" src="{//simulation/modelinfo/prefix}_prof.{ref/@refid}.thumb.png" alt="Graph thumbnail" /></a></td>
95+
<td class="name"><a href="#{ref/@refid}"><xsl:value-of select="id(ref/@refid)/@name"/></a></td>
96+
<td><xsl:value-of select="ncall"/></td>
97+
<td><xsl:value-of select="time"/></td>
98+
<td><xsl:value-of select="format-number(100 * time div /simulation/modelinfo/totalTime,'##0.00')"/>%</td>
99+
<td><xsl:value-of select="maxTime"/></td>
100+
<td><xsl:value-of select="format-number((ncall * maxTime div time)-1,'##0.00')"/>x</td>
101+
</tr>
102+
</xsl:for-each>
103+
</table>
104+
105+
<h3>Equations</h3>
106+
<table>
107+
<tr><th class="name">Name</th><th>Variables</th></tr>
108+
<xsl:for-each select="equations/equation">
109+
<tr><td class="name"><a name="{@id}"><xsl:value-of select="@name"/></a></td>
110+
<td><xsl:choose>
111+
<xsl:when test="count(refs/ref)=0">&nbsp;</xsl:when>
112+
<xsl:otherwise><xsl:for-each select="refs/ref"><a href="#{@refid}"><xsl:value-of select="id(@refid)/@name"/></a><xsl:if test="position() != last()">, </xsl:if>
113+
</xsl:for-each></xsl:otherwise>
114+
</xsl:choose></td>
115+
</tr>
116+
</xsl:for-each>
117+
</table>
118+
119+
<h3>Variables</h3>
120+
<table>
121+
<tr><th class="name">Name</th><th>Comment</th></tr>
122+
<xsl:for-each select="variables/variable">
123+
<tr>
124+
<td class="name"><a name="{@id}" href="{info/@filename}#line={info/@startline}"><xsl:value-of select="@name"/></a></td>
125+
<td><xsl:choose>
126+
<xsl:when test="string-length(@comment)=0">&nbsp;</xsl:when>
127+
<xsl:otherwise><xsl:value-of select="@comment"/></xsl:otherwise>
128+
</xsl:choose></td></tr>
129+
</xsl:for-each>
130+
</table>
131+
132+
<hr />
133+
<p>
134+
This report was generated by <a href="http://openmodelica.org">OpenModelica</a> on <xsl:value-of select="modelinfo/date"/>.
135+
</p>
136+
137+
</body>
138+
139+
</html>
140+
141+
</xsl:template>
142+
143+
</xsl:stylesheet>

0 commit comments

Comments
 (0)