#58: the discovery walk runs in 512-entry slices with requests drained between them (lucisv_core ResumableWalk, state/walking.rs); identities are read in one pass at landing. Proved equal to the one-shot walk. #64: the 40k rescan timing split is not reproducible; the store is kept across rescans, compaction streams, candidates are cheaper (-12% on 40k, answers and store byte-identical). Files topo #71-#74. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
103 lines
3.9 KiB
Python
103 lines
3.9 KiB
Python
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
|
|
|
"""Build the replicated OpenTitan tree the 40 000-file rescan is measured on.
|
|
|
|
`docs/features/fast-actions/README.md` measured its 20k / 40k rows on copies
|
|
of OpenTitan `hw/` replicated 5 / 10 times under `c0/ ... c9/`, every module,
|
|
package, interface, program and class name declared anywhere prefixed `cK_`
|
|
in copy K, so that the copies do not collapse into one set of duplicate
|
|
definitions. That generator (`gen.py`) lived in a scratch directory and is
|
|
gone; this is its replacement, kept here so the tree can be rebuilt.
|
|
|
|
python3 tools/perf/bigtree.py --opentitan ~/repo/opentitan --copies 10 \
|
|
--out "$SCRATCH/ot10"
|
|
|
|
Python 3 standard library only. **The corpus is only read**: every byte goes
|
|
to `--out`, which must not be inside the corpus or the repository, and which
|
|
is refused when it already exists (delete it yourself, so a typo cannot
|
|
delete anything else). Files whose text is not UTF-8 are copied as bytes.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
EXTENSIONS = (".sv", ".v", ".svh", ".vh")
|
|
DECL = re.compile(
|
|
r"^\s*(?:virtual\s+)?(?:module|macromodule|package|interface|program|class)"
|
|
r"\s+(?:automatic\s+|static\s+)?([A-Za-z_][A-Za-z0-9_$]*)",
|
|
re.MULTILINE,
|
|
)
|
|
IDENT = re.compile(r"\b[A-Za-z_][A-Za-z0-9_]*\b")
|
|
|
|
|
|
def sources(hw):
|
|
"""Every source file under `hw`, as paths relative to it, sorted."""
|
|
found = []
|
|
for base, dirs, files in os.walk(hw):
|
|
dirs.sort()
|
|
for name in sorted(files):
|
|
if name.endswith(EXTENSIONS):
|
|
found.append(os.path.relpath(os.path.join(base, name), hw))
|
|
return found
|
|
|
|
|
|
def declared_names(hw, files):
|
|
"""Every unit name any file declares — what each copy prefixes."""
|
|
names = set()
|
|
for rel in files:
|
|
with open(os.path.join(hw, rel), "rb") as handle:
|
|
text = handle.read().decode("utf-8", "replace")
|
|
names.update(DECL.findall(text))
|
|
return names
|
|
|
|
|
|
def renamed(text, names, prefix):
|
|
"""`text` with every whole-word use of a declared name prefixed."""
|
|
return IDENT.sub(lambda m: prefix + m.group(0) if m.group(0) in names else m.group(0), text)
|
|
|
|
|
|
def write_copy(hw, files, names, out, k):
|
|
prefix = "c%d_" % k
|
|
for rel in files:
|
|
target = os.path.join(out, "c%d" % k, rel)
|
|
os.makedirs(os.path.dirname(target), exist_ok=True)
|
|
with open(os.path.join(hw, rel), "rb") as handle:
|
|
raw = handle.read()
|
|
try:
|
|
data = renamed(raw.decode("utf-8"), names, prefix).encode("utf-8")
|
|
except UnicodeDecodeError:
|
|
data = raw
|
|
with open(target, "wb") as handle:
|
|
handle.write(data)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument("--opentitan", required=True)
|
|
parser.add_argument("--copies", type=int, default=10)
|
|
parser.add_argument("--out", required=True)
|
|
args = parser.parse_args()
|
|
hw = os.path.realpath(os.path.join(args.opentitan, "hw"))
|
|
out = os.path.realpath(args.out)
|
|
here = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
for forbidden in (os.path.realpath(args.opentitan), here):
|
|
if out == forbidden or out.startswith(forbidden + os.sep):
|
|
sys.exit("bigtree: --out must be outside %s" % forbidden)
|
|
if os.path.exists(out):
|
|
sys.exit("bigtree: %s exists; remove it first" % out)
|
|
files = sources(hw)
|
|
names = declared_names(hw, files)
|
|
print("bigtree: %d files, %d declared names, %d copies" % (len(files), len(names), args.copies))
|
|
for k in range(args.copies):
|
|
write_copy(hw, files, names, out, k)
|
|
print("bigtree: copy %d written" % k, flush=True)
|
|
print("bigtree: %d files under %s" % (len(files) * args.copies, out))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|