Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: move PGO related code to polyjit.experiments #202

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 2 additions & 57 deletions benchbuild/utils/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import abc
import enum
import functools as ft
import glob
import logging
import os
import sys
Expand All @@ -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__)
Expand Down Expand Up @@ -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
71 changes: 0 additions & 71 deletions benchbuild/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down