Skip to content
Snippets Groups Projects
Commit 00f612a8 authored by Boris Feld's avatar Boris Feld
Browse files

Add script to recompute reference tar benchrepo data

parent 06523a7e
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
"""Update a benchrepo reference tar with the repo format data
Accept a tar archive containing a benchrepo and the repository, untar the
repository, recompute the stats and update the benchrepo file in the tar
archive in-place
"""
import argparse
import os
import os.path
import shutil
import sys
import tarfile
import tempfile
from os.path import abspath, basename, dirname, join
import yaml
parent_dir = abspath(join(dirname(abspath(__file__)), ".."))
sys.path.insert(0, join(parent_dir, "lib"))
from scmperf_lib import gather_repo_stats # isort:skip
def _main(reference_archive_path, tmp_directory):
# Extract the files
print("Extracting the tar.")
with tarfile.open(reference_archive_path, "r") as reference_archive:
reference_archive.extractall(tmp_directory)
# Find the benchrepo file
topdir_file = os.listdir(tmp_directory)
assert len(topdir_file) == 2
benchrepo = [x for x in topdir_file if x.endswith(".benchrepo")]
assert len(benchrepo) == 1
benchrepo = benchrepo[0]
benchrepo_path = join(tmp_directory, benchrepo)
topdir_file.remove(benchrepo)
repository = topdir_file[0]
repository_path = join(tmp_directory, repository)
# Read the benchrepo file
print("Reading the original benchrepo file.")
with open(benchrepo_path) as benchrepo_file:
benchrepo_data = yaml.load(benchrepo_file.read())
# Compute the new stats
print("Gathering the new benchrepo data.")
new_benchrepo_data = gather_repo_stats(
repository_path,
benchrepo_data["reference-repo"]["id"],
benchrepo_data["reference-repo"]["source"],
)
# And write it
with open(benchrepo_path, "w") as new_benchrepo_file:
new_benchrepo_file.write(
yaml.dump(new_benchrepo_data, default_flow_style=False)
)
# Write the new stats in the tar
print("Archiving the new benchrepo file.")
with tarfile.open(join(tmp_directory, "tmp.tar"), "w") as new_tar_file:
new_tar_file.add(benchrepo_path, arcname=benchrepo)
new_tar_file.add(repository_path, arcname=repository)
# And finally overwrite the original tar in place
print("Overwriting the original archive")
shutil.move(join(tmp_directory, "tmp.tar"), reference_archive_path)
def main(args):
parser = argparse.ArgumentParser(description=__doc__.splitlines(1)[0])
parser.add_argument("reference_archive.tar")
args = parser.parse_args(args)
reference_archive_path = getattr(args, "reference_archive.tar")
tmp_directory = tempfile.mkdtemp()
try:
_main(reference_archive_path, tmp_directory)
finally:
print("Removing the temporary directory.")
shutil.rmtree(tmp_directory)
if __name__ == "__main__":
main(sys.argv[1:])
======================================
Test for the `update benchrepo` script
======================================
Setup
$ export PATH=$TESTDIR/../repo-scripts/:${PATH}
$ mkdir some-dir
$ hg init some-dir/my-source-repo
$ cd some-dir/
$ hg -R my-source-repo debugbuilddag --new-file '.+5:brancha$.+11:branchb$.+30:branchc<brancha+2<branchb+2'
$ cat << EOF > my-source-repo.benchrepo
> reference-repo:
> id: my-reference
> source: some-dir/my-source-repo
> EOF
$ cat my-source-repo.benchrepo
reference-repo:
id: my-reference
source: some-dir/my-source-repo
$ tar cf "my-reference.tar" "my-source-repo.benchrepo" "my-source-repo"
Wrong call
----------
$ update-benchrepo --help
usage: update-benchrepo [-h] reference_archive.tar
Update a benchrepo reference tar with the repo format data
positional arguments:
reference_archive.tar
optional arguments:
-h, --help show this help message and exit
$ update-benchrepo
usage: update-benchrepo [-h] reference_archive.tar
update-benchrepo: error: too few arguments
[2]
Actual call
-----------
$ update-benchrepo my-reference.tar
Extracting the tar.
Reading the original benchrepo file.
Gathering the new benchrepo data.
Archiving the new benchrepo file.
Overwriting the original archive
Removing the temporary directory.
$ cd ..
$ cat my-source-repo.benchrepo
cat: my-source-repo.benchrepo: No such file or directory
[1]
$ tar tf some-dir/my-reference.tar | sort
my-source-repo.benchrepo
my-source-repo/
my-source-repo/.hg/
my-source-repo/.hg/00changelog.i
my-source-repo/.hg/cache/
my-source-repo/.hg/cache/branch2-served
my-source-repo/.hg/cache/manifestfulltextcache
my-source-repo/.hg/cache/rbc-names-v1
my-source-repo/.hg/cache/rbc-revs-v1
my-source-repo/.hg/dirstate
my-source-repo/.hg/localtags
my-source-repo/.hg/requires
my-source-repo/.hg/store/
my-source-repo/.hg/store/00changelog.i
my-source-repo/.hg/store/00manifest.i
my-source-repo/.hg/store/data/
my-source-repo/.hg/store/data/nf0.i
my-source-repo/.hg/store/data/nf1.i
my-source-repo/.hg/store/data/nf10.i
my-source-repo/.hg/store/data/nf11.i
my-source-repo/.hg/store/data/nf12.i
my-source-repo/.hg/store/data/nf13.i
my-source-repo/.hg/store/data/nf14.i
my-source-repo/.hg/store/data/nf15.i
my-source-repo/.hg/store/data/nf16.i
my-source-repo/.hg/store/data/nf17.i
my-source-repo/.hg/store/data/nf18.i
my-source-repo/.hg/store/data/nf19.i
my-source-repo/.hg/store/data/nf2.i
my-source-repo/.hg/store/data/nf20.i
my-source-repo/.hg/store/data/nf21.i
my-source-repo/.hg/store/data/nf22.i
my-source-repo/.hg/store/data/nf23.i
my-source-repo/.hg/store/data/nf24.i
my-source-repo/.hg/store/data/nf25.i
my-source-repo/.hg/store/data/nf26.i
my-source-repo/.hg/store/data/nf27.i
my-source-repo/.hg/store/data/nf28.i
my-source-repo/.hg/store/data/nf29.i
my-source-repo/.hg/store/data/nf3.i
my-source-repo/.hg/store/data/nf30.i
my-source-repo/.hg/store/data/nf31.i
my-source-repo/.hg/store/data/nf32.i
my-source-repo/.hg/store/data/nf33.i
my-source-repo/.hg/store/data/nf34.i
my-source-repo/.hg/store/data/nf35.i
my-source-repo/.hg/store/data/nf36.i
my-source-repo/.hg/store/data/nf37.i
my-source-repo/.hg/store/data/nf38.i
my-source-repo/.hg/store/data/nf39.i
my-source-repo/.hg/store/data/nf4.i
my-source-repo/.hg/store/data/nf40.i
my-source-repo/.hg/store/data/nf41.i
my-source-repo/.hg/store/data/nf42.i
my-source-repo/.hg/store/data/nf43.i
my-source-repo/.hg/store/data/nf44.i
my-source-repo/.hg/store/data/nf45.i
my-source-repo/.hg/store/data/nf46.i
my-source-repo/.hg/store/data/nf47.i
my-source-repo/.hg/store/data/nf48.i
my-source-repo/.hg/store/data/nf49.i
my-source-repo/.hg/store/data/nf5.i
my-source-repo/.hg/store/data/nf50.i
my-source-repo/.hg/store/data/nf51.i
my-source-repo/.hg/store/data/nf52.i
my-source-repo/.hg/store/data/nf6.i
my-source-repo/.hg/store/data/nf7.i
my-source-repo/.hg/store/data/nf8.i
my-source-repo/.hg/store/data/nf9.i
my-source-repo/.hg/store/fncache
my-source-repo/.hg/store/phaseroots
my-source-repo/.hg/store/undo
my-source-repo/.hg/store/undo.backupfiles
my-source-repo/.hg/store/undo.phaseroots
my-source-repo/.hg/undo.bookmarks
my-source-repo/.hg/undo.branch
my-source-repo/.hg/undo.desc
my-source-repo/.hg/undo.dirstate
my-source-repo/.hg/wcache/
$ tar -xf some-dir/my-reference.tar my-source-repo.benchrepo
$ cat my-source-repo.benchrepo
reference-repo:
enabled: true
format-info:
compression: zlib
dotencode: true
fncache: true
generaldelta: true
plain-cl-delta: true
sparserevlog: true
hg-version: * (glob)
id: my-reference
number-heads:
all: 3
visible: 3
number-named-branch:
all: 1
visible: 1
number-revisions:
all: 53
visible: 53
source: some-dir/my-source-repo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment