Skip to content

Commit

Permalink
Round total memory b/c it can differ slightly on the same machine
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed May 13, 2021
1 parent ce14c05 commit 684932f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions conbench/machine_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@ def machine_info(host_name):
except ValueError:
info[key] = 0

info["memory_bytes"] = _round_memory(int(info["memory_bytes"]))

for key in info:
info[key] = str(info[key])

return info


def _round_memory(value):
# B -> GiB -> B
gigs = 1024 ** 3
return int("{:.0f}".format(value / gigs)) * gigs


def _commands(info):
for key, command in COMMANDS.items():
try:
Expand Down
17 changes: 16 additions & 1 deletion conbench/tests/benchmark/test_machine_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from ...machine_info import _fill_from_cpuinfo, _fill_from_lscpu, _fill_from_meminfo
from ...machine_info import (
_fill_from_cpuinfo,
_fill_from_lscpu,
_fill_from_meminfo,
_round_memory,
)


L1D_CACHE = 524288
Expand Down Expand Up @@ -334,3 +339,13 @@ def test_fill_order():
"cpu_l3_cache_bytes": L3_CACHE,
"cpu_frequency_max_hz": FREQUENCY,
}


def test_round_memory():
before = [131590280000, 131593068000, 131593872000]
after = [132070244352, 132070244352, 132070244352]
assert list(map(_round_memory, before)) == after

before = [15855024000, 15855036000, 15855040000]
after = [16106127360, 16106127360, 16106127360]
assert list(map(_round_memory, before)) == after

0 comments on commit 684932f

Please sign in to comment.