[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 09:30:56 PDT 2018


rengolin created this revision.
rengolin added reviewers: Ayal, dcaballe, fhahn, hsaito.
Herald added subscribers: rogfer01, rkruppe, tschuett, bollu.

The vectoriser's debug log prints VPlan digraphs, but it's a bit
cumbersome to extract them and render them into PNG images. This script
does exactly that, being careful enough to extract all individual plans,
name them appropriately and save in either .dot or .png files.


https://reviews.llvm.org/D53142

Files:
  utils/extract_vplan.py


Index: utils/extract_vplan.py
===================================================================
--- /dev/null
+++ utils/extract_vplan.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+# This script extracts the VPlan digraphs from the vectoriser debug messages
+# and saves them in individual dot files (one for each plan). Optionally, and
+# providing 'dot' is installed, it can also render the dot into a PNG file.
+
+import sys
+import re
+import argparse
+import shutil
+import subprocess
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--png', action='store_true')
+args = parser.parse_args()
+
+dot = shutil.which('dot')
+if args.png and not dot:
+    raise RuntimeError("Can't export to PNG without 'dot' in the system")
+
+VPlans = list()
+Names = list()
+CurVPlan = ''
+for line in sys.stdin:
+    if not CurVPlan and re.match("digraph VPlan {", line):
+        CurVPlan = line
+    elif CurVPlan:
+        if re.match("}", line):
+            CurVPlan += line
+            VPlans.append(CurVPlan)
+            CurVPlan = ''
+        else:
+            m = re.search("(VF.*,UF.*), ", line)
+            if m:
+                name = re.sub('[^a-zA-Z0-9]', '', m.group(1))
+                Names.append(name)
+                print("Found VPlan for " + name)
+            CurVPlan += line
+
+if len(VPlans) != len(Names):
+    raise RuntimeError("Incongruent number of VPlans and respective names")
+
+for i in range(len(VPlans)):
+    if args.png:
+        filename = 'VPlan' + Names[i] + '.png'
+        print("Exporting " + Names[i] + " 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])
+        if err:
+            raise RuntimeError("Error running dot: " + err)
+
+    else:
+        filename = 'VPlan' + Names[i] + '.dot'
+        print("No visualisation requested, saving to file: " + filename)
+        out = open(filename, 'w')
+        out.write(VPlans[i])
+        out.close()


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


More information about the llvm-commits mailing list