Skip to content

Commit

Permalink
orka: Add Python file to render the JSON of a frame graph on the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
onox committed Apr 1, 2024
1 parent e3701a4 commit 76bbb8d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
45 changes: 45 additions & 0 deletions json-to-digraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
import sys

# Render input.json:
# $ python3 path/to/json-to-digraph.py input.json | python3 -m xdot -

with open(sys.argv[1], "r") as fp:
parsed = json.load(fp)

print("digraph {rankdir=LR;")

for i,v in enumerate(parsed["passes"]):
v["index"] = i + 1
print("P{index} [label=\"{name} ({writeCount})\"".format(**v), end="")
if v["sideEffect"]:
print(",fillcolor=\"#ff4b00\",style=filled,shape=oval];")
elif v["references"] > 0:
print(",fillcolor=\"#64d50a\",style=filled,shape=oval];")
else:
print(",color=\"#64d50a\",style=solid,shape=oval];")

for i,v in enumerate(parsed["resources"]):
v["index"] = i + 1
print("R{index} [label=\"{name} v{version}\n{kind}\n{format} ({readCount})\"".format(**v), end="")
if v["references"] > 0:
if v["implicit"]:
print(",fillcolor=\"#87baf7\",style=dashed,shape=box];")
else:
print(",fillcolor=\"#2480f1\",style=filled,shape=box];")
else:
if v["implicit"]:
print(",color=\"#87baf7\",style=dashed,shape=box];")
else:
print(",color=\"#2480f1\",style=solid,shape=box];")

for v in parsed["writes"]:
v["source"] += 1
v["target"] += 1
print("P{source}->R{target} [color=\"#cb4646\"];".format(**v))
for v in parsed["reads"]:
v["source"] += 1
v["target"] += 1
print("R{source}->P{target} [color=\"#75cb46\"];".format(**v))

print("}")
4 changes: 4 additions & 0 deletions orka/src/orka/orka-frame_graphs.ads
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ package Orka.Frame_Graphs is
-- To pretty print the JSON in the file, execute:
--
-- python3 -m json.tool < graph.json
--
-- To render the graph in the JSON file on the screen, run:
--
-- python3 path/to/orka/json-to-digraph.py graph.json | python3 -m xdot -

private

Expand Down

0 comments on commit 76bbb8d

Please sign in to comment.