Skip to content

Commit 3fde4a2

Browse files
oharboeclaude
andcommitted
flow: hash .v / .rtlil / .odb / .sdc separately in elapsed-time table
genElapsedTime.py used to pick exactly one of .odb / .rtlil / .v as "the result file" for a log and hash that. Synth produces both 1_2_yosys.v and 1_2_yosys.sdc; OpenROAD stages produce both an .odb and a .sdc. Folding all of them into one column means a divergent .sdc (an SDC-generator change) and a divergent .odb (a real flow change) look identical in the elapsed-time triage table. Replace `get_hash` with `get_hashes` that returns every result-file extension that exists, and emit one row per (stage, extension) with the elapsed time and peak memory on the stage's first row only. Column order is `.v / .rtlil / .odb / .sdc` so the primary data artifact comes first and the constraint file last. Added a regression test (`test_emits_one_row_per_result_extension`) to lock the two-row-per-stage behaviour in; existing tests cover the no-result-file fallback (single row with ext="" and hash=N/A) since the table now has an Ext column. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent a5839b8 commit 3fde4a2

2 files changed

Lines changed: 81 additions & 22 deletions

File tree

‎flow/test/test_genElapsedTime.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ def test_no_elapsed_time(self, fake_err_output):
7979
genElapsedTime.scan_logs(["--logDir", str(self.tmp_dir.name), "--noHeader"])
8080
self.assertIn("No elapsed time found in", fake_err_output.getvalue())
8181

82+
@patch("sys.stdout", new_callable=StringIO)
83+
def test_emits_one_row_per_result_extension(self, mock_stdout):
84+
# logs/.../1_2_yosys.log accompanied by both .v and .sdc result
85+
# files should produce two rows: .v with the elapsed/peak,
86+
# .sdc with empty elapsed/peak (the row sharing the stage).
87+
log_dir = os.path.join(self.tmp_dir.name, "logs", "p", "d", "base")
88+
res_dir = os.path.join(self.tmp_dir.name, "results", "p", "d", "base")
89+
os.makedirs(log_dir)
90+
os.makedirs(res_dir)
91+
log_path = os.path.join(log_dir, "1_2_yosys.log")
92+
with open(log_path, "w") as f:
93+
f.write("Elapsed time: 00:00:10[h:]min:sec. Peak memory: 51200KB.\n")
94+
with open(os.path.join(res_dir, "1_2_yosys.v"), "w") as f:
95+
f.write("module foo\nendmodule\n")
96+
with open(os.path.join(res_dir, "1_2_yosys.sdc"), "w") as f:
97+
f.write("create_clock -period 10\n")
98+
genElapsedTime.scan_logs(["--logDir", log_dir, "--noHeader"])
99+
out = mock_stdout.getvalue()
100+
lines = [l for l in out.splitlines() if "1_2_yosys" in l]
101+
self.assertEqual(len(lines), 2, out)
102+
self.assertIn(".v", lines[0])
103+
self.assertIn(".sdc", lines[1])
104+
# elapsed (10) and peak (50) show only on the .v row
105+
self.assertIn("10", lines[0])
106+
self.assertIn("50", lines[0])
107+
# the .sdc row repeats neither the elapsed (10) nor peak (50)
108+
# but does include its own hash; check absence of those tokens
109+
self.assertNotIn(" 10 ", " " + lines[1] + " ")
110+
self.assertNotIn(" 50 ", " " + lines[1] + " ")
111+
82112
def tearDown(self):
83113
self.tmp_dir.cleanup()
84114

‎flow/util/genElapsedTime.py‎

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,41 @@
1414
# ==============================================================================
1515

1616

17-
def get_hash(f):
18-
# content hash for the result file alongside .log file is useful to
19-
# debug divergent results under what should be identical
20-
# builds(such as local and CI builds)
21-
for ext in [".odb", ".rtlil", ".v"]:
17+
# Primary data artifacts first, then the SDC constraint file: yosys
18+
# emits .v / .rtlil; OpenROAD stages emit .odb; both often emit a
19+
# .sdc alongside.
20+
RESULT_EXTS = [".v", ".rtlil", ".odb", ".sdc"]
21+
22+
23+
def get_hashes(f):
24+
"""Return [(ext, sha1), ...] for every result file alongside log
25+
`f` whose extension is in RESULT_EXTS. A yosys stage typically
26+
produces both `.v` and `.sdc`; a floorplan/route stage produces
27+
`.odb` (and often `.sdc`); the canonicalize stage produces
28+
`.rtlil`. Hashing each separately makes "the netlist changed"
29+
distinguishable from "the SDC changed" in the elapsed-time table
30+
used to triage divergent local vs CI builds.
31+
32+
Falls back to a single ("", "N/A") entry when no result file
33+
exists so the caller always emits at least one row per stage.
34+
"""
35+
results = []
36+
for ext in RESULT_EXTS:
2237
result_file = pathlib.Path(
2338
str(f).replace("logs/", "results/").replace(".log", ext)
2439
)
2540
if result_file.exists():
2641
hasher = hashlib.sha1()
27-
with open(result_file, "rb") as odb_f:
42+
with open(result_file, "rb") as rf:
2843
while True:
29-
chunk = odb_f.read(16 * 1024 * 1024)
44+
chunk = rf.read(16 * 1024 * 1024)
3045
if not chunk:
3146
break
3247
hasher.update(chunk)
33-
return hasher.hexdigest()
34-
return "N/A"
48+
results.append((ext, hasher.hexdigest()))
49+
if not results:
50+
results.append(("", "N/A"))
51+
return results
3552

3653

3754
def print_log_dir_times(logdir, args):
@@ -87,37 +104,49 @@ def print_log_dir_times(logdir, args):
87104
)
88105
break
89106

90-
odb_hash = get_hash(f)
107+
hashes = get_hashes(f)
91108

92109
if not found:
93110
print("No elapsed time found in", str(f), file=sys.stderr)
94111
continue
95112

96-
# Print the name of the step and the corresponding elapsed time
97-
format_str = "%-25s %10s %14s %20s"
113+
# Print the name of the step and the corresponding elapsed time.
114+
# One row per (stage, result-file-ext); only the first row of a
115+
# stage shows elapsed/peak.
116+
format_str = "%-25s %-6s %10s %14s %20s"
98117
if elapsedTime is not None and peak_memory is not None:
99118
if first and not args.noHeader:
100119
print(
101120
format_str
102-
% ("Log", "Elapsed/s", "Peak Memory/MB", "sha1sum result [0:20)")
121+
% (
122+
"Log",
123+
"Ext",
124+
"Elapsed/s",
125+
"Peak Memory/MB",
126+
"sha1sum result [0:20)",
127+
)
103128
)
104129
first = False
105-
print(
106-
format_str
107-
% (
108-
stem,
109-
elapsedTime,
110-
peak_memory,
111-
odb_hash[0:20],
130+
stage_first = True
131+
for ext, h in hashes:
132+
print(
133+
format_str
134+
% (
135+
stem,
136+
ext,
137+
elapsedTime if stage_first else "",
138+
peak_memory if stage_first else "",
139+
h[0:20],
140+
)
112141
)
113-
)
142+
stage_first = False
114143
if elapsedTime is not None:
115144
totalElapsed += elapsedTime
116145
if peak_memory is not None:
117146
total_max_memory = max(total_max_memory, int(peak_memory))
118147

119148
if totalElapsed != 0 and not args.match:
120-
print(format_str % ("Total", totalElapsed, total_max_memory, ""))
149+
print(format_str % ("Total", "", totalElapsed, total_max_memory, ""))
121150

122151

123152
def scan_logs(args):

0 commit comments

Comments
 (0)