forked from sofa-framework/sofa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PythonAdvancedTimer.py
42 lines (37 loc) · 1.31 KB
/
PythonAdvancedTimer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
import Sofa
# ploting
import matplotlib.pyplot as plt
# JSON deconding
from collections import OrderedDict
import json
# argument parser: usage via the command line
import argparse
def measureAnimationTime(node, timerName, timerInterval, timerOutputType, resultFileName, simulationDeltaTime, iterations):
# timer
Sofa.timerSetInterval(timerName, timerInterval) # Set the number of steps neded to compute the timer
Sofa.timerSetEnabled(timerName, True)
resultFileName = resultFileName + ".log"
rootNode = node.getRoot()
with open(resultFileName, "w+") as outputFile :
outputFile.write("{")
i = 0
Sofa.timerSetOutPutType(timerName, timerOutputType)
while i < iterations:
Sofa.timerBegin(timerName)
rootNode.simulationStep(simulationDeltaTime)
result = Sofa.timerEnd(timerName, rootNode)
if result != None :
outputFile.write(result + ",")
oldResult = result
i = i+1
last_pose = outputFile.tell()
outputFile.seek(last_pose - 1)
outputFile.write("\n}")
outputFile.seek(7)
firstStep = outputFile.read(1)
outputFile.close()
Sofa.timerSetEnabled(timerName, 0)
print "[Scene info]: end of simulation."
return 0