Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,29 @@
class TimeoutError(Exception):
pass

runningPhase = None
"""What is running now, as (key of execstat, when it started).

A command the watchdog has to kill never returns to its caller -
sendExpressionTimeout ends the process itself - so the caller's own timeout
handler does not run and the phase reports no time at all. Recording it here
instead covers every way out, because they all write the results first.
"""

def phaseStarts(key):
global runningPhase
runningPhase = (key, monotonic())

def phaseEnded():
global runningPhase
runningPhase = None

def writeResult():
if runningPhase is not None:
(key, started) = runningPhase
# Only if the phase did not get to report its own time.
if not execstat.get(key):
execstat[key] = monotonic() - started
with open(statFile, 'w') as fp:
json.dump(execstat, fp)
fp.flush()
Expand Down Expand Up @@ -447,19 +469,28 @@ def simulateCmd(resimulate):
total_before = omc.sendExpression("OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMULATE_TOTAL)")
start=monotonic()
timeout = conf["ulimitOmc"]
# If the command has to be killed there is no way to tell which phase it was in,
# so its time is charged to what the command itself is: building an FMU to the
# build, simulating to the simulation, translating to the front end - which is
# also the phase such a model is reported as having failed in.
if conf.get("fmi"):
cmd='"" <> buildModelFMU(%s,fileNamePrefix="%s",fmuType="%s",version="%s",platforms={"static"})' % (conf["modelName"],conf["fileName"].replace(".","_"),conf["fmuType"],conf["fmi"])
timedPhase = "build"
elif useSimulate:
cmd=simulateCmd(resimulate=False)
timeout = conf["ulimitOmc"] + conf["ulimitExe"]
timedPhase = "sim"
else:
cmd='translateModel(%s,tolerance=%g,outputFormat="%s",numberOfIntervals=%d,variableFilter="%s",fileNamePrefix="%s")' % (conf["modelName"],tolerance,outputFormat,numberOfIntervals,variableFilter,conf["fileName"])
timedPhase = "frontend"
with open(errFile, 'a+') as fp:
fp.write("Running command: %s\n"%(cmd))
try:
phaseStarts(timedPhase)
res=sendExpressionTimeout(omc, cmd, timeout)
phaseEnded()
except TimeoutError as e:
execstat["frontend"]=monotonic()-start
execstat[timedPhase]=monotonic()-start

with open(errFile, 'a+') as fp:
fp.write("Timeout error for cmd: %s\n%s"%(cmd,str(e)))
Expand Down
Loading