Skip to content

Commit 8a267ce

Browse files
committed
First stab at generating example yml and various fixes
1 parent e24b4bb commit 8a267ce

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

git_hashes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ def get_hash_status(h):
7070
hashes.append(h)
7171

7272

73+
elif args.commit_choice_method.startswith('from_hash='):
74+
# get commits from this hash forwards
75+
first_hash = args.commit_choice_method.split('=')[1]
76+
77+
proc_output = shell_exec('git log %s^.. %s --pretty=format:\'%%H %%s\' %s'%(first_hash, first_parent, commit_xtra_args), stdout=subprocess.PIPE)
78+
all_hashes = proc_output.stdout.decode('utf-8').split('\n')[::-1]
79+
all_hashes = filter(bool, all_hashes) # remove empty strings
80+
hashes = [hc.split(' ')[0] for hc in all_hashes]
81+
7382
elif args.commit_choice_method.startswith('hash='):
7483
hashes = args.commit_choice_method.split('=')[1]
7584
hashes = hashes.split(',')

run_sandmark_backfill.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_script_dir():
3838
parser.add_argument('--commit_before', type=str, help='select commits before the specified date (e.g. 2017-10-02)', default=None)
3939
parser.add_argument('--github_oauth_token', type=str, help='oauth token for github api', default=None)
4040
parser.add_argument('--max_hashes', type=int, help='maximum_number of hashes to process', default=1000)
41+
parser.add_argument('--incremental_hashes', action='store_true', default=False)
4142
parser.add_argument('--sandmark_repo', type=str, help='sandmark repo location', default=SANDMARK_REPO)
4243
parser.add_argument('--sandmark_comp_fmt', type=str, help='sandmark location format compiler code', default=SANDMARK_COMP_FMT_DEFAULT)
4344
parser.add_argument('--sandmark_iter', type=int, help='number of sandmark iterations', default=1)
@@ -152,6 +153,16 @@ def check_archive_dir(d):
152153
## generate list of hash commits
153154
hashes = git_hashes.get_git_hashes(args)
154155

156+
if args.incremental_hashes:
157+
def check_hash_new(h):
158+
hash_dir = os.path.join(outdir, h)
159+
hash_already_run = os.path.exists(hash_dir)
160+
if args.verbose and hash_already_run:
161+
print('Found results at %s skipping rerun'%hash_dir)
162+
return not hash_already_run
163+
164+
hashes = [h for h in hashes if check_hash_new(h)]
165+
155166
if args.verbose:
156167
print('Found %d hashes using %s to do %s on'%(len(hashes), args.commit_choice_method, args.run_stages))
157168

sandmark_batch_example.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
scratchdir: "/local/scratch/ctk21/cust" # working location for benchmark runs
3+
bench_core: "4" # core that the benchmarks will run on
4+
environment: "bench2.ocamllabs.io" # codespeed environment tag
5+
exec_spec: "vanilla:" # "<executable>:" defines the codespeed executable tag
6+
codespeed_url: "http://localhost:8083/" # codespeed location for upload
7+
ocamlspeed_dir: "/home/ctk21/proj/ocamlspeed_sandmark_custom" # location of ocamlspeed instance
8+
9+
# list of github branches to run benchmarks for
10+
tracked_branches:
11+
- github_user: "kayceesrk" # github username for repo
12+
github_repo: "ocaml" # github repo name
13+
branch: "closure_rec" # git branch name
14+
first_commit: "9618f860e580d8f491d980b9f84d785f1651a3b8" # first commit of interest (all commits after this are executed)
15+
ocaml_version: "4.10.0" # ocaml base version for the branch (needed for opam)
16+
run_path_tag: "kc1" # short tag for location of run (needs to be small less than ~5 characters)
17+
codespeed_name: "kc_closure_rec" # name that will appear in the codespeed front end

sandmark_batch_generator.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import datetime
5+
import glob
6+
import inspect
7+
import os
8+
import subprocess
9+
import yaml
10+
11+
def get_script_dir():
12+
return os.path.dirname(inspect.getabsfile(get_script_dir))
13+
14+
SCRIPTDIR = get_script_dir()
15+
16+
parser = argparse.ArgumentParser(description='Convert a batch config to a collection of run scripts')
17+
parser.add_argument('config', type=str, help='config file' )
18+
parser.add_argument('outdir', type=str, help='directory of output')
19+
parser.add_argument('-v', '--verbose', action='store_true', default=False)
20+
21+
args = parser.parse_args()
22+
23+
24+
SCRIPT_PREAMBLE = '''#!/bin/sh
25+
26+
# don't allow unset variables
27+
set -o nounset
28+
29+
# be verbose as we execute
30+
set -x
31+
32+
TIMESTAMP=`date +'%Y%m%d_%H%M%S'`
33+
34+
# make sure python log files are in order
35+
PYTHONUNBUFFERED=true
36+
37+
'''
38+
39+
SCRIPT_PARAMS = '''
40+
SCRIPTDIR={scriptdir}
41+
SCRATCHDIR={scratchdir}
42+
43+
BENCH_CORE={bench_core}
44+
ENVIRONMENT={environment}
45+
EXEC_SPEC={exec_spec}
46+
CODESPEED_URL={codespeed_url}
47+
CODESPEED_DB={ocamlspeed_dir}/data/data.db
48+
ARCHIVE_DIR={ocamlspeed_dir}/artifacts/
49+
50+
GITHUB_USER={github_user}
51+
GITHUB_REPO={github_repo}
52+
BRANCH={branch}
53+
FIRST_COMMIT={first_commit}
54+
OCAML_VERSION={ocaml_version}
55+
RUN_PATH_TAG={run_path_tag}
56+
CODESPEED_NAME={codespeed_name}
57+
58+
'''
59+
60+
SCRIPT_BODY = '''
61+
RUNDIR=${SCRATCHDIR}/${RUN_PATH_TAG}
62+
63+
RUN_STAGES=setup,bench,archive,upload
64+
65+
66+
# needed to get the path to include a dune binary
67+
# NB: a full eval $(opam config env) breaks the sandmark build in a strange way...
68+
eval $(opam config env | grep ^PATH=)
69+
70+
mkdir -p ${ARCHIVE_DIR}
71+
72+
## STAGES:
73+
## - get local copy of git repo
74+
## - setup target codespeed db to see project
75+
## - run backfill script to do it
76+
77+
78+
cd $SCRIPTDIR
79+
80+
## get local copy of git repo
81+
REPO=${GITHUB_USER}__${GITHUB_REPO}
82+
if [ ! -d ${REPO} ]; then
83+
git clone https://github.com/${GITHUB_USER}/${GITHUB_REPO}.git ${REPO}
84+
fi
85+
86+
## setup target codespeed db to see project
87+
sqlite3 ${CODESPEED_DB} "INSERT INTO codespeed_project (name,repo_type,repo_path,repo_user,repo_pass,commit_browsing_url,track,default_branch) SELECT '${CODESPEED_NAME}', 'G', 'https://github.com/${GITHUB_USER}/ocaml', '${GITHUB_USER}', '', 'https://github.com/${GITHUB_USER}/${GITHUB_REPO}/commit/{commitid}',1,'${BRANCH}' WHERE NOT EXISTS(SELECT 1 FROM codespeed_project WHERE name = '${CODESPEED_NAME}')"
88+
89+
90+
## run backfill script
91+
./run_sandmark_backfill.py --run_stages ${RUN_STAGES} --branch ${BRANCH} --main_branch ${BRANCH} --repo ${REPO} --repo_pull --repo_reset_hard --use_repo_reference --incremental_hashes --commit_choice_method from_hash=${FIRST_COMMIT} --executable_spec=${EXEC_SPEC} --environment ${ENVIRONMENT} --sandmark_comp_fmt https://github.com/${GITHUB_USER}/${GITHUB_REPO}/archive/{tag}.tar.gz --sandmark_tag_override ${OCAML_VERSION} --sandmark_iter 1 --sandmark_pre_exec="'taskset --cpu-list "${BENCH_CORE}" setarch `uname -m` --addr-no-randomize'" --archive_dir ${ARCHIVE_DIR} --codespeed_url ${CODESPEED_URL} --upload_project_name ${CODESPEED_NAME} -v ${RUNDIR}
92+
93+
94+
'''
95+
96+
def shell_exec(cmd, verbose=args.verbose, check=False, stdout=None, stderr=None):
97+
if verbose:
98+
print('+ %s'%cmd)
99+
return subprocess.run(cmd, shell=True, check=check, stdout=stdout, stderr=stderr)
100+
101+
outdir = os.path.abspath(args.outdir)
102+
if args.verbose: print('making directory: %s'%outdir)
103+
shell_exec('mkdir -p %s'%outdir)
104+
105+
global_conf = {
106+
'scriptdir': SCRIPTDIR,
107+
}
108+
109+
# read in yaml config
110+
with open(args.config, 'r') as stream:
111+
try:
112+
conf = yaml.safe_load(stream)
113+
except yaml.YAMLError as exc:
114+
print('YAMLError: %s'%exc)
115+
sys.exit(1)
116+
117+
# output the script
118+
for run_conf in conf['tracked_branches']:
119+
fname = os.path.join(outdir, '%s.sh'%run_conf['codespeed_name'])
120+
with open(fname, 'w') as outfile:
121+
outfile.write(SCRIPT_PREAMBLE)
122+
conf_str = SCRIPT_PARAMS.format(**{**global_conf, **conf, **run_conf})
123+
outfile.write(conf_str)
124+
outfile.write(SCRIPT_BODY)
125+
shell_exec('chmod +x %s'%fname)
126+
127+

0 commit comments

Comments
 (0)