Skip to content
Snippets Groups Projects
Commit 048b43c5 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

simple-command: add a `gather-info` field to help gather runtime information

Explanations inline, this will be useful for SWH postgres testing
parent ae879b6d
No related branches found
No related tags found
No related merge requests found
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
......@@ -231,5 +232,6 @@
prepare = self.get_var("simple-command.prepare-run")
cleanup = self.get_var("simple-command.cleanup-run")
gather_info = self.get_var("simple-command.gather-info")
temp_dir = tempfile.mkdtemp() # TODO same tmp dir as `copy-data-env`
try:
......@@ -234,9 +236,9 @@
temp_dir = tempfile.mkdtemp() # TODO same tmp dir as `copy-data-env`
try:
r = self._time_command(
r, runtime_info = self._time_command(
bin_env_path,
data_env_path,
cmd,
temp_dir=temp_dir,
prepare=prepare,
cleanup=cleanup,
......@@ -237,9 +239,10 @@
bin_env_path,
data_env_path,
cmd,
temp_dir=temp_dir,
prepare=prepare,
cleanup=cleanup,
gather_info=gather_info,
debug=debug,
)
finally:
......@@ -256,6 +259,9 @@
res["time"]["standard-deviation"] = r["results"][0]["stddev"]
res["time"]["min"] = r["results"][0]["min"]
res["time"]["max"] = r["results"][0]["max"]
if runtime_info is not None:
# XXX is there a better place to store this?
res["runtime_info"] = runtime_info
return res
def _time_command(
......@@ -266,6 +272,7 @@
temp_dir,
prepare=None,
cleanup=None,
gather_info=None,
debug=False,
):
bin_env_path = os.path.abspath(bin_env_path)
......@@ -344,6 +351,35 @@
else:
stdout = subprocess.PIPE
stderr = subprocess.PIPE
runtime_info = None
if gather_info is not None:
if not bool(self.get_var("simple-command.no-set-builtin")):
gather_info = f"set -eEuo pipefail; {gather_info}"
r = subprocess.run(
[shell_path, "/bin/bash", "-c", gather_info],
cwd=cwd,
env=env,
stdout=stdout,
stderr=stderr,
)
if r.returncode != 0:
raise errors.BenchmarkRunFailure(
command=gather_info,
cwd=cwd,
return_code=r.returncode,
stdout=r.stdout,
stderr=r.stderr,
message="Gathering information prior to benchmark failed",
)
runtime_info_path = Path(temp_dir) / "gathered_info.json"
try:
with runtime_info_path.open(mode="r") as f:
runtime_info = json.load(f)
# clean up incase it somehow affects the rest of it
os.unlink(runtime_info_path)
except FileNotFoundError:
pass
r = subprocess.run(
time_cmd, cwd=cwd, env=env, stdout=stdout, stderr=stderr
)
......@@ -379,7 +415,7 @@
stderr=r.stderr,
message=msg,
)
return results_as_json
return results_as_json, runtime_info
class SimpleCommand(object):
......
......@@ -7,6 +7,14 @@
/// It can we extended with variants (see next section)
command = String
/// A command (or series of commands) to run before the entire benchmark
/// to gather runtime information (exact version of a remote service, etc.)
/// to save in the results.
/// The script will be run in the same shell and environment than the benchmark.
/// It should write its output to `"$POULPE_TMP_DIR"/gathered_info.json`
/// as valid JSON data.
gather_info: String?
/// A command (or series of commands) to run before each command run.
prepare_run: String?
......
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