From 76bbb8d7a0fd7fcccd4f787eae78d4e4bcae6c8d Mon Sep 17 00:00:00 2001 From: onox Date: Mon, 1 Apr 2024 21:15:11 +0200 Subject: [PATCH] orka: Add Python file to render the JSON of a frame graph on the screen --- json-to-digraph.py | 45 +++++++++++++++++++++++++++++ orka/src/orka/orka-frame_graphs.ads | 4 +++ 2 files changed, 49 insertions(+) create mode 100644 json-to-digraph.py diff --git a/json-to-digraph.py b/json-to-digraph.py new file mode 100644 index 00000000..e2b5e12d --- /dev/null +++ b/json-to-digraph.py @@ -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("}") diff --git a/orka/src/orka/orka-frame_graphs.ads b/orka/src/orka/orka-frame_graphs.ads index 98260b5b..4d9fcf04 100644 --- a/orka/src/orka/orka-frame_graphs.ads +++ b/orka/src/orka/orka-frame_graphs.ads @@ -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