Esempio n. 1
0
def extract_file(filename, outfile, exp_id, run_group):
    """
    Extract a previously stored file from the database.

    Args:
        filename (str):
            The name of the file associated to the content in the database.
        outfile (str):
            The filepath we want to store the content to.
        exp_id (uuid):
            The experiment uuid the file was stored in.
        run_group (uuid):
            The run_group the file was stored in.
    """
    from benchbuild.utils.schema import Session
    import pathlib

    session = Session()
    result = session.query(FileContent.__table__).get(
        (exp_id, run_group, filename))
    if result:
        filepath = pathlib.Path(outfile)
        filepath.write_bytes(result.content)
    else:
        LOG.error("No file found in database.")
Esempio n. 2
0
    def main(self):
        """ Run the log command. """
        from benchbuild.utils.schema import Session, Run, RunLog

        s = Session()

        exps = self._experiments
        exp_ids = self._experiment_ids
        projects = self._projects
        project_ids = self._project_ids
        types = self._types

        if types is not None:
            query = s.query(Run, RunLog).filter(Run.id == RunLog.run_id)
        else:
            query = s.query(Run)

        if exps is not None:
            query = query.filter(Run.experiment_name.in_(exps))

        if exp_ids is not None:
            query = query.filter(Run.experiment_group.in_(exp_ids))

        if projects is not None:
            query = query.filter(Run.project_name.in_(projects))

        if project_ids is not None:
            query = query.filter(Run.run_group.in_(project_ids))

        if types is not None:
            print_logs(query, types)
        else:
            print_runs(query)
Esempio n. 3
0
    def main(self):
        """ Run the log command. """
        from benchbuild.utils.schema import Session, Run, RunLog

        s = Session()

        exps = self._experiments
        exp_ids = self._experiment_ids
        projects = self._projects
        project_ids = self._project_ids
        types = self._types

        if types is not None:
            query = s.query(Run, RunLog).filter(Run.id == RunLog.run_id)
        else:
            query = s.query(Run)

        if exps is not None:
            query = query.filter(Run.experiment_name.in_(exps))

        if exp_ids is not None:
            query = query.filter(Run.experiment_group.in_(exp_ids))

        if projects is not None:
            query = query.filter(Run.project_name.in_(projects))

        if project_ids is not None:
            query = query.filter(Run.run_group.in_(project_ids))

        if types is not None:
            print_logs(query, types)
        else:
            print_runs(query)
Esempio n. 4
0
def persist_experiment(experiment):
    """
    Persist this experiment in the benchbuild database.

    Args:
        experiment: The experiment we want to persist.
    """
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = CFG['experiment_id'].value()
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = CFG["experiment_description"].value()
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
        logger.debug("New experiment: %s", newe)
    else:
        exps.update({'name': name, 'description': desc})
        logger.debug("Update experiments: %s", exps)
        ret = exps.first()
    try:
        session.commit()
    except IntegrityError as ie:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
Esempio n. 5
0
def persist_experiment(experiment):
    """
    Persist this experiment in the benchbuild database.

    Args:
        experiment: The experiment we want to persist.
    """
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = experiment.id
    LOG.debug("Using experiment ID stored in config: %s", cfg_exp)
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = str(CFG["experiment_description"])
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
    else:
        exps.update({'name': name, 'description': desc})
        ret = exps.first()

    try:
        session.commit()
    except IntegrityError:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
Esempio n. 6
0
def persist_file(f, experiment_id, run_group):
    """
    Persist a file in the FileContent relation.

    Args:
        f (str):
            The filename we want to persist.
        experiment_id (uuid):
            The experiment uuid this file needs to be assigned to.
        run_group (uuid):
            The run group uuid this file needs to be assigned to.
    """
    from benchbuild.utils.schema import Session
    import pathlib
    session = Session()

    filename = os.path.basename(f)
    filepath = pathlib.Path(f)
    session = Session()
    session.add(
        FileContent(experience_id=experiment_id,
                    rungroup_id=run_group,
                    filename=filename,
                    content=filepath.read_bytes()))
    session.commit()
Esempio n. 7
0
def persist_experiment(experiment):
    """
    Persist this experiment in the benchbuild database.

    Args:
        experiment: The experiment we want to persist.
    """
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = experiment.id
    LOG.debug("Using experiment ID stored in config: %s", cfg_exp)
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = str(CFG["experiment_description"])
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
    else:
        exps.update({'name': name, 'description': desc})
        ret = exps.first()

    try:
        session.commit()
    except IntegrityError:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
Esempio n. 8
0
    def __call__(self, *args, timeout=TIMEOUT, **kwargs):
        """
        The call of this extension runs the following extensions until the
        timeout was reached or a run was significant enough to withdraw the
        nullhypothesis.

        Kwargs:
            timeout: The amount of trys the user wants to give the experiment
                     before it gets interrupted.
        Returns:
            The run info object after executing the
            afterwards following extensions.
        """
        iterator = 0
        session = Session()

        while iterator < timeout:
            #get an run_info object after executing the run with its extensions
            ri_object = self.call_next(*args, **kwargs)

            #check if the experiment defines the result function
            if (hasattr(self.experiment, 'res_func')):
                results = self.experiment.res_func(ri_object)
                if (self.t_test(results)):
                    LOG.info("The run was significant.")
                    break

                #check if this was the last iteration
                if (iterator == (timeout - 1)):
                    LOG.warning(
                        "No significant run happened before the timeout!")
                iterator += 1

            # no need to repeat the run without a result function
            else:
                break

        #Commit the database session containing all runs
        session.commit()

        LOG.info("Overall one command was executed %s, " + "times.", iterator)
        return ri_object
Esempio n. 9
0
    def __call__(self, *args, timeout=TIMEOUT, **kwargs):
        """
        The call of this extension runs the following extensions until the
        timeout was reached or a run was significant enough to withdraw the
        nullhypothesis.

        Kwargs:
            timeout: The amount of trys the user wants to give the experiment
                     before it gets interrupted.
        Returns:
            The run info object after executing the
            afterwards following extensions.
        """
        iterator = 0
        session = Session()

        while iterator < timeout:
            #get an run_info object after executing the run with its extensions
            ri_object = self.call_next(*args, **kwargs)

            #check if the experiment defines the result function
            if hasattr(self.experiment, 'res_func'):
                results = self.experiment.res_func(ri_object)
                if self.t_test(results):
                    LOG.info("The run was significant.")
                    break

                #check if this was the last iteration
                if iterator == (timeout - 1):
                    LOG.warning(
                        "No significant run happened before the timeout!")
                iterator += 1

            # no need to repeat the run without a result function
            else:
                break

        #Commit the database session containing all runs
        session.commit()

        LOG.info("Overall one command was executed %s times.", iterator)
        return ri_object
Esempio n. 10
0
    def main(self):
        from benchbuild.utils.schema import Session, RegressionTest
        from benchbuild.utils.cmd import mkdir, sed

        prefix = CFG["regression-prefix"]
        if not os.path.exists(prefix):
            mkdir("-p", prefix)

        session = Session()
        for elem in session.query(RegressionTest).order_by(
                RegressionTest.project_name):
            sub_dir = os.path.join(prefix, elem.project_name)
            if not os.path.exists(sub_dir):
                mkdir("-p", sub_dir)

            test_path = os.path.join(sub_dir, elem.name + ".ll")
            with open(test_path, 'w') as test_f:
                test_f.write("""
; RUN: opt {opt_flags} < %s 2>&1 | FileCheck %s
""".format(opt_flags=" ".join(self.opt_flags())))
                test_f.write(self.get_check_line(test_path, elem.module))
                test_f.write(elem.module)
            (sed["-i", r"0,/\#0/s///", test_path])()
Esempio n. 11
0
    def main(self):
        from benchbuild.utils.schema import Session, RegressionTest
        from plumbum.cmd import mkdir, sed

        prefix = CFG["regression-prefix"]
        if not os.path.exists(prefix):
            mkdir("-p", prefix)

        session = Session()
        for elem in session.query(RegressionTest).order_by(
                RegressionTest.project_name):
            sub_dir = os.path.join(prefix, elem.project_name)
            if not os.path.exists(sub_dir):
                mkdir("-p", sub_dir)

            test_path = os.path.join(sub_dir, elem.name + ".ll")
            with open(test_path, 'w') as test_f:
                test_f.write("""
; RUN: opt {opt_flags} < %s 2>&1 | FileCheck %s
""".format(opt_flags=" ".join(self.opt_flags())))
                test_f.write(self.get_check_line(test_path, elem.module))
                test_f.write(elem.module)
            (sed["-i", r"0,/\#0/s///", test_path])()
Esempio n. 12
0
    def main(self, *args):
        self.verbosity = self.verbosity if self.verbosity < 4 else 3
        settings.CFG["verbosity"] = self.verbosity

        log.configure()
        log.set_defaults()
        if settings.CFG["db"]["create_functions"].value():
            from benchbuild.utils.schema import init_functions, Session
            init_functions(Session())

        if args:
            print("Unknown command {0!r}".format(args[0]))
            return 1
        if not self.nested_command:
            self.help()
Esempio n. 13
0
def persist_project(project):
    """
    Persist this project in the benchbuild database.

    Args:
        project: The project we want to persist.
    """
    from benchbuild.utils.schema import Project, Session
    session = Session()
    projects = session.query(Project) \
        .filter(Project.name == project.name) \
        .filter(Project.group_name == project.group)

    name = project.name
    desc = project.__doc__
    domain = project.domain
    group_name = project.group
    version = project.version() \
        if callable(project.version) else project.version
    try:
        src_url = project.src_uri
    except AttributeError:
        src_url = 'unknown'

    if projects.count() == 0:
        newp = Project()
        newp.name = name
        newp.description = desc
        newp.src_url = src_url
        newp.domain = domain
        newp.group_name = group_name
        newp.version = version
        LOG.debug("Poject INSERT: %s", newp)
        session.add(newp)
    else:
        newp_value = {
            "name": name,
            "description": desc,
            "src_url": src_url,
            "domain": domain,
            "group_name": group_name,
            "version": version
        }
        LOG.debug("Project UPDATE: %s", newp_value)
        projects.update(newp_value)

    session.commit()
    return (projects, session)
Esempio n. 14
0
    def main(self, *args):
        self.verbosity = self.verbosity if self.verbosity < 6 else 5
        if self.debug:
            self.verbosity = 3
        verbosity = int(os.getenv('BB_VERBOSITY', self.verbosity))

        settings.CFG["verbosity"] = verbosity
        settings.CFG["debug"] = self.debug

        log.configure()
        log.set_defaults()

        if settings.CFG["db"]["create_functions"]:
            from benchbuild.utils.schema import init_functions, Session
            init_functions(Session())

        if args:
            print("Unknown command {0!r}".format(args[0]))
            return 1
        if not self.nested_command:
            self.help()
Esempio n. 15
0
def persist_project(project):
    """
    Persist this project in the benchbuild database.

    Args:
        project: The project we want to persist.
    """
    from benchbuild.utils.schema import Project, Session
    session = Session()
    projects = session.query(Project) \
        .filter(Project.name == project.name) \
        .filter(Project.group_name == project.group)

    name = project.name
    desc = project.__doc__
    domain = project.domain
    group_name = project.group
    version = project.version() \
        if callable(project.version) else project.version
    try:
        src_url = project.src_uri
    except AttributeError:
        src_url = 'unknown'

    if projects.count() == 0:
        newp = Project()
        newp.name = name
        newp.description = desc
        newp.src_url = src_url
        newp.domain = domain
        newp.group_name = group_name
        newp.version = version
        session.add(newp)
    else:
        newp_value = {
            "name": name,
            "description": desc,
            "src_url": src_url,
            "domain": domain,
            "group_name": group_name,
            "version": version
        }
        projects.update(newp_value)

    session.commit()
    return (projects, session)
Esempio n. 16
0
    def __call__(self, cc, *args, project=None, **kwargs):
        from benchbuild.experiments.compilestats import CompileStat
        from benchbuild.utils.db import persist_compilestats
        from benchbuild.utils.schema import Session
        from benchbuild.settings import CFG

        if project:
            self.project = project

        original_command = cc[args]
        clang = cc["-Qunused-arguments"]
        clang = clang[args]
        clang = clang[project.cflags]
        clang = clang[project.ldflags]
        clang = clang["-mllvm", "-stats"]

        run_config = self.config
        session = Session()
        with track_execution(clang, self.project, self.experiment) as run:
            run_info = run()
            if run_config is not None:
                persist_config(run_info.db_run, session, run_config)

            if not run_info.has_failed:
                stats = []
                cls = ExtractCompileStats
                for stat in cls.get_compilestats(run_info.stderr):
                    compile_s = CompileStat()
                    compile_s.name = stat["desc"].rstrip()
                    compile_s.component = stat["component"].rstrip()
                    compile_s.value = stat["value"]
                    stats.append(compile_s)

                components = CFG["cs"]["components"].value()
                names = CFG["cs"]["names"].value()

                stats = [s for s in stats if str(s.component) in components] \
                    if components is not None else stats
                stats = [s for s in stats if str(s.name) in names] \
                    if names is not None else stats

                if stats:
                    for stat in stats:
                        LOG.info(" [%s] %s = %s", stat.component, stat.name,
                                 stat.value)
                    persist_compilestats(run_info.db_run, run_info.session,
                                         stats)
                else:
                    LOG.info("No compilestats left, after filtering.")
                    LOG.warning("  Components: %s", components)
                    LOG.warning("  Names:      %s", names)
            else:
                with track_execution(original_command, self.project,
                                     self.experiment, **kwargs) as run:
                    LOG.warning("Fallback to: %s", str(original_command))
                    run_info = run()

        ret = self.call_next(cc, *args, **kwargs)
        ret.append(run_info)
        session.commit()
        return ret