2 from builtins
import range
3 from itertools
import groupby
4 from operator
import attrgetter,itemgetter
7 from collections
import defaultdict
11 To Use: Add the ModuleAllocMonitor Service to the cmsRun job use something like this 14 process.add_(cms.Service("ModuleAllocMonitor", fileName = cms.untracked.string("moduleAlloc.log"))) 16 After running the job, execute this script and pass the name of the 17 ModuleAllocMonitor log file to the script. 19 This script will output a more human readable form of the data in the log file.''' 47 kMicroToSec = 0.000001
49 kSourceFindEvent =
"sourceFindEvent" 50 kSourceDelayedRead =
"sourceDelayedRead" 52 kLargestLumiNumber = 4294967295
59 writeProcessBlock = -10
73 accessInputProcessBlock = 8
80 getNextTransition = 15
93 activityNames_ = { Activity.prefetch :
'prefetch',
94 Activity.acquire :
'acquire',
95 Activity.process :
'process',
96 Activity.delayedGet :
'delayedGet',
97 Activity.externalWork :
'externalWork' }
100 return activityNames_[activity]
102 transitionToNames_ = {
103 Phase.startTracing:
'start tracing',
104 Phase.construction:
'construction',
105 Phase.destruction:
'destruction',
106 Phase.beginJob:
'begin job',
107 Phase.endJob:
'end job',
108 Phase.beginStream:
'begin stream',
109 Phase.endStream:
'end stream',
110 Phase.beginProcessBlock:
'begin process block',
111 Phase.endProcessBlock:
'end process block',
112 Phase.accessInputProcessBlock:
'access input process block',
113 Phase.writeProcessBlock:
'write process block',
114 Phase.globalBeginRun:
'global begin run',
115 Phase.globalEndRun:
'global end run',
116 Phase.globalWriteRun:
'global write run',
117 Phase.streamBeginRun:
'stream begin run',
118 Phase.streamEndRun:
'stream end run',
119 Phase.globalBeginLumi:
'global begin lumi',
120 Phase.globalEndLumi:
'global end lumi',
121 Phase.globalWriteLumi:
'global write lumi',
122 Phase.streamBeginLumi:
'stream begin lumi',
123 Phase.streamEndLumi:
'stream end lumi',
124 Phase.esSyncEnqueue:
'EventSetup synchronization',
125 Phase.esSync:
'EventSetup synchronization',
126 Phase.Event:
'event',
127 Phase.clearEvent:
'clear event',
128 Phase.getNextTransition:
'get next transition',
129 Phase.openFile :
"open file" 133 return transitionToNames_[transition]
135 transitionToIndent_ = {
136 Phase.startTracing: 0,
137 Phase.construction: 0,
138 Phase.destruction: 0,
141 Phase.beginStream: 0,
143 Phase.beginProcessBlock: 1,
144 Phase.endProcessBlock: 1,
145 Phase.accessInputProcessBlock: 1,
146 Phase.writeProcessBlock: 1,
147 Phase.globalBeginRun: 1,
148 Phase.globalEndRun: 1,
149 Phase.globalWriteRun: 1,
150 Phase.streamBeginRun: 1,
151 Phase.streamEndRun: 1,
152 Phase.globalBeginLumi: 2,
153 Phase.globalEndLumi: 2,
154 Phase.globalWriteLumi: 2,
155 Phase.streamBeginLumi: 2,
156 Phase.streamEndLumi: 2,
159 Phase.esSyncEnqueue: 1,
161 Phase.getNextTransition: 1
164 return transitionToIndent_[transition]
166 globalTransitions_ = {
172 Phase.beginProcessBlock,
173 Phase.endProcessBlock,
174 Phase.accessInputProcessBlock,
175 Phase.writeProcessBlock,
176 Phase.globalBeginRun,
178 Phase.globalWriteRun,
179 Phase.globalBeginLumi,
181 Phase.globalWriteLumi,
184 Phase.getNextTransition,
188 return transition
in globalTransitions_;
192 return f
'{time:>11} '+
"++"*indentLevel
203 transition[
"nAllocs"]=self.
nAllocs 205 transition[
"added"]=self.
added 206 transition[
"minTemp"]=self.
minTemp 207 transition[
"maxTemp"]=self.
maxTemp 210 return "{{'nAlloc': {}, 'nDealloc': {}, 'added': {}, 'minTemp': {}, 'maxTemp': {}, 'max1Alloc': {} }}".
format(self.
nAllocs, self.
nDeallocs, self.
added, self.
minTemp, self.
maxTemp, self.
max1Alloc)
220 while len(self.
_runs) <= index:
222 self.
_runs[index] = runNumber
224 return self.
_runs[index]
225 def setLumi(self, index, runNumber, lumiNumber):
226 while len(self.
_lumis) <= index:
228 self.
_lumis[index] = (runNumber, lumiNumber)
231 def setStream(self, index, runNumber, lumiNumber, eventNumber):
234 self.
_streams[index] = (runNumber, lumiNumber, eventNumber)
237 def get(self, transition, index):
238 if transition == Phase.construction
or transition == Phase.destruction:
240 if transition == Phase.beginJob
or transition == Phase.endJob
or transition == Phase.openFile:
242 if transition == Phase.globalBeginRun
or transition == Phase.globalEndRun
or transition == Phase.globalWriteRun:
243 return (self.
runFor(index),)
244 if transition == Phase.globalBeginLumi
or transition == Phase.globalEndLumi
or transition == Phase.globalWriteLumi:
246 if transition == Phase.getNextTransition:
248 if transition == Phase.writeProcessBlock:
250 if transition == Phase.beginStream:
255 raise RuntimeError(
"Unknown transition {}".
format(transition))
262 self.
_times[(label, transition, index)] = time
264 time = self.
_times[(label, transition, index)]
265 del self.
_times[(label, transition, index)]
268 self.
_esTimes[(label, transition, index, record, call)] = time
269 def findTimeES(self, label, transition, index, record, call):
270 time = self.
_esTimes[(label, transition, index, record, call)]
271 del self.
_esTimes[(label, transition, index, record, call)]
275 def __init__(self, start, stop, transition, sync, activity, allocInfo, recordName=None, callID=None):
284 return "{{ 'timeRange': {}, 'transition': {}, 'sync' :{}, 'activity':{}, 'record': {{'name' : {}, 'callID' :{} }}, 'alloc':{} }}".
format(self.
timeRange, self.
transition, self.
sync, self.
activity, self.
record[0], self.
record[1], self.
allocInfo)
288 if len(self.
sync) == 0:
290 if len(self.
sync) == 1:
291 return {
'run' : self.
sync[0]}
292 if len(self.
sync) == 2:
293 return {
'run' : self.
sync[0],
'lumi' : self.
sync[1] }
294 return {
'run' : self.
sync[0],
'lumi' : self.
sync[1],
'event' : self.
sync[2] }
308 def insert(self, label, start, stop, transition, index, sync, activity, allocInfo, recordName=None, callID=None):
309 if label
not in self.
_data:
310 self.
_data[label] = []
311 self.
_data[label].
append(
ModuleData(start, stop, transition, sync, activity, allocInfo, recordName, callID))
312 self.
_last[(label, transition, index, activity)] = self.
_data[label][-1]
313 def findLast(self, label, transition, index, activity):
314 return self.
_last[(label, transition, index, activity)]
320 dct = {
'startedMonitoring': self.
_startTime,
'source' :[],
'clearEvent': [],
'modules' :{}}
321 modules = dct[
'modules']
326 elif m ==
'clearEvent':
327 l = dct[
'clearEvent']
332 l.append( d.toSimpleDict() )
337 data.append((m,
max(lst, key =
lambda x: getattr(x.allocInfo,attribute))) )
338 data.sort( key =
lambda x: getattr(x[1].allocInfo,attribute), reverse=
True)
348 def insert(self, label, start, stop, transition, index, sync, activity, allocInfo, recordName=None, callID=None):
349 self.
_data.
append((label,
ModuleData(start, stop, transition, sync, activity, allocInfo, recordName, callID)))
350 self.
_last[(label,transition, index, activity)] = self.
_data[-1]
351 def findLast(self, label, transition,index, activity):
352 v = self.
_last.get((label, transition, index, activity),
None)
361 dct = {
'startedMonitoring': self.
_startTime,
'measurements' :[]}
362 measurements = dct[
'measurements']
365 entry[
'label'] = d[0]
366 measurements.append(entry)
384 return f
'run={self.sync[0]}' 386 return f
'run={self.sync[0]}' 388 return f
'run={self.sync[0]}' 390 return f
'run={self.sync[0]} lumi={self.sync[1]}' 392 return f
'run={self.sync[0]} lumi={self.sync[1]}' 394 return f
'run={self.sync[0]} lumi={self.sync[1]}' 396 return f
'run={self.sync[0]} lumi={self.sync[1]} event={self.sync[2]}' 398 return f
'run={self.sync[0]} lumi={self.sync[1]}' 408 return f
'{transitionName(self.transition)} : id={self.index} {self.syncText()}' 410 return f
'{self.textPrefix()} {self.textSpecial()}: {self.textPostfix()}' 413 for i
in range(len(containers)):
414 if containers[i][-1][
"sync"] == sync:
417 for i
in range(len(containers)):
418 for t
in containers[i]:
419 if t[
"sync"] == sync:
422 print(
"find failed",sync, containers)
425 transitionsToFindMatch_ = {
428 Phase.globalWriteRun,
429 Phase.globalWriteLumi
438 isSourceTrans =
False 440 data.setStartTime(self.
time)
444 elif self.
transition == Phase.globalBeginLumi:
455 src = data.findLast(
"source", self.
transition, self.
index, Activity.process)
456 if src.sync != self.
index:
457 raise RuntimeError(
"Framework and Source transitions do not have matching index: source {} framework {} for transition type {} at framework time {} and source time {}".
format(src.sync, self.
index, self.
transition, self.
time, src.timeRange))
467 container = data.indexedGlobal(index)
470 if last[
"type"]==Phase.globalBeginRun
and last[
"isSrc"]:
471 last[
"sync"]=list(self.
sync)
474 container = data.indexedGlobal(index)
477 if last[
"type"]==Phase.globalBeginLumi
and last[
"isSrc"]:
478 last[
"sync"]=list(self.
sync)
479 elif self.
transition in transitionsToFindMatch_:
481 container = data.indexedGlobal(index)
483 container = data.indexedStream(self.
index)
487 if last[
"type"]==Phase.Event
and last[
"isSrc"]:
488 last[
"sync"]=list(self.
sync)
504 data.insert(
"clearEvent" , start, self.
time, self.
transition, self.
index, syncs.get(Phase.Event, self.
index) , Activity.process, self.
alloc)
508 container = data.indexedGlobal(index)
510 container = data.indexedStream(self.
index)
511 container[-1][
"finish"]=self.
time*kMicroToSec
513 self.
alloc.inject(container[-1])
520 if self.
transition == Phase.getNextTransition:
535 if self.
transition == Phase.getNextTransition:
543 return f
'source during {transitionName(self.transition)} : id={self.index}' 545 return f
'{self.textPrefix()} {self.textSpecial()}: {self.textPostfix()}' 560 data.findOpenSlotInModGlobals(0,0).
append(data._nextTrans[-1])
564 container = data.indexedGlobal(index)
567 container = data.indexedStream(index)
570 container = data.indexedGlobal(index)
571 nextTrans = data._nextTrans
577 transStartTime = t[
'start']
579 for i
in range(-1, -1*len(container), -1):
580 if transStartTime > container[i][
'start']:
586 container.insert(i+1,t)
590 container.insert(0,t)
594 data.findOpenSlotInModStreams(index,0).
append(container[-1])
596 data.findOpenSlotInModGlobals(index,0).
append(container[-1])
612 if self.
transition in [ Phase.construction, Phase.getNextTransition, Phase.destruction, Phase.openFile]:
619 container = data.indexedStream(index)
620 elif self.
transition == Phase.getNextTransition:
621 data._nextTrans[-1][
'finish'] = self.
time*kMicroToSec
622 self.
allocInfo.inject(data._nextTrans[-1])
626 for i, g
in enumerate(data.allGlobals()):
627 for t
in reversed(g):
628 if t[
"type"] != Phase.construction:
634 pre[
"finish"]=self.
time*kMicroToSec
639 container = data.indexedGlobal(index)
641 container[-1][
"finish"]=self.
time*kMicroToSec
659 return f
'{self.moduleName} during {transitionName(self.transition)} : id={self.index}' 662 return f
' transform {self.callID-1}' 665 return f
'{self.textPrefix(context)} {self.textSpecial()}{self.textIfTransform()}: {self.textPostfix()}' 670 compare =
lambda x: x[
'type'] == self.
transition and x[
'id'] == self.
index and x[
'mod'] == self.
moduleID and x[
'call'] == self.
callID and (x[
'act'] == Activity.temporary
or x[
'act'] == Activity.externalWork)
672 item,slot = data.findLastInModGlobals(index, self.
moduleID, compare)
674 item,slot = data.findLastInModStreams(index, self.
moduleID, compare)
676 if item[
'act'] == Activity.temporary:
679 item[
'finish']=self.
time*kMicroToSec
683 slot = data.findOpenSlotInModGlobals(index, self.
moduleID)
685 slot = data.findOpenSlotInModStreams(index, self.
moduleID)
692 item,slot = data.findLastInModGlobals(index, self.
moduleID, compare)
694 item,slot = data.findLastInModStreams(index, self.
moduleID, compare)
696 print(f
"failed to find {self.moduleID} for {self.transition} in {self.index}")
698 item[
"finish"]=self.
time*kMicroToSec
701 slot.append(injectAfter)
714 return "starting action" 726 return "finished action" 738 return "starting acquire" 751 return "finished acquire" 764 return "starting delayed get" 771 class PostEDModuleEventDelayedGetParser(EDModuleTransitionParser):
776 return "finished delayed get" 783 class PreEventReadFromSourceParser(EDModuleTransitionParser):
787 return "starting read from source" 800 return "finished read from source" 808 def __init__(self, payload, moduleNames, esModuleNames, recordNames):
824 return f
'esmodule {self.moduleName} in record {self.recordName} during {transitionName(self.transition)} : id={self.index}' 826 return f
'{self.textPrefix(context)} {self.textSpecial()}: {self.textPostfix()}' 830 slot = data.findOpenSlotInModGlobals(index, -1*self.
moduleID)
832 slot = data.findOpenSlotInModStreams(index, -1*self.
moduleID)
836 compare =
lambda x: x[
'id'] == self.
index and x[
'mod'] == -1*self.
moduleID and x[
'call'] == self.
callID 839 item,s = data.findLastInModGlobals(index, -1*self.
moduleID, compare)
841 item,s = data.findLastInModStreams(index, -1*self.
moduleID, compare)
843 print(f
"failed to find {-1*self.moduleID} for {self.transition} in {self.index}")
845 item[
"finish"]=self.
time*kMicroToSec
851 data.insert( self.
moduleName , start, self.
time, self.
transition, self.
index, syncs.get(self.
transition, self.
index) , activity, self.allocInfo, self.
recordName, self.
callID)
855 def __init__(self, payload, names, esNames, recordNames):
856 super().
__init__(payload, names, esNames, recordNames)
858 return "starting action" 865 def __init__(self, payload, names, esNames, recordNames):
866 super().
__init__(payload, names, esNames, recordNames)
869 return "finished action" 877 super().
__init__(payload, names, recordNames)
879 return "starting acquire" 884 def __init__(self, payload, names, esNames, recordNames):
885 super().
__init__(payload, names, esNames, recordNames)
888 return "finished acquire" 933 if not l
or l[0] ==
'#':
935 (step,payload) =
tuple(l.split(
None,1))
936 payload=payload.split()
938 parser =
lineParserFactory(step, payload, moduleNames, esModuleNames, recordNames, moduleCentric)
945 streamBeginRun =
str(Phase.streamBeginRun)
947 numStreamsFromSource = 0
953 if l
and l[0] ==
'M':
955 if i[3] == streamBeginRun:
957 numStreams =
int(i[1])+1
959 if numStreams == 0
and l
and l[0] ==
'S':
960 s =
int(l.split(
' ')[1])
961 if s > numStreamsFromSource:
962 numStreamsFromSource = s
963 if len(l) > 5
and l[0:2] ==
"#M":
965 moduleNames[
int(id)] = name
967 if len(l) > 5
and l[0:2] ==
"#N":
969 esModuleNames[
int(id)] = name
971 if len(l) > 5
and l[0:2] ==
"#R":
973 recordNames[
int(id)] = name
979 numStreams = numStreamsFromSource +2
985 for n
in moduleNames.items():
987 for n
in esModuleNames.items():
993 """Create a generator which can step through the file and return each processing step. 994 Using a generator reduces the memory overhead when parsing a large file. 1001 for p
in parser.processingSteps():
1002 print(p.text(context))
1012 while len(container) < index+1:
1013 container.append([])
1026 container = fullContainer[index]
1028 foundOpenSlot =
False 1029 for slot
in container:
1031 foundOpenSlot =
True 1033 if slot[-1][
"finish"] != 0:
1034 foundOpenSlot =
True 1036 if not foundOpenSlot:
1037 container.append([])
1038 slot = container[-1]
1045 container = fullContainer[index]
1047 for slot
in container:
1048 if comparer(slot[-1]):
1049 return (slot[-1],slot)
1067 while len(container) < index+1:
1068 container.append([])
1071 container.insert(0,[])
1088 foundOpenSlot =
False 1089 for slot
in container:
1091 foundOpenSlot =
True 1093 if slot[-1][
"finish"] != 0:
1094 foundOpenSlot =
True 1096 if not foundOpenSlot:
1097 container.append([])
1098 slot = container[-1]
1105 if not fullContainer:
1112 for slot
in container:
1113 if slot
is not None and comparer(slot[-1]):
1114 return (slot[-1],slot)
1132 while len(container) < index+1:
1133 container.append([])
1136 container.insert(0,[])
1153 foundOpenSlot =
False 1154 for slot
in container:
1156 foundOpenSlot =
True 1158 if slot[-1][
"finish"] != 0:
1159 foundOpenSlot =
True 1161 if not foundOpenSlot:
1162 container.append([])
1163 slot = container[-1]
1170 if not fullContainer:
1177 for slot
in container:
1178 if slot
is not None and comparer(slot[-1]):
1179 return (slot[-1],slot)
1189 return {
"type": type,
"id": id,
"sync": sync,
"start": start*kMicroToSec,
"finish": finish*kMicroToSec,
"isSrc":isSrc}
1192 return {
"type": type,
"id": id,
"mod": modID,
"call": callID,
"act": activity,
"start": start*kMicroToSec,
"finish": finish*kMicroToSec}
1206 for p
in parser.processingSteps():
1207 if hasattr(p,
"jsonInfo"):
1208 p.jsonInfo(sync,temp, data)
1216 for p
in parser.processingSteps():
1217 if hasattr(p,
"jsonInfo"):
1218 p.jsonInfo(sync,temp, data)
1219 return data.sortModulesBy(attribute)
1222 if parser._moduleCentric:
1226 for p
in parser.processingSteps():
1227 p.jsonVisInfo( data)
1229 for g
in data.allGlobals():
1230 g.sort(key=startTime)
1231 final = {
"transitions" : [] ,
"modules": [],
"esModules": []}
1232 final[
"transitions"].
append({
"name":
"Global",
"slots": []})
1233 globals = final[
"transitions"][-1][
"slots"]
1234 for i, g
in enumerate(data.allGlobals()):
1236 if not parser._moduleCentric:
1237 if len(data._modGlobals) < i+1:
1239 for mod
in data._modGlobals[i]:
1241 for i,s
in enumerate(data.allStreams()):
1242 final[
"transitions"].
append({
"name": f
"Stream {i}",
"slots":[]})
1243 stream = final[
"transitions"][-1][
"slots"]
1245 if not parser._moduleCentric:
1246 for mod
in data._modStreams[i]:
1248 if parser._moduleCentric:
1249 sourceSlot = data._modules[data._moduleID2Index(0)]
1251 for i,m
in parser._moduleNames.items():
1252 modules.append({
"name": f
"{m}",
"slots":[]})
1253 slots = modules[-1][
"slots"]
1254 foundSlots = data._modules[data._moduleID2Index(i)]
1256 for s
in foundSlots:
1259 if t[
"act"] !=Activity.prefetch:
1260 time += t[
"finish"]-t[
"start"]
1261 modules[-1][
'time']=time
1262 for i,m
in parser._esModuleNames.items():
1263 modules.append({
"name": f
"{m}",
"slots":[]})
1264 slots = modules[-1][
"slots"]
1265 foundSlots = data._modules[data._moduleID2Index(-1*i)]
1267 for s
in foundSlots:
1270 if t[
"act"] !=Activity.prefetch:
1271 time += t[
"finish"]-t[
"start"]
1272 modules[-1][
'time']=time
1273 modules.sort(key=
lambda x : x[
'time'], reverse=
True)
1274 final[
'transitions'].
append({
"name":
"source",
"slots":sourceSlot})
1276 final[
'transitions'].
append(m)
1279 for k
in parser._moduleNames.keys():
1283 final[
"modules"] =[
'']*(max+1)
1284 final[
"modules"][0] =
'source' 1285 for k,v
in parser._moduleNames.items():
1286 final[
"modules"][k]=v
1289 for k
in parser._esModuleNames.keys():
1292 final[
"esModules"] = [
'']*(max+1)
1293 for k,v
in parser._esModuleNames.items():
1294 final[
"esModules"][k] = v
1308 class TestModuleCommand(unittest.TestCase):
1320 f
'F {Phase.startTracing} 0 0 0 0 {incr(t)}',
1321 f
'S {Phase.construction} 0 {incr(t)}',
1322 f
's {Phase.construction} 0 {incr(t)} 1 1 10 0 10 10',
1323 f
'M {Phase.construction} 0 1 0 {incr(t)}',
1324 f
'm {Phase.construction} 0 1 0 {incr(t)} 3 2 20 0 50 25',
1325 f
'F {Phase.beginJob} 0 0 0 0 {incr(t)}',
1326 f
'M {Phase.beginJob} 0 1 0 {incr(t)}',
1327 f
'm {Phase.beginJob} 0 1 0 {incr(t)} 3 2 20 0 50 25',
1328 f
'f {Phase.beginJob} 0 0 0 0 {incr(t)}',
1329 f
'F {Phase.beginProcessBlock} 0 0 0 0 {incr(t)}',
1330 f
'f {Phase.beginProcessBlock} 0 0 0 0 {incr(t)}',
1331 f
'S {Phase.getNextTransition} {incr(t)}',
1332 f
's {Phase.getNextTransition} {incr(t)} 1 1 10 0 10 10',
1333 f
'S {Phase.globalBeginRun} 0 {incr(t)}',
1334 f
's {Phase.globalBeginRun} 0 {incr(t)} 1 1 10 0 10 10',
1335 f
'S {Phase.getNextTransition} {incr(t)}',
1336 f
's {Phase.getNextTransition} {incr(t)} 1 1 10 0 10 10',
1337 f
'F {Phase.globalBeginRun} 0 1 0 0 {incr(t)}',
1338 f
'M {Phase.globalBeginRun} 0 1 0 {incr(t)}',
1339 f
'm {Phase.globalBeginRun} 0 1 0 {incr(t)} 3 2 20 0 50 25',
1340 f
'f {Phase.globalBeginRun} 0 1 0 0 {incr(t)}',
1341 f
'S {Phase.getNextTransition} {incr(t)}',
1342 f
's {Phase.getNextTransition} {incr(t)} 1 1 10 0 10 10',
1343 f
'F {Phase.streamBeginRun} 0 1 0 0 {incr(t)}',
1344 f
'M {Phase.streamBeginRun} 0 1 0 {incr(t)}',
1345 f
'm {Phase.streamBeginRun} 0 1 0 {incr(t)} 3 2 20 0 50 25',
1346 f
'f {Phase.streamBeginRun} 0 1 0 0 {incr(t)}',
1347 f
'F {Phase.streamBeginRun} 1 1 0 0 {incr(t)}',
1348 f
'M {Phase.streamBeginRun} 1 1 0 {incr(t)}',
1349 f
'm {Phase.streamBeginRun} 1 1 0 {incr(t)} 3 2 20 0 50 25',
1350 f
'f {Phase.streamBeginRun} 1 1 0 0 {incr(t)}',
1351 f
'S {Phase.globalBeginLumi} 0 {incr(t)}',
1352 f
's {Phase.globalBeginLumi} 0 {incr(t)} 1 1 10 0 10 10',
1353 f
'S {Phase.getNextTransition} {incr(t)}',
1354 f
's {Phase.getNextTransition} {incr(t)} 1 1 10 0 10 10',
1355 f
'F {Phase.globalBeginLumi} 0 1 1 0 {incr(t)}',
1356 f
'M {Phase.globalBeginLumi} 0 1 0 {incr(t)}',
1357 f
'm {Phase.globalBeginLumi} 0 1 0 {incr(t)} 3 2 20 0 50 25',
1358 f
'f {Phase.globalBeginLumi} 0 1 1 0 {incr(t)}',
1359 f
'F {Phase.streamBeginLumi} 0 1 1 0 {incr(t)}',
1360 f
'f {Phase.streamBeginLumi} 0 1 1 0 {incr(t)}',
1361 f
'F {Phase.streamBeginLumi} 1 1 1 0 {incr(t)}',
1362 f
'f {Phase.streamBeginLumi} 1 1 1 0 {incr(t)}',
1363 f
'S {Phase.Event} 0 {incr(t)}',
1364 f
's {Phase.Event} 0 {incr(t)} 1 1 10 0 10 10',
1365 f
'S {Phase.getNextTransition} {incr(t)}',
1366 f
's {Phase.getNextTransition} {incr(t)} 1 1 10 0 10 10',
1367 f
'F {Phase.Event} 0 1 1 1 {incr(t)}',
1368 f
'S {Phase.Event} 1 {incr(t)}',
1369 f
's {Phase.Event} 1 {incr(t)} 1 1 10 0 10 10',
1370 f
'F {Phase.Event} 1 1 1 2 {incr(t)}',
1371 f
'N {Phase.Event} 0 1 1 0 {incr(t)}',
1372 f
'n {Phase.Event} 0 1 1 0 {incr(t)} 6 5 30 0 100 80',
1373 f
'M {Phase.Event} 0 1 0 {incr(t)}',
1374 f
'M {Phase.Event} 1 1 0 {incr(t)}',
1375 f
'm {Phase.Event} 1 1 0 {incr(t)} 3 2 20 0 50 25',
1376 f
'm {Phase.Event} 0 1 0 {incr(t)} 3 2 20 0 50 25',
1377 f
'f {Phase.Event} 0 1 1 1 {incr(t)}',
1378 f
'f {Phase.Event} 1 1 1 2 {incr(t)}'])
1384 self.assertEqual(s.runFor(0), 1)
1386 self.assertEqual(s.lumiFor(0), (1,1))
1387 s.setStream(1, 1,1,3)
1388 self.assertEqual(s.streamFor(1), (1,1,3))
1392 self.assertEqual(len(c.allGlobals()), 3)
1394 self.assertEqual(len(c.allStreams()), 3)
1395 slot = c.findOpenSlotInModGlobals(2, 1)
1396 self.assertEqual(len(c._modGlobals),3)
1397 self.assertEqual(len(slot),0)
1398 slot.append({
"start":1,
"finish":0,
"id":1})
1400 return item[
"id"]==1
1401 item,s = c.findLastInModGlobals(2, 1, testFind)
1402 self.assertEqual(item[
"id"],1)
1403 self.assertEqual(slot,s)
1404 slot = c.findOpenSlotInModStreams(2, 1)
1405 self.assertEqual(len(c._modStreams),3)
1406 self.assertEqual(len(slot),0)
1407 slot.append({
"start":1,
"finish":0,
"id":1})
1408 item,s = c.findLastInModStreams(2, 1, testFind)
1409 self.assertEqual(item[
"id"],1)
1410 self.assertEqual(slot,s)
1414 self.assertEqual(len(j.data()),3)
1415 self.assertEqual(len(j.data()[
"source"]), 10)
1416 self.assertEqual(len(j.data()[
"Module"]), 8)
1417 self.assertEqual(len(j.data()[
"ESModule"]), 1)
1421 self.assertEqual(len(j.data()),19)
1426 self.assertEqual(len(d), 3)
1427 self.assertEqual(d[0][0],
'ESModule')
1428 self.assertEqual(d[1][0],
'Module')
1429 self.assertEqual(d[2][0],
'source')
1434 self.assertEqual(len(j[
"modules"]), 2)
1435 self.assertEqual(len(j[
"esModules"]), 2)
1436 self.assertEqual(len(j[
'transitions']), 3)
1437 self.assertEqual(j[
'transitions'][0][
'name'],
"Global")
1438 self.assertEqual(j[
'transitions'][1][
'name'],
"Stream 0")
1439 self.assertEqual(j[
'transitions'][2][
'name'],
"Stream 1")
1440 self.assertEqual(len(j[
"transitions"][0][
"slots"]), 2)
1441 self.assertEqual(len(j[
"transitions"][0][
"slots"][0]), 11)
1442 self.assertEqual(len(j[
"transitions"][0][
"slots"][1]), 4)
1443 self.assertEqual(len(j[
"transitions"][1][
"slots"]), 2)
1444 self.assertEqual(len(j[
"transitions"][1][
"slots"][0]), 5)
1445 self.assertEqual(len(j[
"transitions"][1][
"slots"][1]), 3)
1446 self.assertEqual(len(j[
"transitions"][2][
"slots"]), 2)
1447 self.assertEqual(len(j[
"transitions"][2][
"slots"][0]), 5)
1448 self.assertEqual(len(j[
"transitions"][2][
"slots"][1]), 2)
1453 self.assertEqual(len(j[
"modules"]), 2)
1454 self.assertEqual(len(j[
"esModules"]), 2)
1455 self.assertEqual(len(j[
'transitions']), 6)
1456 self.assertEqual(j[
'transitions'][0][
'name'],
"Global")
1457 self.assertEqual(j[
'transitions'][1][
'name'],
"Stream 0")
1458 self.assertEqual(j[
'transitions'][2][
'name'],
"Stream 1")
1459 self.assertEqual(j[
'transitions'][3][
'name'],
"source")
1460 self.assertEqual(j[
'transitions'][4][
'name'],
"Module")
1461 self.assertEqual(j[
'transitions'][5][
'name'],
"ESModule")
1462 self.assertEqual(len(j[
"transitions"][0][
"slots"]), 1)
1463 self.assertEqual(len(j[
"transitions"][0][
"slots"][0]), 11)
1464 self.assertEqual(len(j[
"transitions"][1][
"slots"]), 1)
1465 self.assertEqual(len(j[
"transitions"][1][
"slots"][0]), 5)
1466 self.assertEqual(len(j[
"transitions"][2][
"slots"]), 1)
1467 self.assertEqual(len(j[
"transitions"][2][
"slots"][0]), 5)
1468 self.assertEqual(len(j[
"transitions"][4][
"slots"]), 2)
1469 self.assertEqual(len(j[
"transitions"][4][
"slots"][0]), 7)
1470 self.assertEqual(len(j[
"transitions"][4][
"slots"][1]), 1)
1471 self.assertTrue(j[
"transitions"][4][
"slots"][1][-1][
'finish'] != 0.0)
1472 self.assertEqual(len(j[
"transitions"][5][
"slots"]), 1)
1473 self.assertEqual(len(j[
"transitions"][5][
"slots"][0]), 1)
1476 return unittest.main(argv=sys.argv[:1])
1479 if __name__==
"__main__":
1485 parser = argparse.ArgumentParser(description=
'Convert a compact tracer file into human readable output.',
1486 formatter_class=argparse.RawDescriptionHelpFormatter,
1488 parser.add_argument(
'filename',
1489 type=argparse.FileType(
'r'), # open file 1490 help='file to process')
1491 parser.add_argument(
'-j',
'--json',
1492 action=
'store_true',
1493 help=
'''Write output in json format.''' )
1494 parser.add_argument(
'-s',
'--sortBy',
1497 help=
"sort modules by attribute. Alloed values 'nAllocs', 'nDeallocs', 'added', 'minTemp', maxTemp', and 'max1Alloc'")
1501 parser.add_argument(
'-t',
'--timeOrdered',
1502 action =
'store_true',
1503 help=
'''For --json, organize data by time instead of by module.''' )
1504 parser.add_argument(
'-T',
'--test',
1505 action=
'store_true',
1506 help=
'''Run internal tests.''')
1508 args = parser.parse_args()
1515 json.dump(
jsonInfo(parser, args.timeOrdered).toSimpleDict(), sys.stdout, indent=2)
def _preJsonVis(self, activity, data)
def insertTimeES(self, label, transition, index, record, call, time)
def indexedStream(self, index)
def findTime(self, label, transition, index)
def transitionName(transition)
def jsonInfo(self, syncs, temp, data)
def jsonVisInfo(self, data)
def _findLastIn(self, index, fullContainer, comparer)
def _preJsonInfo(self, temp)
def findOpenSlotInModStreams(self, index, modID)
def testFullVisualization(self)
def textPrefix(self, context)
def jsonVisInfo(self, data)
def _extendIfNeeded(self, container, index)
def findOpenSlotInModGlobals(self, index, modID)
def insertTime(self, label, transition, index, time)
def __init__(self, payload, names)
def indexedGlobal(self, index)
def _findLastIn(self, index, fullContainer, comparer)
def findLastInModGlobals(self, index, modID, comparer)
def jsonInfo(self, syncs, temp, data)
def findOpenSlotInModStreams(self, index, modID)
def __init__(self, payload)
def findLastInModStreams(self, index, modID, comparer)
def baseIndentLevel(self)
def jsonVisInfo(self, data)
def __init__(self, payload, names)
def indexedGlobal(self, index)
def indexedStream(self, index)
def _moduleID2Index(self, modID)
def indexedStream(self, index)
def streamFor(self, index)
def __init__(self, payload, names, recordNames)
def jsonInfo(self, syncs, temp, data)
def setLumi(self, index, runNumber, lumiNumber)
def __init__(self, payload, moduleNames)
def jsonInfo(self, syncs, temp, data)
def lineParserFactory(step, payload, moduleNames, esModuleNames, recordNames, moduleCentric)
def jsonInfo(self, syncs, temp, data)
def __init__(self, payload, moduleNames, esModuleNames, recordNames)
def jsonInfo(self, syncs, temp, data)
def _findOpenSlot(self, index, fullContainer)
def jsonInfo(parser, temporal)
def jsonInfo(self, syncs, temp, data)
def jsonVisInfo(self, data)
def sortByAttribute(parser, attribute)
def findOpenSlotInModGlobals(self, index, modID)
def _extendIfNeeded(self, container, index)
def processingSteps(self)
def insert(self, label, start, stop, transition, index, sync, activity, allocInfo, recordName=None, callID=None)
def _findOpenSlot(self, index, fullContainer)
def __init__(self, payload)
def _postJsonVis(self, data, alloc, injectAfter=None)
def jsonVisInfo(self, data)
def get(self, transition, index)
def findOpenSlotInModGlobals(self, index, modID)
def jsonInfo(self, syncs, temp, data)
def findTimeES(self, label, transition, index, record, call)
def __init__(self, payload, names)
def __init__(self, payload, names, esNames, recordNames)
def jsonVisInfo(self, data)
def jsonVisInfo(self, data)
def jsonInfo(self, syncs, temp, data)
def processingStepsFromFile(f, moduleNames, esModuleNames, recordNames, moduleCentric)
def _postJsonInfo(self, syncs, temp, data, activity)
def _extendModulesIfNeeded(self, container, index)
def findLastInModGlobals(self, index, modID, comparer)
def __init__(self, payload, moduleCentric)
def setStream(self, index, runNumber, lumiNumber, eventNumber)
def findLastInModGlobals(self, index, modID, comparer)
def __init__(self, payload)
def jsonVisInfo(self, data)
def jsonVisInfo(self, data)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def __init__(self, payload, names)
def transitionIsGlobal(transition)
def findOpenSlotInModStreams(self, index, modID)
def __init__(self, payload)
def setStartTime(self, time)
def _findLastIn(self, index, fullContainer, comparer)
def jsonVisInfo(self, data)
def activityName(activity)
def baseIndentLevel(self)
def __init__(self, payload, moduleCentric)
def insert(self, label, start, stop, transition, index, sync, activity, allocInfo, recordName=None, callID=None)
def __init__(self, payload)
def __init__(self, f, moduleCentric)
def _extendIfNeeded(self, container, index)
def textPrefix(self, context)
def split(sequence, size)
def _postJsonVis(self, data, alloc)
def setRun(self, index, runNumber)
def setStartTime(self, time)
def jsonModuleTransition(type, id, modID, callID, activity, start, finish=0)
def jsonVisInfo(self, data)
def sortModulesBy(self, attribute)
def syncToSimpleDict(self)
def jsonVisInfo(self, data)
def findLast(self, label, transition, index, activity)
def _moduleID2Index(self, modID)
def __init__(self, start, stop, transition, sync, activity, allocInfo, recordName=None, callID=None)
def jsonInfo(self, syncs, temp, data)
def _extendModulesIfNeeded(self, container, index)
def jsonInfo(self, syncs, temp, data)
def __init__(self, payload, names, moduleCentric)
def testModuleCentricVisualization(self)
def _findOpenSlot(self, index, fullContainer)
def _preJsonInfo(self, temp)
def __init__(self, payload, names, moduleCentric)
def indexedGlobal(self, index)
def findLast(self, label, transition, index, activity)
def jsonTransition(type, id, sync, start, finish, isSrc=False)
def textPrefix_(time, indentLevel)
def findLastInModStreams(self, index, modID, comparer)
def jsonInfo(self, syncs, temp, data)
def __init__(self, payload, names)
def jsonInfo(self, syncs, temp, data)
def textIfTransform(self)
def transitionIndentLevel(transition)
def jsonVisInfo(self, data)
def _postJsonInfo(self, syncs, temp, data, activity)
def testJsonTemporal(self)
def jsonVisInfo(self, data)
def __init__(self, payload, names, esNames, recordNames)
def _preJsonVis(self, activity, data, mayUseTemp=False)
def jsonInfo(self, syncs, temp, data)
def jsonVisInfo(self, data)
def findMatchingTransition(sync, containers)
def __init__(self, payload, names, esNames, recordNames)
def findLastInModStreams(self, index, modID, comparer)
def jsonVisInfo(self, data)
def __init__(self, payload, names, moduleCentric)
def inject(self, transition)
def jsonVisualizationInfo(parser)