예제 #1
0
파일: db.py 프로젝트: simbuerg/benchbuild
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)
예제 #2
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()
예제 #3
0
파일: db.py 프로젝트: PolyJIT/benchbuild
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)
예제 #4
0
파일: db.py 프로젝트: tobiH94/benchbuild
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)
예제 #5
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)
예제 #6
0
파일: db.py 프로젝트: PolyJIT/benchbuild
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)
예제 #7
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
예제 #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
예제 #9
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