Skip to content

Commit 351845a

Browse files
committed
Moved ODB hashing into its own method and made it compatible with pre-Python 3.8
Signed-off-by: Jeff Ng <[email protected]>
1 parent eb2be3a commit 351845a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

flow/util/genElapsedTime.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
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"]:
22+
result_file = pathlib.Path(
23+
str(f).replace("logs/", "results/").replace(".log", ext)
24+
)
25+
if result_file.exists():
26+
hasher = hashlib.sha1()
27+
with open(result_file, "rb") as odb_f:
28+
while True:
29+
chunk = odb_f.read(16 * 1024 * 1024)
30+
if not chunk:
31+
break
32+
hasher.update(chunk)
33+
return hasher.hexdigest()
34+
return "N/A"
35+
36+
1737
def print_log_dir_times(logdir, args):
1838
first = True
1939
totalElapsed = 0
@@ -66,22 +86,7 @@ def print_log_dir_times(logdir, args):
6686
int(line.split("Peak memory: ")[1].split("KB")[0]) / 1024
6787
)
6888

69-
# content hash for the result file alongside .log file is useful to
70-
# debug divergent results under what should be identical
71-
# builds(such as local and CI builds)
72-
for ext in [".odb", ".rtlil", ".v"]:
73-
result_file = pathlib.Path(
74-
str(f).replace("logs/", "results/").replace(".log", ext)
75-
)
76-
if result_file.exists():
77-
hasher = hashlib.sha1()
78-
with open(result_file, "rb") as odb_f:
79-
while chunk := odb_f.read(16 * 1024 * 1024):
80-
hasher.update(chunk)
81-
odb_hash = hasher.hexdigest()
82-
break
83-
else:
84-
odb_hash = "N/A"
89+
odb_hash = get_hash(f)
8590

8691
if not found:
8792
print("No elapsed time found in", str(f), file=sys.stderr)

0 commit comments

Comments
 (0)