[PATCH] D53142: [VPlan] Script to extract VPlan digraphs from log

Renato Golin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 10:07:45 PDT 2018


rengolin updated this revision to Diff 169232.
rengolin added a comment.

Hi Florian,

Indeed, the "zip" and "with" Python idioms are much nicer, thanks!

I haven't used glob read because I wanted to make sure I got the VF/UF from the right line.

I have now made it even more explicitly by changing the search to a match and making sure the beginning or the line is the one I want.

cheers,
--renato


https://reviews.llvm.org/D53142

Files:
  utils/extract_vplan.py


Index: utils/extract_vplan.py
===================================================================
--- utils/extract_vplan.py
+++ utils/extract_vplan.py
@@ -30,7 +30,7 @@
             VPlans.append(CurVPlan)
             CurVPlan = ''
         else:
-            m = re.search("(VF.*,UF.*), ", line)
+            m = re.match("graph.+(VF.*,UF.*), ", line)
             if m:
                 name = re.sub('[^a-zA-Z0-9]', '', m.group(1))
                 Names.append(name)
@@ -40,19 +40,18 @@
 if len(VPlans) != len(Names):
     raise RuntimeError("Incongruent number of VPlans and respective names")
 
-for i in range(len(VPlans)):
+for name, vplan in zip(Names, VPlans):
     if args.png:
-        filename = 'VPlan' + Names[i] + '.png'
-        print("Exporting " + Names[i] + " to PNG via dot: " + filename)
+        filename = 'VPlan' + name + '.png'
+        print("Exporting " + name + " to PNG via dot: " + filename)
         p = subprocess.Popen([dot, '-Tpng', '-o', filename], encoding='utf-8',
                               stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        out, err = p.communicate(input=VPlans[i])
+        out, err = p.communicate(input=vplan)
         if err:
             raise RuntimeError("Error running dot: " + err)
 
     else:
-        filename = 'VPlan' + Names[i] + '.dot'
+        filename = 'VPlan' + name + '.dot'
         print("No visualisation requested, saving to file: " + filename)
-        out = open(filename, 'w')
-        out.write(VPlans[i])
-        out.close()
+        with open(filename, 'w') as out:
+            out.write(vplan)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53142.169232.patch
Type: text/x-patch
Size: 1620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181011/f7b79620/attachment.bin>


More information about the llvm-commits mailing list