Beispiel #1
0
def load_result(taudbCfg, trialName, trialDir):
    """
    Load a trial result with the given name. If find a local ppk file
    with the name 'data.ppk', use it. Otherwise, try to connect
    to TAUdb using `taudbCfg`, export the trial named `trialName` to a
    local ppk file and then load it.

    Args:
      taudbCfg  (string): Name of the TAUdb config we are going to try
      trialName (string): Name of the trial we want to load
      trialDir  (string): Directory to look for 'data.ppk'

    Returns:
      The trial data we load

    Exceptions:
      DBFailure  : Can not connect to TAUdb
      NoSuchTrial: The trial can not be found
    """
    ppk = "%s/data.ppk" % trialDir
    cfg = os.path.expanduser("~/.ParaProf/perfdmf.cfg.%s" % taudbCfg)

    if os.path.isfile(ppk) is False:
        print "*** Exporting trial %s from taudb ..." % trialName,

        # connect to TAUdb
        db = TAUdbDatabaseAPI()
        db.initialize(cfg, False)

        try:
            trial = db.setTrial(trialName, True)
        except:
            raise DBFailure

        if trial is None:
            raise NoSuchTrial(trialName)

        data = TAUdbDataSource(db)
        data.load()
        # data.generateDerivedData()

        DataSourceExport.writePacked(data, File(ppk))

        print "Done"

    print "*** Loading trial %s ..." % trialName
    result = DataSourceResult(DataSourceResult.PPK,
                              [ppk],
                              False)
    result.setIgnoreWarnings(True)
    print "*** Done"

    return result
Beispiel #2
0
def is_exist(taudb, trial):
    """
    Check whether the `trial` exist in `taudb`

    Args:
      taudb (string): TAUdb config name
      trial (string): A trial name

    Returns:
      bool: whether `trial` exist in `taudb`
    """

    # connect to `taudb`
    cfg = os.path.expanduser("~/.ParaProf/perfdmf.cfg.%s" % taudb)
    db = TAUdbDatabaseAPI()
    db.initialize(cfg, False)

    # search for the `trial`
    for t in db.getTrialList(False):
        if t.getName() == trial:
            return True

    return False