@@ -35,6 +35,9 @@ def prepareDir(directory):
3535 trial = 2
3636baseDir = os .path .abspath (os .path .dirname (sys .argv [0 ]))
3737tool = sys .argv [1 ]
38+ if tool != 'cam' :
39+ print ('Temporary disable spade and opus for new concurrency testing, please revert to git version a28cc39585c6e74dbeccfc3dccfeef537857ff22 for testing spade and opus in a stable version' )
40+ quit ()
3841toolBaseDir = os .path .abspath (sys .argv [2 ])
3942benchmarkDir = os .path .abspath (sys .argv [3 ])
4043stageDir = os .path .abspath ('%s/stage/' % baseDir )
@@ -51,19 +54,22 @@ def prepareDir(directory):
5154
5255stage1Tool = config [tool ]['stage1tool' ]
5356stage2Handler = config [tool ]['stage2handler' ]
54- template = config [tool ]['template' ]
5557
5658#Stage 1 - Start the tools and generate graph (neo4j / dot / provjson)
5759start = time .time ()
5860print ('Starting stage 1...Generating provenance from native tools' )
5961
6062os .system ('sudo chmod +x %s/startTool/%s' % (baseDir , stage1Tool .split ()[0 ]))
6163stage1Command = 'sudo %s/startTool/%s %s %s %s %s %s %s %d' % (baseDir , stage1Tool , stageDir , workingDir , '%s' , '%s' , toolBaseDir , '%s' , trial )
64+
6265print ('Program' )
63- subprocess .call ((stage1Command % (benchmarkDir , 'PROGRAM,RANDOM,READ=2,WRITE=2' , 'program' )).split ())
66+ #programFingerprint = subprocess.check_output((stage1Command % (benchmarkDir, 'PROGRAM,RANDOM,READ=2,WRITE=2', 'program')).split())
67+ programFingerprint = subprocess .check_output ((stage1Command % (benchmarkDir , 'PROGRAM,READ=2,WRITE=2' , 'program' )).split ()).decode ().split ()
6468print ('End Program' )
69+
6570print ('Control' )
66- subprocess .call ((stage1Command % (benchmarkDir , 'CONTROL,RANDOM,READ=2,WRITE=2' , 'control' )).split ())
71+ #controlFingerprint = subprocess.check_output((stage1Command % (benchmarkDir, 'CONTROL,RANDOM,READ=2,WRITE=2', 'control')).split())
72+ controlFingerprint = subprocess .check_output ((stage1Command % (benchmarkDir , 'CONTROL,READ=2,WRITE=2' , 'control' )).split ()).decode ().split ()
6773print ('End Control' )
6874
6975print ('End of stage 1\n ' )
@@ -75,13 +81,26 @@ def prepareDir(directory):
7581print ('Starting stage 2...Transforming provenance result to Clingo graph' )
7682
7783os .system ('sudo chmod +x %s/genClingoGraph/%s' % (baseDir , stage2Handler .split ()[0 ]))
78- stage2Command = 'sudo %s/genClingoGraph/%s %s %s %s' % (baseDir , stage2Handler , '%s' , template , workingDir )
79- for i in range (1 ,trial + 1 ):
80- suffix = 'control-%d' % i
81- subprocess .call ((stage2Command % (suffix ,suffix )).split ())
82- for i in range (1 ,trial + 1 ):
83- suffix = 'program-%d' % i
84- subprocess .call ((stage2Command % (suffix ,suffix )).split ())
84+ stage2Command = 'sudo %s/genClingoGraph/%s %s %s %s' % (baseDir , stage2Handler , '%s' , '%s' , '%s' )
85+
86+ for fingerprint in controlFingerprint :
87+ dir = os .path .abspath ('%s/%s' % (workingDir , fingerprint ))
88+ if os .path .isdir (dir ):
89+ i = 1
90+ for file in os .listdir (dir ):
91+ suffix = 'control-%d' % i
92+ subprocess .call ((stage2Command % (suffix ,file ,dir )).split ())
93+ i += 1
94+
95+ for fingerprint in programFingerprint :
96+ dir = os .path .abspath ('%s/%s' % (workingDir , fingerprint ))
97+ if os .path .isdir (dir ):
98+ i = 1
99+ for file in os .listdir (dir ):
100+ suffix = 'program-%d' % i
101+ subprocess .call ((stage2Command % (suffix ,file ,dir )).split ())
102+ i += 1
103+
85104print ('End of stage 2\n ' )
86105end = time .time ()
87106t2 = end - start
@@ -93,32 +112,52 @@ def prepareDir(directory):
93112os .system ('sudo chmod +x %s/processGraph/generalizeGraph.py' % baseDir )
94113stage3Command = 'sudo %s/processGraph/generalizeGraph.py %s %s %s' % (baseDir , workingDir , ('%s/processGraph/template.lp' % baseDir ), '%s' )
95114
96- command = stage3Command % ('control %s' )
97- for i in range (1 ,trial + 1 ):
98- suffix = 'control-%d' % i
99- command = command % ('%s/clingo-%s %s' % (workingDir , suffix , '%s' ))
100- subprocess .call ((command % ' ' ).split ())
101-
102- command = stage3Command % ('program %s' )
103- for i in range (1 ,trial + 1 ):
104- suffix = 'program-%d' % i
105- command = command % ('%s/clingo-%s %s' % (workingDir , suffix ,'%s' ))
106- subprocess .call ((command % '' ).split ())
115+ for fingerprint in controlFingerprint :
116+ dir = os .path .abspath ('%s/%s' % (workingDir , fingerprint ))
117+ if os .path .isdir (dir ):
118+ command = stage3Command % ('control-%s %s' % (fingerprint , '%s' ))
119+ for file in ('%s/%s' % (dir ,name ) for name in os .listdir (dir ) if name .startswith ('clingo-control' )):
120+ command = command % ('%s %s' % (file , '%s' ))
121+ subprocess .call ((command % '' ).split ())
122+
123+ for fingerprint in programFingerprint :
124+ dir = os .path .abspath ('%s/%s' % (workingDir , fingerprint ))
125+ if os .path .isdir (dir ):
126+ command = stage3Command % ('program-%s %s' % (fingerprint , '%s' ))
127+ for file in ('%s/%s' % (dir ,name ) for name in os .listdir (dir ) if name .startswith ('clingo-program' )):
128+ command = command % ('%s %s' % (file , '%s' ))
129+ subprocess .call ((command % '' ).split ())
107130
108131print ('End of stage 3\n ' )
109132end = time .time ()
110133t3 = end - start
111134
112- shutil . copyfile ( '%s/general.clingo-program' % workingDir , '%s/ general.clingo-program' % outDir )
113- shutil .copyfile ('%s/general.clingo-control ' % workingDir , '%s/general.clingo-control ' % outDir )
135+ for file in ( file for file in os . listdir ( workingDir ) if file . startswith ( ' general.clingo' )):
136+ shutil .copyfile ('%s/%s ' % ( workingDir ,file ), '%s/%s ' % ( outDir , file ) )
114137
115138#Stage 4 - Compare and generate benchmark
116139start = time .time ()
117140print ('Starting stage 4...Generating benchmark' )
118141
119142os .system ('sudo chmod +x %s/processGraph/findSubgraph.py' % baseDir )
120- stage4Command = 'sudo %s/processGraph/findSubgraph.py %s %s 1 general.clingo-control general.clingo-program %s' % (baseDir , workingDir , ('%s/processGraph/template.lp' % baseDir ), ('%s/result.clingo' % outDir ))
121- subprocess .call (stage4Command .split ())
143+ for fingerprint in programFingerprint :
144+ if len (controlFingerprint ) > 1 :
145+ editDistance = sys .maxsize
146+ for backgroundFingerprint in controlFingerprint :
147+ preStage4Command = '''sudo %s/processGraph/calEditDistance.py %s %s/general.clingo-control-%s
148+ %s/general.clingo-program-%s''' % (baseDir , ('''%s/processGraph/editdist.lp
149+ ''' % baseDir ), workingDir , backgroundFingerprint , workingDir , fingerprint )
150+ newEditDistance = int (subprocess .check_output (preStage4Command .split ()))
151+ if newEditDistance < editDistance :
152+ editDistance = newEditDistance
153+ background = backgroundFingerprint
154+ else :
155+ background = controlFingerprint [0 ]
156+
157+ stage4Command = '''sudo %s/processGraph/findSubgraph.py %s %s 1 general.clingo-control-%s general.clingo-program-%s %s
158+ ''' % (baseDir , workingDir , ('%s/processGraph/template.lp' % baseDir ), background , fingerprint , ('''%s/result-%s.clingo
159+ ''' % (outDir ,fingerprint )))
160+ subprocess .call (stage4Command .split ())
122161
123162print ('End of stage 4\n ' )
124163end = time .time ()
0 commit comments