Skip to content

Commit

Permalink
Merge PR #158: Ensure empty string for unset variable, and maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed Sep 5, 2021
2 parents 07fbdf5 + f3f06ee commit 3489dfc
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 73 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -6,16 +6,17 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ '2.7', '3.7', '3.8-dev', 'pypy3' ]
python-version: [ '2.7', '3.7', '3.9', 'pypy3' ]
yaml-parser: ['', 'ruamel']
include:
- python-version: 2.7
coverage: "--with-coverage --cover-package=rebench"
exclude:
- python-version: 2.7
yaml-parser: ruamel
- python-version: '3.8-dev'
- python-version: 3.9
yaml-parser: ruamel
- python-version: pypy3
yaml-parser: ruamel
Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
run: |
pip install pylint
pylint rebench
if: startsWith(matrix.python-version, 'pypy') == false
if: startsWith(matrix.python-version, '3.')

- name: Upload coverage results to Coveralls
run: coveralls
Expand Down
4 changes: 2 additions & 2 deletions rebench/configurator.py
Expand Up @@ -106,7 +106,7 @@ def load_config(file_name):
and return the configuration.
"""
try:
with open(file_name, 'r') as conf_file:
with open(file_name, 'r') as conf_file: # pylint: disable=unspecified-encoding
data = yaml.safe_load(conf_file)
validator = Core(
source_data=data,
Expand Down Expand Up @@ -175,7 +175,7 @@ def __init__(self, raw_config, data_store, ui, cli_options=None, cli_reporter=No
self._data_store = data_store
self._process_cli_options()

self._build_commands = dict()
self._build_commands = {}

self._run_filter = _RunFilter(run_filter)

Expand Down
11 changes: 8 additions & 3 deletions rebench/denoise.py
Expand Up @@ -11,6 +11,7 @@
from multiprocessing import Pool
from cpuinfo import get_cpu_info

from .ui import escape_braces
from .subprocess_with_timeout import output_as_str

try:
Expand Down Expand Up @@ -97,7 +98,7 @@ def minimize_noise(show_warnings, ui):
elif 'command not found' in output:
msg += '{ind}Please make sure `rebench-denoise` is on the PATH\n'
else:
msg += '{ind}Error: ' + output
msg += '{ind}Error: ' + escape_braces(output)

if not success and show_warnings:
ui.warning(msg)
Expand Down Expand Up @@ -200,7 +201,7 @@ def _set_scaling_governor(governor, num_cores):
try:
for cpu_i in range(num_cores):
filename = "/sys/devices/system/cpu/cpu" + str(cpu_i) + "/cpufreq/scaling_governor"
with open(filename, "w") as gov_file:
with open(filename, "w") as gov_file: # pylint: disable=unspecified-encoding
gov_file.write(governor + "\n")
except IOError:
return "failed"
Expand All @@ -215,6 +216,7 @@ def _set_no_turbo(with_no_turbo):
value = "0"

try:
# pylint: disable-next=unspecified-encoding
with open("/sys/devices/system/cpu/intel_pstate/no_turbo", "w") as nt_file:
nt_file.write(value + "\n")
except IOError:
Expand All @@ -224,9 +226,11 @@ def _set_no_turbo(with_no_turbo):

def _minimize_perf_sampling():
try:
# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_cpu_time_max_percent", "w") as perc_file:
perc_file.write("1\n")

# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_event_max_sample_rate", "w") as sample_file:
sample_file.write("1\n")
except IOError:
Expand All @@ -237,6 +241,7 @@ def _minimize_perf_sampling():

def _restore_perf_sampling():
try:
# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_cpu_time_max_percent", "w") as perc_file:
perc_file.write("25\n")
except IOError:
Expand Down Expand Up @@ -307,7 +312,7 @@ def _test(num_cores):
lower = _shield_lower_bound(num_cores)
upper = _shield_upper_bound(num_cores)
core_cnt = upper - lower + 1
pool = Pool(core_cnt)
pool = Pool(core_cnt) # pylint: disable=consider-using-with

print("Test on %d cores" % core_cnt)

Expand Down
28 changes: 14 additions & 14 deletions rebench/environment.py
Expand Up @@ -23,7 +23,7 @@ def _encode_str(out):

def _exec(cmd):
try:
with open(os.devnull, 'w') as dev_null_f:
with open(os.devnull, 'w') as dev_null_f: # pylint: disable=unspecified-encoding
out = subprocess.check_output(cmd, stderr=dev_null_f)
except subprocess.CalledProcessError:
return None
Expand All @@ -38,7 +38,7 @@ def determine_source_details():
if _source:
return _source

result = dict()
result = {}

is_git_repo = _exec(['git', 'rev-parse']) is not None
if not is_git_repo:
Expand Down Expand Up @@ -81,19 +81,22 @@ def determine_source_details():

def init_env_for_test():
global _environment # pylint: disable=global-statement
_environment = dict()
_environment['hostName'] = 'test'
_environment['userName'] = 'test'
_environment = {
'hostName': 'test',
'userName': 'test'
}


def init_environment(denoise_result, ui):
result = dict()
result['userName'] = getpass.getuser()
result['manualRun'] = not ('CI' in os.environ and os.environ['CI'] == 'true')

u_name = os.uname()
result['hostName'] = u_name[1]
result['osType'] = u_name[0]
result = {
'userName': getpass.getuser(),
'manualRun': not ('CI' in os.environ and os.environ['CI'] == 'true'),
'hostName': u_name[1],
'osType': u_name[0],
'memory': virtual_memory().total,
'denoise': denoise_result.details
}

try:
cpu_info = _get_cpu_info_internal()
Expand All @@ -108,14 +111,11 @@ def init_environment(denoise_result, ui):
ui.warning('Was not able to determine the type of CPU used and its clock speed.'
+ ' Thus, these details will not be recorded with the data.')

result['memory'] = virtual_memory().total
result['software'] = []
result['software'].append({'name': 'kernel', 'version': u_name[3]})
result['software'].append({'name': 'kernel-release', 'version': u_name[2]})
result['software'].append({'name': 'architecture', 'version': u_name[4]})

result['denoise'] = denoise_result.details

global _environment # pylint: disable=global-statement
_environment = result

Expand Down
10 changes: 5 additions & 5 deletions rebench/model/benchmark.py
Expand Up @@ -126,11 +126,11 @@ def as_str_list(self):
'' if self._extra_args is None else str(self._extra_args)]

def as_dict(self):
result = dict()
result['name'] = self._name
result['runDetails'] = self._run_details.as_dict()
result['suite'] = self._suite.as_dict()
return result
return {
'name': self._name,
'runDetails': self._run_details.as_dict(),
'suite': self._suite.as_dict()
}

@classmethod
def from_str_list(cls, data_store, str_list):
Expand Down
9 changes: 5 additions & 4 deletions rebench/model/benchmark_suite.py
Expand Up @@ -104,10 +104,11 @@ def __str__(self):
return "Suite(%s, %s)" % (self._name, self._command)

def as_dict(self):
result = dict()
result['name'] = self._name
result['executor'] = self._executor.as_dict()
result = {
'name': self._name,
'executor': self._executor.as_dict(),
'desc': self._desc
}
if self._build:
result['build'] = [b.as_dict() for b in self._build]
result['desc'] = self._desc
return result
8 changes: 4 additions & 4 deletions rebench/model/build_cmd.py
Expand Up @@ -77,7 +77,7 @@ def __hash__(self):
return hash((self._cmd, self._location))

def as_dict(self):
result = dict()
result['cmd'] = self._cmd
result['location'] = self._location
return result
return {
'cmd': self._cmd,
'location': self._location
}
7 changes: 4 additions & 3 deletions rebench/model/executor.py
Expand Up @@ -95,9 +95,10 @@ def variables(self):
return self._variables

def as_dict(self):
result = dict()
result['name'] = self._name
result = {
'name': self._name,
'desc': self._description
}
if self._build:
result['build'] = [b.as_dict() for b in self._build]
result['desc'] = self._description
return result
10 changes: 5 additions & 5 deletions rebench/model/exp_run_details.py
Expand Up @@ -120,8 +120,8 @@ def retries_after_failure(self):
return self._retries_after_failure

def as_dict(self):
result = dict()
result['warmup'] = self._warmup
result['minIterationTime'] = self._min_iteration_time
result['maxInvocationTime'] = self._max_invocation_time
return result
return {
'warmup': self._warmup,
'minIterationTime': self._min_iteration_time,
'maxInvocationTime': self._max_invocation_time
}
14 changes: 7 additions & 7 deletions rebench/model/measurement.py
Expand Up @@ -92,10 +92,10 @@ def from_str_list(cls, data_store, str_list, line_number=None, filename=None):
criterion, line_number, filename)

def as_dict(self):
result = dict()
result['c'] = self._criterion
result['in'] = self._invocation
result['it'] = self._iteration
result['u'] = self._unit
result['v'] = self._value
return result
return {
'c': self._criterion,
'in': self._invocation,
'it': self._iteration,
'u': self._unit,
'v': self._value
}
26 changes: 14 additions & 12 deletions rebench/model/run_id.py
Expand Up @@ -239,17 +239,19 @@ def as_simple_string(self):
def _expand_vars(self, string):
try:
return string % {'benchmark': self._benchmark.command,
'cores': self._cores,
'cores': self.cores_as_str,
'executor': self._benchmark.suite.executor.name,
'input': self._input_size,
'input': self.input_size_as_str,
'iterations': self.iterations,
'suite': self._benchmark.suite.name,
'variable': self._var_value,
'variable': self.var_value_as_str,
'warmup': self._benchmark.run_details.warmup}
except ValueError as err:
self._report_format_issue_and_exit(string, err)
return None
except TypeError as err:
self._report_format_issue_and_exit(string, err)
return None
except KeyError as err:
msg = ("The configuration of %s contains improper Python format strings.\n"
+ "{ind}The command line configured is: %s\n"
Expand Down Expand Up @@ -316,15 +318,15 @@ def as_str_list(self):
return result

def as_dict(self):
result = dict()
result['benchmark'] = self._benchmark.as_dict()
result['cores'] = self._cores
result['inputSize'] = self._input_size
result['varValue'] = self._var_value
result['extraArgs'] = str(self._benchmark.extra_args)
result['cmdline'] = self.cmdline()
result['location'] = self.location
return result
return {
'benchmark': self._benchmark.as_dict(),
'cores': self._cores,
'inputSize': self._input_size,
'varValue': self._var_value,
'extraArgs': str(self._benchmark.extra_args),
'cmdline': self.cmdline(),
'location': self.location
}

@classmethod
def from_str_list(cls, data_store, str_list):
Expand Down
13 changes: 9 additions & 4 deletions rebench/persistence.py
Expand Up @@ -185,13 +185,15 @@ def _discard_old_data(self):

@staticmethod
def _truncate_file(filename):
# pylint: disable-next=unspecified-encoding
with open(filename, 'w'):
pass

def _read_start_time(self):
if not os.path.exists(self._data_filename):
self._start_time = None
return
# pylint: disable-next=unspecified-encoding
with open(self._data_filename, 'r') as data_file:
self._start_time = self._read_first_meta_block(data_file)

Expand All @@ -217,11 +219,13 @@ def load_data(self, runs, discard_run_data):
try:
if current_runs:
with NamedTemporaryFile('w', delete=False) as target:
# pylint: disable-next=unspecified-encoding
with open(self._data_filename, 'r') as data_file:
self._process_lines(data_file, current_runs, target)
os.unlink(self._data_filename)
shutil.move(target.name, self._data_filename)
else:
# pylint: disable-next=unspecified-encoding
with open(self._data_filename, 'r') as data_file:
self._process_lines(data_file, current_runs, None)
except IOError:
Expand Down Expand Up @@ -293,6 +297,7 @@ def _open_file_and_append_execution_comment(self):
shebang_line += "# Source: " + json.dumps(determine_source_details()) + "\n"

try:
# pylint: disable-next=unspecified-encoding,consider-using-with
data_file = open(self._data_filename, 'a+')
data_file.write(shebang_line)
data_file.flush()
Expand Down Expand Up @@ -384,10 +389,10 @@ def _send_data(self, cache):
measurements = dp.measurements_as_dict(criteria)
num_measurements += len(measurements['m'])
dp_data.append(measurements)
data = dict()
data['runId'] = run_id.as_dict()
data['d'] = dp_data
all_data.append(data)
all_data.append({
'runId': run_id.as_dict(),
'd': dp_data
})

criteria_index = []
for c, idx in criteria.items():
Expand Down
1 change: 1 addition & 0 deletions rebench/rebench.py
Expand Up @@ -299,6 +299,7 @@ def main_func():
ui = UI()
for ex in exceptions.exceptions:
ui.error(str(ex) + "\n")
return -1


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion rebench/rebenchdb.py
Expand Up @@ -89,7 +89,7 @@ def _send_to_rebench_db(self, payload_data, operation):
payload = json.dumps(payload_data, separators=(',', ':'), ensure_ascii=True)

# self._ui.output("Saving JSON Payload of size: %d\n" % len(payload))
with open("payload.json", "w") as text_file:
with open("payload.json", "w") as text_file: # pylint: disable=unspecified-encoding
text_file.write(payload)

try:
Expand Down
7 changes: 2 additions & 5 deletions rebench/statistics.py
Expand Up @@ -66,11 +66,8 @@ def add_sample(self, sample):
((sample - prev_mean) * (sample - self.mean)))
self.std_dev = math.sqrt(self._variance_times_num_samples / self.num_samples)

if self.min > sample:
self.min = sample

if self.max < sample:
self.max = sample
self.min = min(self.min, sample)
self.max = max(self.max, sample)

def as_tuple(self):
return (self.mean,
Expand Down

0 comments on commit 3489dfc

Please sign in to comment.