Skip to content

Commit c2ba5c0

Browse files
committed
almost...alive
1 parent 2562d69 commit c2ba5c0

File tree

4 files changed

+83
-32
lines changed

4 files changed

+83
-32
lines changed

gitbench/git.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,33 @@ class BenchRepo(object):
121121
"""
122122
Manage an isolated copy of a repository for benchmarking
123123
"""
124-
def __init__(self, conf):
125-
self.conf = conf
124+
def __init__(self, source_dir, target_dir, build_cmds):
125+
self.source_dir = source_dir
126+
self.target_dir = target_dir
127+
self.build_cmds = build_cmds
128+
self._copy_repo()
129+
130+
def _copy_repo(self):
131+
if os.path.exists(self.target_dir):
132+
print 'Deleting %s first' % self.target_dir
133+
# response = raw_input('%s exists, delete? y/n' % self.target_dir)
134+
# if response == 'n':
135+
# raise Exception('foo')
136+
cmd = 'rm -rf %s' % self.target_dir
137+
print cmd
138+
os.system(cmd)
139+
cmd = 'cp -r %s %s' % (self.source_dir, self.target_dir)
140+
print cmd
141+
os.system(cmd)
142+
143+
self._copy_benchmark_script()
144+
145+
def _copy_benchmark_script(self):
146+
pth, _ = os.path.split(os.path.abspath(__file__))
147+
script_path = os.path.join(pth, 'scripts/gb_run_benchmarks.py')
148+
cmd = 'cp %s %s' % (script_path, self.target_dir)
149+
print cmd
150+
os.system(cmd)
126151

127152
def switch_to_revision(self, rev):
128153
"""
@@ -132,10 +157,25 @@ def switch_to_revision(self, rev):
132157
self._build()
133158

134159
def _checkout(self, rev):
135-
pass
160+
git = _git_command(self.target_dir)
161+
rest = 'checkout -f %s' % rev
162+
args = git.split() + rest.split()
163+
164+
print ' '.join(args)
165+
166+
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
167+
proc.wait()
168+
print proc.stdout.read()
136169

137170
def _build(self):
138-
pass
171+
cmd = ';'.join([x for x in self.build_cmds.split('\n')
172+
if len(x.strip()) > 0])
173+
174+
print cmd
175+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True,
176+
cwd=self.target_dir)
177+
stdout, stderr = proc.communicate()
178+
print stdout
139179

140180

141181
def _convert_timezones(stamps):

gitbench/runner.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cPickle as pickle
22
import os
3+
import subprocess
34

45
from gitbench.git import GitRepo, BenchRepo
56
from gitbench.db import BenchmarkDB
@@ -49,7 +50,7 @@ def run(self):
4950
results = self._run_revision(rev)
5051

5152
for checksum, timing in results.iteritems():
52-
self.db.write_result(checksum, revision,
53+
self.db.write_result(checksum, rev,
5354
timing.get('loops'),
5455
timing.get('timing'),
5556
timing.get('traceback'))
@@ -73,15 +74,25 @@ def _run_revision(self, rev):
7374

7475
print 'Running %d benchmarks for revision %s' % (len(need_to_run), rev)
7576

76-
self._prepare_code(rev)
77+
self.bench_repo.switch_to_revision(rev)
7778

78-
pickle_path = pjoin(self.tmp_dir, 'benchmarks.pickle')
79-
results_path = pjoin(self.tmp_dir, 'results.pickle')
79+
pickle_path = os.path.join(self.tmp_dir, 'benchmarks.pickle')
80+
results_path = os.path.join(self.tmp_dir, 'results.pickle')
8081
if os.path.exists(results_path):
8182
os.remove(results_path)
8283
pickle.dump(need_to_run, open(pickle_path, 'w'))
8384

84-
_run_benchmark_subproc(pickle_path, results_path)
85+
# run the process
86+
cmd = 'python run_benchmarks.py --input=%s --output=%s' % (pickle_path,
87+
results_path)
88+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
89+
cwd=self.tmp_dir)
90+
stdout, stderr = proc.communicate()
91+
92+
print stdout
93+
94+
if stderr:
95+
raise Exception(stderr)
8596

8697
results = pickle.load(open(results_path, 'r'))
8798
os.remove(pickle_path)
@@ -110,12 +121,3 @@ def _get_revisions_to_run(self):
110121
raise Exception('unrecognized run_method %s' % self.run_method)
111122

112123
return revs_to_run
113-
114-
def _prepare_code(self, rev):
115-
self.bench_repo.checkout(rev)
116-
self.bench_repo.build()
117-
118-
def _run_benchmark_subproc(input_path, result_path):
119-
from subprocess import Popen, PIPE
120-
121-

test.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@
33
import gitbench.git as git
44
reload(git)
55

6-
repo_path = '/home/wesm/code/pandas'
7-
repo = git.GitRepo(repo_path)
6+
# repo_path = '/home/wesm/code/pandas'
7+
# repo = git.GitRepo(repo_path)
88

9-
hists = repo.messages
9+
# hists = repo.messages
1010

11-
def churn_graph(repo):
12-
omit_paths = [path for path in churn.major_axis
13-
if not path.endswith('.pyx') or not path.endswith('.py')]
14-
omit_shas = [sha for sha in churn.minor_axis
15-
if 'LF' in hists[sha]]
16-
omit_shas.append('dcf3490')
11+
# def churn_graph(repo):
12+
# omit_paths = [path for path in churn.major_axis
13+
# if not path.endswith('.pyx') or not path.endswith('.py')]
14+
# omit_shas = [sha for sha in churn.minor_axis
15+
# if 'LF' in hists[sha]]
16+
# omit_shas.append('dcf3490')
1717

18-
by_date = repo.get_churn(omit_shas=omit_shas, omit_paths=omit_paths)
19-
by_date = by_date.drop([datetime(2011, 6, 10)])
18+
# by_date = repo.get_churn(omit_shas=omit_shas, omit_paths=omit_paths)
19+
# by_date = by_date.drop([datetime(2011, 6, 10)])
2020

21-
# clean out days where I touched Cython
22-
by_date = by_date[by_date < 5000]
23-
return by_date
21+
# # clean out days where I touched Cython
22+
# by_date = by_date[by_date < 5000]
23+
# return by_date
2424

25+
REPO_PATH = '/home/wesm/code/pandas'
26+
TMP_DIR = '/home/wesm/tmp/gb_pandas'
27+
BUILD = """
28+
python setup.py build_ext --inplace
29+
"""
30+
31+
repo = git.GitRepo(REPO_PATH)
32+
33+
burp = git.BenchRepo(REPO_PATH, TMP_DIR, BUILD)

0 commit comments

Comments
 (0)