23
23
# for more.
24
24
COMPARE_FACTOR = 1.2
25
25
26
+ BENCHMARKS_DIR = Path (__file__ ).parent
26
27
27
28
# Common ASV arguments for all run_types except `custom`.
28
29
ASV_HARNESS = (
29
- "asv run {posargs} --attribute rounds=4 --interleave-rounds --strict "
30
+ "run {posargs} --attribute rounds=4 --interleave-rounds --strict "
30
31
"--show-stderr"
31
32
)
32
33
33
34
35
+ def _subprocess_run_print (args , ** kwargs ):
36
+ print (f"BM_RUNNER DEBUG: { ' ' .join (args )} " )
37
+ return subprocess .run (args , ** kwargs )
38
+
39
+
40
+ def _subprocess_run_asv (args , ** kwargs ):
41
+ args .insert (0 , "asv" )
42
+ kwargs ["cwd" ] = BENCHMARKS_DIR
43
+ return _subprocess_run_print (args , ** kwargs )
44
+
45
+
34
46
def _check_requirements (package : str ) -> None :
35
47
try :
36
48
import_module (package )
@@ -47,7 +59,7 @@ def _prep_data_gen_env() -> None:
47
59
Create/access a separate, unchanging environment for generating test data.
48
60
"""
49
61
50
- root_dir = Path ( __file__ ). parents [ 1 ]
62
+ root_dir = BENCHMARKS_DIR . parent
51
63
python_version = "3.10"
52
64
data_gen_var = "DATA_GEN_PYTHON"
53
65
if data_gen_var in environ :
@@ -56,7 +68,7 @@ def _prep_data_gen_env() -> None:
56
68
print ("Setting up the data generation environment ..." )
57
69
# Get Nox to build an environment for the `tests` session, but don't
58
70
# run the session. Will re-use a cached environment if appropriate.
59
- subprocess . run (
71
+ _subprocess_run_print (
60
72
[
61
73
"nox" ,
62
74
f"--noxfile={ root_dir / 'noxfile.py' } " ,
@@ -75,15 +87,15 @@ def _prep_data_gen_env() -> None:
75
87
print ("Installing Mule into data generation environment ..." )
76
88
mule_dir = data_gen_python .parents [1 ] / "resources" / "mule"
77
89
if not mule_dir .is_dir ():
78
- subprocess . run (
90
+ _subprocess_run_print (
79
91
[
80
92
"git" ,
81
93
"clone" ,
82
94
"https://github.com/metomi/mule.git" ,
83
95
str (mule_dir ),
84
96
]
85
97
)
86
- subprocess . run (
98
+ _subprocess_run_print (
87
99
[
88
100
str (data_gen_python ),
89
101
"-m" ,
@@ -103,28 +115,28 @@ def _setup_common() -> None:
103
115
_prep_data_gen_env ()
104
116
105
117
print ("Setting up ASV ..." )
106
- subprocess . run ([ "asv" , "machine" , "--yes" ])
118
+ _subprocess_run_asv ([ "machine" , "--yes" ])
107
119
108
120
print ("Setup complete." )
109
121
110
122
111
123
def _asv_compare (* commits : str , overnight_mode : bool = False ) -> None :
112
124
"""Run through a list of commits comparing each one to the next."""
113
125
commits = [commit [:8 ] for commit in commits ]
114
- shifts_dir = Path ( ".asv" ) / "performance-shifts"
126
+ shifts_dir = BENCHMARKS_DIR / ".asv" / "performance-shifts"
115
127
for i in range (len (commits ) - 1 ):
116
128
before = commits [i ]
117
129
after = commits [i + 1 ]
118
130
asv_command = (
119
- f"asv compare { before } { after } --factor={ COMPARE_FACTOR } --split"
131
+ f"compare { before } { after } --factor={ COMPARE_FACTOR } --split"
120
132
)
121
- subprocess . run (asv_command .split (" " ))
133
+ _subprocess_run_asv (asv_command .split (" " ))
122
134
123
135
if overnight_mode :
124
136
# Record performance shifts.
125
137
# Run the command again but limited to only showing performance
126
138
# shifts.
127
- shifts = subprocess . run (
139
+ shifts = _subprocess_run_asv (
128
140
[* asv_command .split (" " ), "--only-changed" ],
129
141
capture_output = True ,
130
142
text = True ,
@@ -207,11 +219,11 @@ def func(args: argparse.Namespace) -> None:
207
219
208
220
commit_range = f"{ args .first_commit } ^^.."
209
221
asv_command = ASV_HARNESS .format (posargs = commit_range )
210
- subprocess . run ([* asv_command .split (" " ), * args .asv_args ])
222
+ _subprocess_run_asv ([* asv_command .split (" " ), * args .asv_args ])
211
223
212
224
# git rev-list --first-parent is the command ASV uses.
213
225
git_command = f"git rev-list --first-parent { commit_range } "
214
- commit_string = subprocess . run (
226
+ commit_string = _subprocess_run_print (
215
227
git_command .split (" " ), capture_output = True , text = True
216
228
).stdout
217
229
commit_list = commit_string .rstrip ().split ("\n " )
@@ -246,7 +258,7 @@ def func(args: argparse.Namespace) -> None:
246
258
_setup_common ()
247
259
248
260
git_command = f"git merge-base HEAD { args .base_branch } "
249
- merge_base = subprocess . run (
261
+ merge_base = _subprocess_run_print (
250
262
git_command .split (" " ), capture_output = True , text = True
251
263
).stdout [:8 ]
252
264
@@ -255,7 +267,7 @@ def func(args: argparse.Namespace) -> None:
255
267
hashfile .flush ()
256
268
commit_range = f"HASHFILE:{ hashfile .name } "
257
269
asv_command = ASV_HARNESS .format (posargs = commit_range )
258
- subprocess . run ([* asv_command .split (" " ), * args .asv_args ])
270
+ _subprocess_run_asv ([* asv_command .split (" " ), * args .asv_args ])
259
271
260
272
_asv_compare (merge_base , "HEAD" )
261
273
@@ -312,13 +324,13 @@ def csperf(
312
324
asv_command = asv_command .replace (" --strict" , "" )
313
325
# Only do a single round.
314
326
asv_command = re .sub (r"rounds=\d" , "rounds=1" , asv_command )
315
- subprocess . run ([* asv_command .split (" " ), * args .asv_args ])
327
+ _subprocess_run_asv ([* asv_command .split (" " ), * args .asv_args ])
316
328
317
- asv_command = f"asv publish { commit_range } --html-dir={ publish_subdir } "
318
- subprocess . run (asv_command .split (" " ))
329
+ asv_command = f"publish { commit_range } --html-dir={ publish_subdir } "
330
+ _subprocess_run_asv (asv_command .split (" " ))
319
331
320
332
# Print completion message.
321
- location = Path (). cwd () / ".asv"
333
+ location = BENCHMARKS_DIR / ".asv"
322
334
print (
323
335
f'New ASV results for "{ run_type } ".\n '
324
336
f'See "{ publish_subdir } ",'
@@ -366,7 +378,7 @@ def add_arguments(self) -> None:
366
378
@staticmethod
367
379
def func (args : argparse .Namespace ) -> None :
368
380
_setup_common ()
369
- subprocess . run ([ "asv" , args .asv_sub_command , * args .asv_args ])
381
+ _subprocess_run_asv ([ args .asv_sub_command , * args .asv_args ])
370
382
371
383
372
384
def main ():
0 commit comments