Skip to content

Use yosys stat -json for metrics extraction#4019

Open
rohithsiddi wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
rohithsiddi:yosys-stat-json-metrics
Open

Use yosys stat -json for metrics extraction#4019
rohithsiddi wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
rohithsiddi:yosys-stat-json-metrics

Conversation

@rohithsiddi
Copy link
Copy Markdown

@rohithsiddi rohithsiddi commented Mar 20, 2026

Use yosys stat -json for metrics extraction

Fixes #3485

Description

Yosys stat -json produces structured JSON output that is more reliable for scripting than the plain-text stat output. This replaces the text-based synth_stat.txt report and the fragile regex patterns used to parse it with a proper JSON file parsed in Python.

Changes

  • flow/scripts/synth.tcl: replace stat with stat -json, writing output to synth_stat.json
  • flow/util/genMetrics.py: parse synth_stat.json with json.load() instead of using regex on synth_stat.txt; skip non-JSON prefix (e.g. "Found gzip magic in file...") that yosys emits before JSON output when reading .lib.gz liberty files
  • docs/tutorials/FlowTutorial.md: update references from synth_stat.txt to synth_stat.json

Testing

Tested locally against nangate45/gcd, asap7/gcd, and gf180/aes. asap7 and gf180 use .lib.gz liberty files which cause yosys to emit log messages before the JSON output; the parser handles this correctly.

Metric nangate45/gcd asap7/gcd gf180/aes
synth__design__instance__count__stdcell 425 307 15336
synth__design__instance__area__stdcell 562.324 35.663 499940.179

AI tools were used to assist with code generation. All technical decisions and implementation details are my own.

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>
@rohithsiddi rohithsiddi marked this pull request as draft March 20, 2026 14:11
Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
@rohithsiddi rohithsiddi marked this pull request as ready for review March 20, 2026 18:50
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +235 to +239
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the above is implemented we likely will not need this post-processing.

@rohithsiddi rohithsiddi requested a review from vvbandeira March 31, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use yosys stat -json for metrics extraction

2 participants