コード例 #1
0
ファイル: StatsCollect.py プロジェクト: intel/wult
    def _init_outdir(self, discovery=False):
        """
        Helper function for 'configure()' that creates the output directory and various of its
        sub-direcories.
        """

        if not self.outdir:
            self.outdir = FSHelpers.mktemp(prefix="stats-collect-",
                                           proc=self._proc)
            self._outdir_created = True
            _LOG.debug("created output directory '%s'%s", self.outdir,
                       self._proc.hostmsg)
        else:
            try:
                FSHelpers.mkdir(self.outdir, parents=True, proc=self._proc)
            except ErrorExists:
                pass
            else:
                self._outdir_created = True

        self._logsdir = self.outdir / "logs"
        FSHelpers.mkdir(self._logsdir, exist_ok=True, proc=self._proc)

        if discovery:
            # The statistics collected during discovery belong to the logs.
            self._statsdir = self._logsdir / "discovery-stats"
        else:
            self._statsdir = self.outdir / "stats"
        FSHelpers.mkdir(self._statsdir, exist_ok=True, proc=self._proc)
コード例 #2
0
def _deploy_drivers(args, proc):
    """Deploy drivers to the SUT represented by 'proc'."""

    drvsrc = find_app_data("wult", _DRV_SRC_SUBPATH/f"{args.toolname}",
                           descr=f"{args.toolname} drivers sources")
    if not drvsrc.is_dir():
        raise Error(f"path '{drvsrc}' does not exist or it is not a directory")

    kver = None
    if not args.ksrc:
        kver = KernelVersion.get_kver(proc=proc)
        if not args.ksrc:
            args.ksrc = Path(f"/lib/modules/{kver}/build")
    else:
        args.ksrc = FSHelpers.abspath(args.ksrc, proc=proc)

    if not FSHelpers.isdir(args.ksrc, proc=proc):
        raise Error(f"kernel sources directory '{args.ksrc}' does not exist{proc.hostmsg}")

    if not kver:
        kver = KernelVersion.get_kver_ktree(args.ksrc, proc=proc)

    _LOG.info("Kernel sources path: %s", args.ksrc)
    _LOG.info("Kernel version: %s", kver)

    if KernelVersion.kver_lt(kver, args.minkver):
        raise Error(f"version of the kernel{proc.hostmsg} is {kver}, and it is not new enough.\n"
                    f"Please, use kernel version {args.minkver} or newer.")

    _LOG.debug("copying the drivers to %s:\n   '%s' -> '%s'", proc.hostname, drvsrc, args.stmpdir)
    proc.rsync(f"{drvsrc}/", args.stmpdir / "drivers", remotesrc=False, remotedst=True)
    drvsrc = args.stmpdir / "drivers"

    kmodpath = Path(f"/lib/modules/{kver}")
    if not FSHelpers.isdir(kmodpath, proc=proc):
        raise Error(f"kernel modules directory '{kmodpath}' does not exist{proc.hostmsg}")

    # Build the drivers on the SUT.
    _LOG.info("Compiling the drivers%s", proc.hostmsg)
    cmd = f"make -C '{drvsrc}' KSRC='{args.ksrc}'"
    if args.debug:
        cmd += " V=1"

    stdout, stderr, exitcode = proc.run(cmd)
    if exitcode != 0:
        msg = proc.cmd_failed_msg(cmd, stdout, stderr, exitcode)
        if "synth_event_" in stderr:
            msg += "\n\nLooks like synthetic events support is disabled in your kernel, enable " \
                   "the 'CONFIG_SYNTH_EVENTS' kernel configuration option."
        raise Error(msg)

    _log_cmd_output(args, stdout, stderr)

    # Deploy the drivers.
    dstdir = kmodpath / _DRV_SRC_SUBPATH
    FSHelpers.mkdir(dstdir, parents=True, exist_ok=True, proc=proc)

    for name in _get_deployables(drvsrc, proc):
        installed_module = _get_module_path(proc, name)
        srcpath = drvsrc / f"{name}.ko"
        dstpath = dstdir / f"{name}.ko"
        _LOG.info("Deploying driver '%s' to '%s'%s", name, dstpath, proc.hostmsg)
        proc.rsync(srcpath, dstpath, remotesrc=True, remotedst=True)

        if installed_module and installed_module.resolve() != dstpath.resolve():
            _LOG.debug("removing old module '%s'%s", installed_module, proc.hostmsg)
            proc.run_verify(f"rm -f '{installed_module}'")

    stdout, stderr = proc.run_verify(f"depmod -a -- '{kver}'")
    _log_cmd_output(args, stdout, stderr)

    # Potentially the deployed driver may crash the system before it gets to write-back data
    # to the file-system (e.g., what 'depmod' modified). This may lead to subsequent boot
    # problems. So sync the file-system now.
    proc.run_verify("sync")
コード例 #3
0
def _deploy_helpers(args, proc):
    """Deploy helpers (including python helpers) to the SUT represented by 'proc'."""

    # Python helpers need to be deployd only to a remote host. The local host already has them
    # deployed by 'setup.py'.
    if not proc.is_remote:
        args.pyhelpers = []

    helpers = args.helpers + args.pyhelpers
    if not helpers:
        return

    # We assume all helpers are in the same base directory.
    helper_path = _HELPERS_SRC_SUBPATH/f"{helpers[0]}"
    helpersrc = find_app_data("wult", helper_path, descr=f"{args.toolname} helper sources")
    helpersrc = helpersrc.parent

    if not helpersrc.is_dir():
        raise Error(f"path '{helpersrc}' does not exist or it is not a directory")

    # Make sure all helpers are available.
    for helper in helpers:
        helperdir = helpersrc / helper
        if not helperdir.is_dir():
            raise Error(f"path '{helperdir}' does not exist or it is not a directory")

    # Copy python helpers to the temporary directory on the controller.
    for pyhelper in args.pyhelpers:
        srcdir = helpersrc / pyhelper
        _LOG.debug("copying helper %s:\n  '%s' -> '%s'",
                   pyhelper, srcdir, args.ctmpdir)
        Procs.Proc().rsync(f"{srcdir}", args.ctmpdir, remotesrc=False, remotedst=False)

    # Build stand-alone version of every python helper.
    for pyhelper in args.pyhelpers:
        _LOG.info("Building a stand-alone version of '%s'", pyhelper)
        basedir = args.ctmpdir / pyhelper
        deployables = _get_deployables(basedir)
        for name in deployables:
            _create_standalone_python_script(name, basedir)

    # And copy the "standoline-ized" version of python helpers to the SUT.
    if proc.is_remote:
        for pyhelper in args.pyhelpers:
            srcdir = args.ctmpdir / pyhelper
            _LOG.debug("copying helper '%s' to %s:\n  '%s' -> '%s'",
                       pyhelper, proc.hostname, srcdir, args.stmpdir)
            proc.rsync(f"{srcdir}", args.stmpdir, remotesrc=False, remotedst=True)

    # Copy non-python helpers to the temporary directory on the SUT.
    for helper in args.helpers:
        srcdir = helpersrc/ helper
        _LOG.debug("copying helper '%s' to %s:\n  '%s' -> '%s'",
                   helper, proc.hostname, srcdir, args.stmpdir)
        proc.rsync(f"{srcdir}", args.stmpdir, remotesrc=False, remotedst=True)

    deploy_path = get_helpers_deploy_path(proc, args.toolname)

    # Build the non-python helpers on the SUT.
    if args.helpers:
        for helper in args.helpers:
            _LOG.info("Compiling helper '%s'%s", helper, proc.hostmsg)
            helperpath = f"{args.stmpdir}/{helper}"
            stdout, stderr = proc.run_verify(f"make -C '{helperpath}'")
            _log_cmd_output(args, stdout, stderr)

    # Make sure the the destination deployment directory exists.
    FSHelpers.mkdir(deploy_path, parents=True, exist_ok=True, proc=proc)

    # Deploy all helpers.
    _LOG.info("Deploying helpers to '%s'%s", deploy_path, proc.hostmsg)

    helpersdst = args.stmpdir / "helpers_deployed"
    _LOG.debug("deploying helpers to '%s'%s", helpersdst, proc.hostmsg)

    for helper in helpers:
        helperpath = f"{args.stmpdir}/{helper}"

        cmd = f"make -C '{helperpath}' install PREFIX='{helpersdst}'"
        stdout, stderr = proc.run_verify(cmd)
        _log_cmd_output(args, stdout, stderr)

        proc.rsync(str(helpersdst) + "/bin/", deploy_path, remotesrc=True, remotedst=True)
コード例 #4
0
def collect_before(outdir, proc):
    """
    Collect information about the SUT (System Under Test) defined by 'proc' (an 'SSH' or 'Proc'
    object). This function is supposed to be called before running a workload on the SUT. It will
    collect various global data like the contents of the '/proc/cmdline' file, the 'lspci' output,
    and store the data in the 'outdir' directory on the SUT.
    """

    FSHelpers.mkdir(outdir, parents=True, exist_ok=True, proc=proc)

    cmdinfos = {}

    cmdinfos["proc_cmdline"] = cmdinfo = {}
    outfile = outdir / "proc_cmdline.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"cat /proc/cmdline > '{outfile}' 2>&1"

    cmdinfos["uname_a"] = cmdinfo = {}
    outfile = outdir / "uname-a.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"uname -a > '{outfile}' 2>&1"

    cmdinfos["dmidecode"] = cmdinfo = {}
    outfile = outdir / "dmidecode.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"dmidecode > '{outfile}' 2>&1"

    cmdinfos["dmidecode_u"] = cmdinfo = {}
    outfile = outdir / "dmidecode-u.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"dmidecode -u > '{outfile}' 2>&1"

    cmdinfos["lspci"] = cmdinfo = {}
    outfile = outdir / "lspci.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"lspci > '{outfile}' 2>&1"

    cmdinfos["lspci_vvv"] = cmdinfo = {}
    outfile = outdir / "lspci-vvv.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"lspci -vvv > '{outfile}' 2>&1"

    cmdinfos["proc_cpuinfo"] = cmdinfo = {}
    outfile = outdir / "proc_cpuinfo.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"cat /proc/cpuinfo > '{outfile}' 2>&1"

    cmdinfos["lsmod"] = cmdinfo = {}
    outfile = outdir / "lsmod.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"lsmod > '{outfile}' 2>&1"

    cmdinfos["lsusb"] = cmdinfo = {}
    outfile = outdir / "lsusb.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"lsusb > '{outfile}' 2>&1"

    cmdinfos["lsusb_v"] = cmdinfo = {}
    outfile = outdir / "lsusb-v.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"lsusb -v > '{outfile}' 2>&1"

    cmdinfos["lsblk"] = cmdinfo = {}
    outfile = outdir / "lsblk.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"lsblk > '{outfile}' 2>&1"

    cmdinfos["sysctl_all"] = cmdinfo = {}
    outfile = outdir / "sysctl-all.raw.txt"
    cmdinfo["outfile"] = outfile
    cmdinfo["cmd"] = f"sysctl --all > '{outfile}' 2>&1"

    _run_commands(cmdinfos, proc)
    _collect_totals(outdir, "before", proc)