Skip to content

Commit

Permalink
Allow runners to write into the instrumentation dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Feb 1, 2018
1 parent fabab7f commit a598417
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
4 changes: 4 additions & 0 deletions krun.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ def inner_main(mailer, on_first_invocation, config, args):
platform.no_pstate_check = args.no_pstate_check
platform.hardware_reboots = args.hardware_reboots

# Create the instrumentation directory if required
if on_first_invocation:
util.make_instr_dir(config)

debug("Checking platform preliminaries")
platform.check_preliminaries()

Expand Down
48 changes: 43 additions & 5 deletions krun/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import shutil
import sys
import subprocess
import pwd
import grp
import getpass
from subprocess import Popen, PIPE
from logging import error, debug, info, warn, root as root_logger
from bz2 import BZ2File
Expand All @@ -60,6 +63,10 @@
# than are strictly necessary. In either case we are safe and correct.
PIPE_BUF_SZ = 1024 * 16

from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IXUSR, S_IXGRP, S_IROTH, S_IXOTH
INSTR_DIR_MODE = S_IRUSR | S_IWUSR | S_IXUSR \
| S_IRGRP | S_IWGRP | S_IXGRP \
| S_IROTH | S_IXOTH

DIR = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -439,15 +446,46 @@ def get_instr_json_dir(config):
return os.path.join(os.getcwd(), "%s_instr_data" % config_base)


def make_instr_dir(config):
# We only want make a dir if >=1 VM is in instrumentation mode.
for vm in config.VMS.itervalues():
if vm['vm_def'].instrument:
break
else:
return # no VM is in instrumentation mode.

dir = get_instr_json_dir(config)
debug("making instrumentation dir: %s" % dir)
os.mkdir(dir)


def set_instr_dir_perms(config, platform):
"""Grant the Krun user write access to the instrumentation dir.
Sadly this has to be done as root as there is no guarantee that the initial
user is in the krun user's group."""

from krun.vm_defs import BENCHMARK_USER
group = grp.getgrnam(BENCHMARK_USER).gr_name
user = pwd.getpwnam(getpass.getuser()).pw_name

from krun import util
path = util.get_instr_json_dir(config)

args = platform.change_user_args()
args.extend(["chown", "%s:%s" % (user, group), path])
run_shell_cmd(" ".join(args))

os.chmod(path, INSTR_DIR_MODE)


def dump_instr_json(key, exec_num, config, instr_data):
"""Write per-execution instrumentation data to a separate JSON file"""
"""Write per-execution instrumentation data to a separate JSON file.
instr_json_dir = get_instr_json_dir(config)
if not os.path.exists(instr_json_dir):
os.mkdir(instr_json_dir)
Assumes the instrumentation directory exists."""

filename = "%s__%s.json.bz2" % (key.replace(":", "__"), exec_num)
path = os.path.join(instr_json_dir, filename)
path = os.path.join(get_instr_json_dir(config), filename)

# The directory was checked to be non-existant when the benchmark session
# started, so it follows that the instrumentation JSON file (each of which
Expand Down
4 changes: 4 additions & 0 deletions krun/vm_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def _run_exec(self, args, heap_lim_k, stack_lim_k, key, key_pexec_idx,

if not self.platform.no_user_change:
self.platform.make_fresh_krun_user()
# If we are in instrumentation mode, grant the Krun user write
# access to the instrumentation directory.
if self.instrument:
util.set_instr_dir_perms(self.config, self.platform)

wrapper_filename, envlog_filename = \
self.make_wrapper_script(args, heap_lim_k, stack_lim_k)
Expand Down

0 comments on commit a598417

Please sign in to comment.