|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 | 3 | """
|
4 |
| -This program parse the output from pcap_compile() to visualize the CFG after |
| 4 | +This program parses the output from pcap_compile() to visualize the CFG after |
5 | 5 | each optimize phase.
|
6 | 6 |
|
7 | 7 | Usage guide:
|
|
15 | 15 | testprogs/filtertest -g EN10MB host 192.168.1.1 > a.txt
|
16 | 16 | 3. Send a.txt to this program's standard input
|
17 | 17 | cat a.txt | testprogs/visopts.py
|
| 18 | + (Graphviz must be installed) |
18 | 19 | 4. Step 2&3 can be merged:
|
19 | 20 | testprogs/filtertest -g EN10MB host 192.168.1.1 | testprogs/visopts.py
|
20 | 21 | 5. The standard output is something like this:
|
21 | 22 | generated files under directory: /tmp/visopts-W9ekBw
|
22 | 23 | the directory will be removed when this programs finished.
|
23 | 24 | open this link: http://localhost:39062/expr1.html
|
24 |
| -6. Using open link at the 3rd line `http://localhost:39062/expr1.html' |
| 25 | +6. Open the URL at the 3rd line in a browser. |
25 | 26 |
|
26 | 27 | Note:
|
27 |
| -1. The CFG is translated to SVG an document, expr1.html embeded them as external |
28 |
| - document. If you open expr1.html as local file using file:// protocol, some |
29 |
| - browsers will deny such requests so the web pages will not shown properly. |
30 |
| - For chrome, you can run it using following command to avoid this: |
| 28 | +1. The CFG is translated to SVG images, expr1.html embeds them as external |
| 29 | + documents. If you open expr1.html as local file using file:// protocol, some |
| 30 | + browsers will deny such requests so the web page will not work properly. |
| 31 | + For Chrome, you can run it using the following command to avoid this: |
31 | 32 | chromium --disable-web-security
|
32 |
| - That's why this program start a localhost http server. |
33 |
| -2. expr1.html use jquery from https://ajax.googleapis.com, so you need internet |
34 |
| - access to show the web page. |
| 33 | + That's why this program starts a localhost HTTP server. |
| 34 | +2. expr1.html uses jQuery from https://ajax.googleapis.com, so it needs Internet |
| 35 | + access to work. |
35 | 36 | """
|
36 | 37 |
|
37 | 38 | import sys, os
|
@@ -255,7 +256,13 @@ def render_on_html(infile):
|
255 | 256 | log += line
|
256 | 257 |
|
257 | 258 | if indot == 2:
|
258 |
| - p = subprocess.Popen(['dot', '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| 259 | + try: |
| 260 | + p = subprocess.Popen(['dot', '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| 261 | + except OSError as ose: |
| 262 | + print "Failed to run 'dot':", ose |
| 263 | + print "(Is Graphviz installed?)" |
| 264 | + exit(1) |
| 265 | + |
259 | 266 | svg = p.communicate(dot)[0]
|
260 | 267 | with file("expr1_g%03d.svg" % (gid), "wt") as f:
|
261 | 268 | f.write(svg)
|
@@ -296,7 +303,7 @@ def main():
|
296 | 303 | os.chdir(tempfile.mkdtemp(prefix="visopts-"))
|
297 | 304 | atexit.register(shutil.rmtree, os.getcwd())
|
298 | 305 | print "generated files under directory: %s" % os.getcwd()
|
299 |
| - print " the directory will be removed when this programs finished." |
| 306 | + print " the directory will be removed when this program has finished." |
300 | 307 |
|
301 | 308 | if not render_on_html(sys.stdin):
|
302 | 309 | return 1
|
|
0 commit comments