To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit bf5253e2 authored by Zixian Cai's avatar Zixian Cai
Browse files

Merge branch 'master' of gitlab.anu.edu.au:mu/mu-perf-benchmarks

parents 4543d7f2 c3844c78
...@@ -24,11 +24,14 @@ sys.path.insert(0, os.path.abspath(os.path.join(__file__, "..", ".."))) ...@@ -24,11 +24,14 @@ sys.path.insert(0, os.path.abspath(os.path.join(__file__, "..", "..")))
from mubench import __VERSION__ from mubench import __VERSION__
from mubench.frontend import frontends from mubench.frontend import frontends
from mubench.conf import settings
assert sys.version_info[:2] >= (3, 4), "Python 3.4+ is required." assert sys.version_info[:2] >= (3, 4), "Python 3.4+ is required."
LOGGING_FORMAT_DEFAULT = "[%(levelname)s] %(asctime)s %(module)s %(message)s"
logging.basicConfig( logging.basicConfig(
format="[%(levelname)s] %(asctime)s %(module)s %(message)s", format=getattr(settings, 'LOGGING_FORMAT', LOGGING_FORMAT_DEFAULT),
level=logging.INFO) level=logging.INFO)
......
...@@ -17,10 +17,10 @@ import importlib ...@@ -17,10 +17,10 @@ import importlib
from pathlib import Path from pathlib import Path
import os import os
from mubench.conf import global_settings from mubench.conf import global_settings
from mubench.exceptions import ImproperBehavior
class ImproperBehavior(Exception):
pass
class Settings: class Settings:
......
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class ExecutionFailure(Exception):
def __init__(self, cmd, exec_res):
self.cmd = cmd
self.exec_res = exec_res
def dump(self, errlog_file):
with errlog_file.open('w') as fp:
fp.write('---------------- stdout ----------------\n')
if self.exec_res.stdout:
fp.write(str(self.exec_res.stdout, encoding='utf-8'))
fp.write('\n')
fp.write('---------------- stderr ----------------\n')
if self.exec_res.stderr:
fp.write(str(self.exec_res.stderr, encoding='utf-8'))
def __str__(self):
return "Executing '%s' failed." % \
(' '.join(self.cmd) if isinstance(self.cmd, list) else self.cmd)
class ImproperBehavior(Exception):
pass
...@@ -14,17 +14,12 @@ ...@@ -14,17 +14,12 @@
# limitations under the License. # limitations under the License.
import os import os
import time import time
import logging
import subprocess as subproc
from pathlib import Path from pathlib import Path
from mubench import CALLBACKS_DIR from mubench import CALLBACKS_DIR
from mubench.util import expandenv from mubench.util import expandenv
from mubench.exceptions import ExecutionFailure from mubench.util import run_in_subproc
from types import SimpleNamespace
logger = logging.getLogger(__name__)
class Language: class Language:
name = None name = None
...@@ -59,27 +54,6 @@ class Language: ...@@ -59,27 +54,6 @@ class Language:
def run(cls, target, task): def run(cls, target, task):
raise NotImplementedError raise NotImplementedError
@classmethod
def run_in_subproc(cls, cmd, env=None): # TODO: maybe put this in util.py
cmd = list(map(str, cmd))
logger.info(" ".join(cmd))
import resource
ru0 = resource.getrusage(resource.RUSAGE_CHILDREN)
t0 = ru0.ru_utime + ru0.ru_stime
res = subproc.Popen(cmd, stdout=subproc.PIPE, stderr=subproc.PIPE,
env=env)
so, se = res.communicate()
res = SimpleNamespace(stdout=so, stderr=se, returncode=res.returncode)
ru1 = resource.getrusage(resource.RUSAGE_CHILDREN)
t1 = ru1.ru_utime + ru1.ru_stime
if res.returncode != 0:
raise ExecutionFailure(cmd, res)
return res, (t1 - t0)
def get_lang(name): def get_lang(name):
from mubench.lang.python import Python from mubench.lang.python import Python
......
...@@ -17,7 +17,7 @@ import os ...@@ -17,7 +17,7 @@ import os
from mubench.lang import Language from mubench.lang import Language
from mubench import CALLBACKS_DIR from mubench import CALLBACKS_DIR
from mubench.util import expandenv from mubench.util import expandenv, run_in_subproc
class C(Language): class C(Language):
...@@ -59,7 +59,7 @@ class C(Language): ...@@ -59,7 +59,7 @@ class C(Language):
cmd.append(task.srcfile) cmd.append(task.srcfile)
cls.run_in_subproc(cmd, task.env) run_in_subproc(cmd, task.env)
assert target.exists() assert target.exists()
return target return target
...@@ -75,4 +75,4 @@ class C(Language): ...@@ -75,4 +75,4 @@ class C(Language):
cmd.extend(task.benchmark['args']) cmd.extend(task.benchmark['args'])
return cls.run_in_subproc(cmd, task.env) return run_in_subproc(cmd, task.env)
...@@ -19,8 +19,7 @@ from pathlib import Path ...@@ -19,8 +19,7 @@ from pathlib import Path
from mubench.lang import Language from mubench.lang import Language
from mubench import CALLBACKS_DIR from mubench import CALLBACKS_DIR
from mubench.exceptions import ExecutionFailure from mubench.util import expandenv, run_in_subproc
from mubench.util import expandenv
class Mu(Language): class Mu(Language):
...@@ -153,7 +152,7 @@ class Mu(Language): ...@@ -153,7 +152,7 @@ class Mu(Language):
] ]
cmd.extend(srcs) cmd.extend(srcs)
cls.run_in_subproc(cmd, task.env) run_in_subproc(cmd, task.env)
assert build_target.exists() assert build_target.exists()
...@@ -163,7 +162,7 @@ class Mu(Language): ...@@ -163,7 +162,7 @@ class Mu(Language):
cmd.append(cc['vmarg_s']) cmd.append(cc['vmarg_s'])
cmd.append(target.absolute()) cmd.append(target.absolute())
cls.run_in_subproc(cmd, task.env) run_in_subproc(cmd, task.env)
assert target.exists() assert target.exists()
return target return target
...@@ -185,4 +184,4 @@ class Mu(Language): ...@@ -185,4 +184,4 @@ class Mu(Language):
cmd.extend(task.benchmark['args']) cmd.extend(task.benchmark['args'])
return cls.run_in_subproc(cmd, task.env) return run_in_subproc(cmd, task.env)
...@@ -18,8 +18,7 @@ import os ...@@ -18,8 +18,7 @@ import os
from mubench import CALLBACKS_DIR from mubench import CALLBACKS_DIR
from mubench.lang import Language from mubench.lang import Language
from mubench.exceptions import ExecutionFailure from mubench.util import expandenv, run_in_subproc
from mubench.util import expandenv
class Python(Language): class Python(Language):
...@@ -60,4 +59,4 @@ class Python(Language): ...@@ -60,4 +59,4 @@ class Python(Language):
cmd.extend(bmc['args']) cmd.extend(bmc['args'])
return cls.run_in_subproc(cmd, task.env) return run_in_subproc(cmd, task.env)
...@@ -20,8 +20,7 @@ from pathlib import Path ...@@ -20,8 +20,7 @@ from pathlib import Path
from mubench.lang import Language from mubench.lang import Language
from mubench import CALLBACKS_DIR from mubench import CALLBACKS_DIR
from mubench.exceptions import ExecutionFailure from mubench.util import expandenv, run_in_subproc
from mubench.util import expandenv
class RPython(Language): class RPython(Language):
...@@ -152,7 +151,7 @@ class RPython(Language): ...@@ -152,7 +151,7 @@ class RPython(Language):
# the rest, custom defined arguments # the rest, custom defined arguments
cmd.extend(task.compiler['args']) cmd.extend(task.compiler['args'])
cls.run_in_subproc(cmd, task.env) run_in_subproc(cmd, task.env)
assert target.exists() assert target.exists()
return target return target
...@@ -174,4 +173,4 @@ class RPython(Language): ...@@ -174,4 +173,4 @@ class RPython(Language):
cmd.extend(task.benchmark['args']) cmd.extend(task.benchmark['args'])
return cls.run_in_subproc(cmd, task.env) return run_in_subproc(cmd, task.env)
...@@ -19,8 +19,7 @@ import subprocess as subproc ...@@ -19,8 +19,7 @@ import subprocess as subproc
from mubench.lang import Language from mubench.lang import Language
from mubench import CALLBACKS_DIR from mubench import CALLBACKS_DIR
from mubench.util import expandenv from mubench.util import expandenv, run_in_subproc
from mubench.exceptions import ExecutionFailure
from types import SimpleNamespace from types import SimpleNamespace
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -70,7 +69,7 @@ class WASM(Language): ...@@ -70,7 +69,7 @@ class WASM(Language):
callback_file = callback_dir / ('cb_%(name)s.c' % task.callback) callback_file = callback_dir / ('cb_%(name)s.c' % task.callback)
cmd.append(callback_file) cmd.append(callback_file)
cls.run_in_subproc(cmd, task.env) run_in_subproc(cmd, task.env)
assert target.exists() assert target.exists()
return target return target
...@@ -86,19 +85,5 @@ class WASM(Language): ...@@ -86,19 +85,5 @@ class WASM(Language):
cmd.extend(task.benchmark['args']) cmd.extend(task.benchmark['args'])
return cls.run_in_subproc(cmd, task.env, return run_in_subproc(cmd, task.env,
cwd=str(target.parent.resolve())) cwd=str(target.parent.resolve()))
@classmethod
def run_in_subproc(cls, cmd, env=None, **kwargs):
cmd = list(map(str, cmd))
logger.info(" ".join(cmd))
t0 = time.perf_counter()
res = subproc.Popen(cmd, stdout=subproc.PIPE, stderr=subproc.PIPE,
env=env, **kwargs)
so, se = res.communicate()
res = SimpleNamespace(stdout=so, stderr=se, returncode=res.returncode)
t1 = time.perf_counter()
if res.returncode != 0:
raise ExecutionFailure(cmd, res)
return res, (t1 - t0)
...@@ -24,9 +24,8 @@ from pathlib import Path ...@@ -24,9 +24,8 @@ from pathlib import Path
from types import SimpleNamespace from types import SimpleNamespace
from mubench import SUITE_DIR, CALLBACKS_DIR from mubench import SUITE_DIR, CALLBACKS_DIR
from mubench.exceptions import ExecutionFailure
from mubench.conf import settings from mubench.conf import settings
from mubench.util import expandenv, dictify from mubench.util import expandenv, dictify, run_in_subproc, ExecutionFailure
from mubench.lang import get_lang, Language from mubench.lang import get_lang, Language
from mubench.models.result import Result from mubench.models.result import Result
...@@ -241,7 +240,7 @@ class TaskSet: ...@@ -241,7 +240,7 @@ class TaskSet:
# source # source
cmd.append(CALLBACKS_DIR / ('cb_%(name)s.c' % self.callback)) cmd.append(CALLBACKS_DIR / ('cb_%(name)s.c' % self.callback))
Language.run_in_subproc(cmd, self.env) run_in_subproc(cmd, self.env)
class Task: class Task:
""" """
......
...@@ -15,10 +15,58 @@ ...@@ -15,10 +15,58 @@
from string import Template from string import Template
import os import os
import logging
import subprocess as subproc
from types import SimpleNamespace
logger = logging.getLogger(__name__)
def expandenv(s, env=os.environ): def expandenv(s, env=os.environ):
return Template(s).substitute(env) return Template(s).substitute(env)
def dictify(opt, key_name='name'): def dictify(opt, key_name='name'):
return {key_name: opt} if isinstance(opt, str) else opt return {key_name: opt} if isinstance(opt, str) else opt
\ No newline at end of file
class ExecutionFailure(Exception):
def __init__(self, cmd, exec_res):
self.cmd = cmd
self.exec_res = exec_res
def dump(self, errlog_file):
with errlog_file.open('w') as fp:
fp.write('---------------- stdout ----------------\n')
if self.exec_res.stdout:
fp.write(str(self.exec_res.stdout, encoding='utf-8'))
fp.write('\n')
fp.write('---------------- stderr ----------------\n')
if self.exec_res.stderr:
fp.write(str(self.exec_res.stderr, encoding='utf-8'))
def __str__(self):
return "Executing '%s' failed." % \
(' '.join(self.cmd) if isinstance(self.cmd, list) else self.cmd)
def run_in_subproc(cmd, env=None, **kwds):
cmd = list(map(str, cmd))
logger.info(" ".join(cmd))
import resource
ru0 = resource.getrusage(resource.RUSAGE_CHILDREN)
t0 = ru0.ru_utime + ru0.ru_stime
res = subproc.Popen(cmd, stdout=subproc.PIPE, stderr=subproc.PIPE,
env=env, **kwds)
so, se = res.communicate()
res = SimpleNamespace(stdout=so, stderr=se, returncode=res.returncode)
ru1 = resource.getrusage(resource.RUSAGE_CHILDREN)
t1 = ru1.ru_utime + ru1.ru_stime
if res.returncode != 0:
raise ExecutionFailure(cmd, res)
return res, (t1 - t0)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment