Skip to content

Commit 1b8f63e

Browse files
committed
Report startup in harness.py
1 parent 0415136 commit 1b8f63e

File tree

1 file changed

+24
-3
lines changed
  • graalpython/com.oracle.graal.python.benchmarks/python

1 file changed

+24
-3
lines changed

graalpython/com.oracle.graal.python.benchmarks/python/harness.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
import os
4242
import sys
4343
import types
44-
from time import time
44+
from time import time, monotonic_ns
4545

46+
GRAALPYTHON = sys.implementation.name == "graalpython"
4647

4748
_HRULE = '-'.join(['' for i in range(80)])
4849

@@ -195,7 +196,7 @@ def _as_int(value):
195196

196197

197198
class BenchRunner(object):
198-
def __init__(self, bench_file, bench_args=None, iterations=1, warmup=-1, warmup_runs=0):
199+
def __init__(self, bench_file, bench_args=None, iterations=1, warmup=-1, warmup_runs=0, startup=False):
199200
assert isinstance(iterations, int), \
200201
"BenchRunner iterations argument must be an int, got %s instead" % iterations
201202
assert isinstance(warmup, int), \
@@ -213,6 +214,7 @@ def __init__(self, bench_file, bench_args=None, iterations=1, warmup=-1, warmup_
213214
self.iterations = 1 if self._run_once else _iterations
214215
self.warmup_runs = warmup_runs if warmup_runs > 0 else 0
215216
self.warmup = warmup if warmup > 0 else -1
217+
self.startup = startup
216218

217219
@staticmethod
218220
def get_bench_module(bench_file):
@@ -271,19 +273,28 @@ def run(self):
271273
self._call_attr(ATTR_SETUP, *args)
272274
print("### start benchmark ... ")
273275

276+
report_startup = GRAALPYTHON and self.startup and __graalpython__.startup_nano != -1
277+
274278
bench_func = self._get_attr(ATTR_BENCHMARK)
279+
startup = -1
275280
durations = []
276281
if bench_func and hasattr(bench_func, '__call__'):
277282
if self.warmup_runs:
278283
print("### (pre)warming up for %s iterations ... " % self.warmup_runs)
279284
for _ in range(self.warmup_runs):
280285
bench_func(*args)
286+
cur_time_nano = monotonic_ns()
287+
if report_startup and startup == -1:
288+
startup = cur_time_nano - __graalpython__.startup_nano
281289
self._call_attr(ATTR_CLEANUP, *args)
282290

283291
for iteration in range(self.iterations):
284292
start = time()
285293
bench_func(*args)
294+
cur_time_nano = monotonic_ns()
286295
duration = time() - start
296+
if report_startup and startup == -1:
297+
startup = cur_time_nano - __graalpython__.startup_nano
287298
durations.append(duration)
288299
duration_str = "%.3f" % duration
289300
self._call_attr(ATTR_CLEANUP, *args)
@@ -311,6 +322,9 @@ def run(self):
311322
print(_HRULE)
312323

313324
# summary
325+
# We can do that only on Graalpython
326+
if report_startup:
327+
print("### STARTUP duration: %.3f s" % (startup / 10e9))
314328
if self._run_once:
315329
print("### SINGLE RUN duration: %.3f s" % durations[0])
316330
else:
@@ -333,6 +347,9 @@ def run(self):
333347
else:
334348
print("### WARMUP iteration not specified or could not be detected")
335349

350+
if GRAALPYTHON and self.startup and __graalpython__.startup_nano == -1:
351+
print("### Startup could not be measured. You need to enable startup time snapshotting.")
352+
336353
print(_HRULE)
337354
print("### RAW DURATIONS: %s" % str(durations))
338355
print(_HRULE)
@@ -342,6 +359,7 @@ def run_benchmark(args):
342359
warmup = -1
343360
warmup_runs = 0
344361
iterations = 1
362+
startup = False
345363
bench_file = None
346364
bench_args = []
347365
paths = []
@@ -367,6 +385,9 @@ def run_benchmark(args):
367385
elif arg.startswith("--warmup-runs"):
368386
warmup_runs = _as_int(arg.split("=")[1])
369387

388+
elif arg == '-s' or arg == '--startup':
389+
startup = True
390+
370391
elif arg == '-p':
371392
i += 1
372393
paths = args[i].split(",")
@@ -389,7 +410,7 @@ def run_benchmark(args):
389410
else:
390411
print("### no extra module search paths specified")
391412

392-
BenchRunner(bench_file, bench_args=bench_args, iterations=iterations, warmup=warmup, warmup_runs=warmup_runs).run()
413+
BenchRunner(bench_file, bench_args=bench_args, iterations=iterations, warmup=warmup, warmup_runs=warmup_runs, startup=startup).run()
393414

394415

395416
if __name__ == '__main__':

0 commit comments

Comments
 (0)