Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions adjust
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import signal

import subprocess

from adjust import Adjust, AdjustError

import json
# 'compact' format json encode (no spaces)
json_enc = json.JSONEncoder(separators=(",",":")).encode
Expand All @@ -23,7 +25,11 @@ def run(path, *args, data = None):
data = json_enc(data).encode("UTF-8")
r = subprocess.check_output([path]+list(args), input = data)

return json.loads(r.decode("UTF-8"))
try:
output = r.decode("UTF-8")
return json.loads(output)
except json.decoder.JSONDecodeError as error:
raise AdjustError(f"JSON decoding of subprocess output failed:\n{output}") from error


def locate_drivers():
Expand Down Expand Up @@ -76,8 +82,13 @@ def _query(app_id='app'):
g_state[d] = q

# merge after all data is collected
descriptor = {"application" : { "components" : {}}, "monitoring": {}}
comps = descriptor['application']['components']
monitoring = descriptor['monitoring']

for d,info in drivers:
# TODO: s[application] (global app settings not supported for now)
monitoring.update(g_state[d].get("monitoring",{}))
for cn, cd in g_state[d]["application"]["components"].items():
c = comps.setdefault(cn, {})
try:
Expand All @@ -87,7 +98,7 @@ def _query(app_id='app'):
# NOTE we don't keep track where the first one came from, just report the current driver as the culprit
raise ValueError("{}: duplicate setting for component {}: {}".format(os.path.basename(d), cn, str(x)))

return {"application" : { "components" : comps }}
return descriptor


def _adjust(app_id, new_settings):
Expand Down Expand Up @@ -150,9 +161,9 @@ def _adjust(app_id, new_settings):
for d,s in p_status.items():
if s["status"] == "ok": continue
msg.append("{}: {}: {}".format(os.path.basename(d), s["status"], s.get("message","")))
raise Exception( "\n".join(msg) )
raise AdjustError( "\n".join(msg), status=s["status"], reason=s["reason"] )

class A(adjust.Adjust):
class A(Adjust):

def query(self):
return _query()
Expand Down
152 changes: 0 additions & 152 deletions adjust.py

This file was deleted.

2 changes: 2 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def run_and_track(path, *args, data = None, progress_cb: typing.Callable[..., No
if rc != 0: # error, add verbose info to returned data
if not rsp.get("status"): # NOTE if driver didn't return any json, status will be "nodata". Preferably, it should print structured data even on failures, so errors can be reported neatly.
rsp["status"] = "failed"
if not rsp.get("reason"):
rsp["reason"] = "unknown"
m = rsp.get("message", "")
# if config[report_stderr]:
rs = os.environ.get("OPTUNE_VERBOSE_STDERR", "all") # FIXME: default setting?
Expand Down