about summary refs log tree commit diff homepage
path: root/utils/hacks/TreeGraphs/Animate.py
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-05-02 17:59:13 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-05-02 17:59:13 +0000
commitf4cdc443fb86f715ab93f3528aff23452a5bb3a3 (patch)
treeffab5077611d32a8b95c9d9b4f96b47703190e82 /utils/hacks/TreeGraphs/Animate.py
parentbae2fa50234b0a575a18a119019e5d96f7ff7ecf (diff)
downloadklee-f4cdc443fb86f715ab93f3528aff23452a5bb3a3.tar.gz
Add a little hack for visualizing KLEE branching.
 - This consumes the treestream files produced with --write-paths or
   --write-sym-paths, and renders out the tree in a very ad-hoc funky way.
   Your mileage may vary! :)

Example image: http://klee.llvm.org/data/treegraph_example.jpg
Example movie: http://klee.llvm.org/data/treegraph_example.avi

git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@102869 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/hacks/TreeGraphs/Animate.py')
-rwxr-xr-xutils/hacks/TreeGraphs/Animate.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/utils/hacks/TreeGraphs/Animate.py b/utils/hacks/TreeGraphs/Animate.py
new file mode 100755
index 00000000..07f43756
--- /dev/null
+++ b/utils/hacks/TreeGraphs/Animate.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+import os
+import TreeGraph
+import Image
+
+def main():
+    from optparse import OptionParser
+    op = OptionParser("usage: %prog [options] <tree-stream-path> <output-directory>")
+    op.add_option('','--start', dest='startCount', type=int, default=10,
+                  help='number of paths to start animation at')
+    op.add_option('','--end', dest='endCount', type=int, default=1000,
+                  help='number of paths to start animation at')
+    op.add_option('','--stride', dest='countStride', type=int, default=10,
+                  help='number of paths to step by in each frame')
+    op.add_option('','--convert-to-jpg', dest='convertToJPG',
+                  action='store_true', default=False)
+    op.add_option('','--convert-to-rgb', dest='convertToRGB',
+                  action='store_true', default=False)
+    opts,args = op.parse_args()
+
+    if len(args) != 2:
+        parser.error('invalid number of arguments')
+
+    symPath,outputDir = args
+    if not os.path.exists(outputDir):
+        os.mkdir(outputDir)
+    
+    for frame,count in enumerate(range(opts.startCount, opts.endCount,
+                                     opts.countStride)):
+        print 'generating frame %d with path count %d...' % (frame+1, count)
+        pdf_path = os.path.join(outputDir, 'frame_%05d.pdf' % frame)
+        TreeGraph.makeTreeGraph(pdf_path, symPath, count)
+        if not opts.convertToJPG:
+            continue
+
+        jpg_path = os.path.join(outputDir, 'frame_%05d.jpg' % frame)
+        if not opts.convertToRGB:
+            os.system('convert "%s" "%s"' % (pdf_path, jpg_path))
+            continue
+
+        jpg_tmp_path = os.path.join(outputDir, 'frame_%05d_tmp.jpg' % frame)
+        os.system('convert "%s" "%s"' % (pdf_path, jpg_tmp_path))
+
+        img = Image.open(jpg_tmp_path)
+        img = img.convert('RGB')
+        img.save(jpg_path, quality=100)
+        
+if __name__=='__main__':
+    try:
+        main()
+    except:
+        import sys,traceback
+        traceback.print_exc(file= sys.__stdout__)
+        sys.__stdout__.flush()