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

Source Code for Module PyFoam.LogAnalysis.ExecutionTimeLineAnalyzer

  1  #  ICE Revision: $Id: ExecutionTimeLineAnalyzer.py 8285 2007-12-10 15:11:39Z 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()>=(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,doTimelines=True,doFiles=True):
26 self.hasClock=(foamVersionNumber()>=(1,3)) 27 titles=["cumulated"] 28 if self.hasClock: 29 titles.append("delta") 30 31 GeneralLineAnalyzer.__init__(self,titles=titles,doTimelines=doTimelines,doFiles=doFiles) 32 self.exp=re.compile(executionRegexp()) 33 34 self.exp=re.compile(executionRegexp()) 35 36 self.lastTime=0. 37 self.time=0. 38 if self.hasClock: 39 self.lastClock=0. 40 self.clock=0. 41 42 self.first=True; 43 self.firstTime=0. 44 if self.hasClock: 45 self.firstClock=0.
46
47 - def startAnalysis(self,match):
48 self.time=float(match.group(1)) 49 if self.hasClock: 50 self.clock=float(match.group(2))
51
52 - def endAnalysis(self,match):
53 self.lastTime = self.time 54 if self.first: 55 self.firstTime=self.time 56 57 if self.hasClock: 58 self.lastClock = self.clock 59 if self.first: 60 self.firstClock=self.clock 61 62 self.first=False
63
64 - def addToFiles(self,match):
65 self.files.write("executionTime",self.parent.getTime(),(self.time,self.time-self.lastTime)) 66 67 if self.hasClock: 68 self.files.write("wallClockTime",self.parent.getTime(),(self.clock,self.clock-self.lastClock))
69
70 - def addToTimelines(self,match):
71 self.lines.setValue("cpu",self.time-self.lastTime) 72 73 if self.hasClock: 74 self.lines.setValue("clock",self.clock-self.lastClock)
75
76 - def clockFirst(self):
77 """Returns the Wall-Clock-Time of the first timestep""" 78 if self.hasClock: 79 return self.firstClock 80 else: 81 return None
82
83 - def clockTotal(self):
84 """Returns the total Wall-Clock-Time""" 85 if self.hasClock: 86 return self.clock 87 else: 88 return None
89
90 - def timeFirst(self):
91 """Returns the CPU-Time of the first timestep""" 92 return self.firstTime
93
94 - def timeTotal(self):
95 """Returns the total CPU-Time""" 96 return self.time
97 98
99 -class ExecutionTimeLineAnalyzer(GeneralExecutionLineAnalyzer):
100 """Parses lines for the execution time""" 101
102 - def __init__(self):
103 GeneralExecutionLineAnalyzer.__init__(self,doTimelines=False)
104 105 ## self.exp=re.compile(executionRegexp()) 106 ## self.lastTime=0. 107 108 ## def doAnalysis(self,line): 109 ## """Writes total execution time and time needed since last 110 ## time-step""" 111 ## m=self.exp.match(line) 112 ## if m!=None: 113 ## time=float(m.group(1)) 114 115 ## self.files.write("executionTime",self.parent.getTime(),(time,time-self.lastTime)) 116 117 ## self.lastTime = time 118
119 -class TimeLineExecutionTimeLineAnalyzer(GeneralExecutionLineAnalyzer):
120 """Parses lines for the execution time""" 121
122 - def __init__(self):
123 GeneralExecutionLineAnalyzer.__init__(self,doFiles=False)
124 125 ## self.hasClock=(foamVersionNumber()>=(1,3)) 126 127 ## self.exp=re.compile(executionRegexp()) 128 129 ## self.lastTime=0. 130 ## if self.hasClock: 131 ## self.lastClock=0. 132 133 ## def doAnalysis(self,line): 134 ## """Writes total execution time and time needed since last 135 ## time-step""" 136 ## m=self.exp.match(line) 137 ## if m!=None: 138 ## time=float(m.group(1)) 139 ## if self.hasClock: 140 ## clock=float(m.group(2)) 141 142 ## self.lines.setValue("cpu",time-self.lastTime) 143 ## self.lastTime = time 144 145 ## if self.hasClock: 146 ## self.lines.setValue("clock",clock-self.lastClock) 147 ## self.lastClock = clock 148