Use yosys stat -json for metrics extraction#4019
Use yosys stat -json for metrics extraction#4019rohithsiddi wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
Conversation
Replace text-based synth_stat.txt with JSON output from stat -json. Update genMetrics.py to parse the JSON instead of using regex. Fixes The-OpenROAD-Project#3485 Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
| tee -o $::env(REPORTS_DIR)/synth_check.txt check | ||
|
|
||
| tee -o $::env(REPORTS_DIR)/synth_stat.txt stat {*}$lib_args | ||
| tee -o $::env(REPORTS_DIR)/synth_stat.json stat -json {*}$lib_args |
There was a problem hiding this comment.
We should tee to a log file and use the -o option to output a valid JSON:
https://yosyshq.readthedocs.io/projects/yosys/en/latest/cmd/index_backends.html#json-write-design-in-json-format
There was a problem hiding this comment.
The json backend (write_json -o) outputs the design netlist rather than synthesis statistics, it doesn't include aggregated cell count or area values that we need for metrics. stat -json provides these but doesn't support -o; its docs recommend using tee for file output. Our current approach uses tee -oto capture stat -json and skips any log prefix (e.g. "Found gzip magic") in genMetrics.py before parsing. Would this be acceptable?
| try: | ||
| with open(synth_stat_file) as f: | ||
| content = f.read() | ||
| # yosys may emit log messages (e.g. "Found gzip magic in file...") | ||
| # before the JSON when reading compressed liberty files. Skip them. |
There was a problem hiding this comment.
If the above is implemented we likely will not need this post-processing.
Use yosys stat -json for metrics extraction
Fixes #3485
Description
Yosys
stat -jsonproduces structured JSON output that is more reliable for scripting than the plain-textstatoutput. This replaces the text-basedsynth_stat.txtreport and the fragile regex patterns used to parse it with a proper JSON file parsed in Python.Changes
flow/scripts/synth.tcl: replacestatwithstat -json, writing output tosynth_stat.jsonflow/util/genMetrics.py: parsesynth_stat.jsonwithjson.load()instead of using regex onsynth_stat.txt; skip non-JSON prefix (e.g. "Found gzip magic in file...") that yosys emits before JSON output when reading.lib.gzliberty filesdocs/tutorials/FlowTutorial.md: update references fromsynth_stat.txttosynth_stat.jsonTesting
Tested locally against
nangate45/gcd,asap7/gcd, andgf180/aes. asap7 and gf180 use.lib.gzliberty files which cause yosys to emit log messages before the JSON output; the parser handles this correctly.synth__design__instance__count__stdcellsynth__design__instance__area__stdcellAI tools were used to assist with code generation. All technical decisions and implementation details are my own.