Package PyFoam :: Package LogAnalysis :: Module ExecutionTimeLineAnalyzer
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.LogAnalysis.ExecutionTimeLineAnalyzer

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/LogAnalysis/ExecutionTimeLineAnalyzer.py 6298 2010-04-02T12:51:05.772488Z bgschaid  $  
  2  """Check for Execution-Time information""" 
  3   
  4  import re 
  5   
6 -def executionRegexp():
7 """@Return: The regular expression that parses the execution time 8 depending on the OpenFOAM-Version""" 9 10 if foamVersionNumber(useConfigurationIfNoInstallation=True)>=(1,3): 11 return "^ExecutionTime = (.+) s ClockTime = (.+) s$" 12 else: 13 return "^ExecutionTime = (.+) s$"
14 15 # from FileLineAnalyzer import FileLineAnalyzer 16 # from TimeLineLineAnalyzer import TimeLineLineAnalyzer 17 18 from GeneralLineAnalyzer import GeneralLineAnalyzer 19 20 from PyFoam.FoamInformation import foamVersionNumber 21
22 -class GeneralExecutionLineAnalyzer(GeneralLineAnalyzer):
23 """Parses lines for the execution time""" 24
25 - def __init__(self, 26 doTimelines=True, 27 doFiles=True, 28 singleFile=False, 29 startTime=None, 30 endTime=None):
31 self.hasClock=(foamVersionNumber()>=(1,3)) 32 titles=["cumulated"] 33 if self.hasClock: 34 titles.append("delta") 35 36 GeneralLineAnalyzer.__init__(self, 37 titles=titles, 38 doTimelines=doTimelines, 39 doFiles=doFiles, 40 singleFile=singleFile, 41 startTime=startTime, 42 endTime=endTime) 43 44 self.exp=re.compile(executionRegexp()) 45 46 self.exp=re.compile(executionRegexp()) 47 48 self.lastTime=0. 49 self.time=0. 50 if self.hasClock: 51 self.lastClock=0. 52 self.clock=0. 53 54 self.first=True; 55 self.firstTime=0. 56 if self.hasClock: 57 self.firstClock=0.
58
59 - def startAnalysis(self,match):
60 self.time=float(match.group(1)) 61 if self.hasClock: 62 self.clock=float(match.group(2))
63
64 - def endAnalysis(self,match):
65 self.lastTime = self.time 66 if self.first: 67 self.firstTime=self.time 68 69 if self.hasClock: 70 self.lastClock = self.clock 71 if self.first: 72 self.firstClock=self.clock 73 74 self.first=False
75
76 - def addToFiles(self,match):
77 self.files.write("executionTime",self.parent.getTime(),(self.time,self.time-self.lastTime)) 78 79 if self.hasClock: 80 self.files.write("wallClockTime",self.parent.getTime(),(self.clock,self.clock-self.lastClock))
81
82 - def addToTimelines(self,match):
83 self.lines.setValue("cpu",self.time-self.lastTime) 84 85 if self.hasClock: 86 self.lines.setValue("clock",self.clock-self.lastClock)
87
88 - def clockFirst(self):
89 """Returns the Wall-Clock-Time of the first timestep""" 90 if self.hasClock: 91 return self.firstClock 92 else: 93 return None
94
95 - def clockTotal(self):
96 """Returns the total Wall-Clock-Time""" 97 if self.hasClock: 98 return self.clock 99 else: 100 return None
101
102 - def timeFirst(self):
103 """Returns the CPU-Time of the first timestep""" 104 return self.firstTime
105
106 - def timeTotal(self):
107 """Returns the total CPU-Time""" 108 return self.time
109 110
111 -class ExecutionTimeLineAnalyzer(GeneralExecutionLineAnalyzer):
112 """Parses lines for the execution time""" 113
114 - def __init__(self):
115 GeneralExecutionLineAnalyzer.__init__(self,doTimelines=False)
116 117 ## self.exp=re.compile(executionRegexp()) 118 ## self.lastTime=0. 119 120 ## def doAnalysis(self,line): 121 ## """Writes total execution time and time needed since last 122 ## time-step""" 123 ## m=self.exp.match(line) 124 ## if m!=None: 125 ## time=float(m.group(1)) 126 127 ## self.files.write("executionTime",self.parent.getTime(),(time,time-self.lastTime)) 128 129 ## self.lastTime = time 130
131 -class TimeLineExecutionTimeLineAnalyzer(GeneralExecutionLineAnalyzer):
132 """Parses lines for the execution time""" 133
134 - def __init__(self):
135 GeneralExecutionLineAnalyzer.__init__(self,doFiles=False)
136 137 ## self.hasClock=(foamVersionNumber()>=(1,3)) 138 139 ## self.exp=re.compile(executionRegexp()) 140 141 ## self.lastTime=0. 142 ## if self.hasClock: 143 ## self.lastClock=0. 144 145 ## def doAnalysis(self,line): 146 ## """Writes total execution time and time needed since last 147 ## time-step""" 148 ## m=self.exp.match(line) 149 ## if m!=None: 150 ## time=float(m.group(1)) 151 ## if self.hasClock: 152 ## clock=float(m.group(2)) 153 154 ## self.lines.setValue("cpu",time-self.lastTime) 155 ## self.lastTime = time 156 157 ## if self.hasClock: 158 ## self.lines.setValue("clock",clock-self.lastClock) 159 ## self.lastClock = clock 160