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

simple-command: store information about memory usage

Caveats inline
parent a48391ea
No related tags found
1 merge request!46simple-command: store information about memory usage
Pipeline #96655 passed
import json
import os
from pathlib import Path
import platform
import resource
import shutil
import subprocess
import sys
......@@ -252,6 +254,11 @@
# TODO record poulpe version in results in case results accidentally
# get bogus for some poulpe version.
# XXX This is only valid once (if you only run a single benchmark),
# and returns the RSS of hyperfine + setup + multiple runs + cleanup
total_rss = self.get_memory_usage()
number_of_runs = len(r["results"][0]["exit_codes"])
# we should store more
res["time"] = {}
res["time"]["user"] = r["results"][0]["user"]
......@@ -261,8 +268,13 @@
res["time"]["standard-deviation"] = r["results"][0]["stddev"]
res["time"]["min"] = r["results"][0]["min"]
res["time"]["max"] = r["results"][0]["max"]
res["memory"] = {}
res["memory"]["avg-rss-bytes"] = total_rss // number_of_runs
res["meta"] = {
"runs": number_of_runs,
}
if runtime_info is not None:
# XXX is there a better place to store this?
res["runtime_info"] = runtime_info
return res
......@@ -264,8 +276,23 @@
if runtime_info is not None:
# XXX is there a better place to store this?
res["runtime_info"] = runtime_info
return res
def get_memory_usage(self):
try:
max_rss = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
except resource.error:
# "Exceptional circumstance" as per the docs, still we shouldn't
# waste the results because we failed to find the memory usage
max_rss = 0
# Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes
if platform.system() == "Darwin":
max_rss.ru_maxrss
else:
max_rss = max_rss * 1024
return max_rss
def _time_command(
self,
bin_env_path,
......@@ -383,7 +410,12 @@
pass
r = subprocess.run(
time_cmd, cwd=cwd, env=env, stdout=stdout, stderr=stderr
time_cmd,
cwd=cwd,
env=env,
stdout=stdout,
stderr=stderr,
start_new_session=True,
)
if r.returncode != 0:
raise errors.BenchmarkRunFailure(
......
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