From 4569ed6f662210d698e93276ecadba9221b098dc Mon Sep 17 00:00:00 2001 From: Andreas Simbuerger Date: Thu, 12 Jul 2018 00:00:40 +0200 Subject: [PATCH] utils: move PGO related code to polyjit.experiments --- benchbuild/utils/actions.py | 59 ++---------------------------- benchbuild/utils/db.py | 71 ------------------------------------- 2 files changed, 2 insertions(+), 128 deletions(-) diff --git a/benchbuild/utils/actions.py b/benchbuild/utils/actions.py index 61cd020c1..5f3acf780 100644 --- a/benchbuild/utils/actions.py +++ b/benchbuild/utils/actions.py @@ -16,7 +16,6 @@ import abc import enum import functools as ft -import glob import logging import os import sys @@ -25,12 +24,12 @@ from datetime import datetime import sqlalchemy as sa -from plumbum import ProcessExecutionError, local +from plumbum import ProcessExecutionError import attr import benchbuild.signals as signals from benchbuild.settings import CFG -from benchbuild.utils.cmd import llvm_profdata, mkdir, rm, rmdir +from benchbuild.utils.cmd import mkdir, rm, rmdir from benchbuild.utils.db import persist_experiment LOG = logging.getLogger(__name__) @@ -559,57 +558,3 @@ def __str__(self, indent=0): textwrap.indent("* Clean the directory: {0}".format(p), indent * " ")) return "\n".join(lines) - - -@attr.s -class SaveProfile(Step): - NAME = "SAVEPROFILE" - DESCRIPTION = "Save a profile in llvm format in the DB" - - filename = attr.ib(default=None) - - @notify_step_begin_end - def __call__(self): - from benchbuild.utils.db import persist_file - from benchbuild.project import Project - if not isinstance(self.obj, Project): - raise AttributeError - - obj_builddir = self.obj.builddir - outfile = os.path.abspath(os.path.join(obj_builddir, self.filename)) - profiles = os.path.abspath(os.path.join(obj_builddir, "raw-profiles")) - with local.cwd(profiles): - merge_profdata = llvm_profdata["merge", "-output={}".format( - outfile)] - merge_profdata = merge_profdata[glob.glob('default_*.profraw')] - merge_profdata() - - exp_id = self.obj.experiment.id - run_group = self.obj.run_uuid - - persist_file(outfile, exp_id, run_group) - self.status = StepResult.OK - - -@attr.s -class RetrieveFile(Step): - NAME = "RETRIEVEFILE" - DESCRIPTION = "Retrieve a file from the database" - - filename = attr.ib(default=None) - run_group = attr.ib(default=None) - - @notify_step_begin_end - def __call__(self): - from benchbuild.project import Project - from benchbuild.utils.db import extract_file - - if not isinstance(self.obj, Project): - raise AttributeError - - obj_builddir = self.obj.builddir - outfile = os.path.abspath(os.path.join(obj_builddir, self.filename)) - exp_id = self.obj.experiment.id - extract_file(self.filename, outfile, exp_id, self.run_group) - - self.status = StepResult.OK diff --git a/benchbuild/utils/db.py b/benchbuild/utils/db.py index e820c7364..bfd06d8ad 100644 --- a/benchbuild/utils/db.py +++ b/benchbuild/utils/db.py @@ -171,77 +171,6 @@ def persist_experiment(experiment): return (ret, session) -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, FileContent - 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() - - -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, FileContent - import pathlib - - session = Session() - result = session.query(FileContent).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.") - - -def persist_likwid(run, session, measurements): - """ - Persist all likwid results. - - Args: - run: The run we attach our measurements to. - session: The db transaction we belong to. - measurements: The likwid measurements we want to store. - """ - from benchbuild.utils import schema as s - - for (region, name, core, value) in measurements: - db_measurement = s.Likwid( - metric=name, region=region, value=value, core=core, run_id=run.id) - session.add(db_measurement) - - @validate def persist_time(run, session, timings): """