Beispiel #1
0
def init_environment(scorep_config, keep_files=False, verbose=False):
    """
    Set the inital needed environment variables, to get everything up an running.
    As a few variables interact with LD env vars, the program needs to be restarted after this.

    @param scorep_config configuration flags for score-p
    @param keep_files whether to keep the generated files, or not.
    @param verbose Set to True to output information about config used and environment variables set.
    """

    if "libscorep" in os.environ.get("LD_PRELOAD", ""):
        raise RuntimeError(
            "Score-P is already loaded. This should not happen at this point")

    if "--user" not in scorep_config:
        scorep_config.append("--user")

    if verbose:
        _print_info("Score-P config: %s" % scorep_config)

    old_env = os.environ.copy()

    subsystem_lib_name, temp_dir = generate(scorep_config, keep_files)
    scorep_ld_preload = generate_ld_preload(scorep_config)

    if not os.access(temp_dir + "/" + subsystem_lib_name, os.X_OK):
        clean_up(keep_files=keep_files)
        raise RuntimeError(
            "The Score-P Subsystem Library at {} cannot be executed. Changing $TMP might help. "
            "Directory erased, use --keep-files to inspect the situation.".
            format(temp_dir + "/" + subsystem_lib_name))

    scorep.helper.add_to_ld_library_path(temp_dir)

    preload_str = scorep_ld_preload + " " + subsystem_lib_name
    if os.environ.get("LD_PRELOAD"):
        print_err(
            "LD_PRELOAD is already specified. If Score-P is already loaded this might lead to errors."
        )
        preload_str = os.environ["LD_PRELOAD"] + " " + preload_str
        os.environ["SCOREP_LD_PRELOAD_BACKUP"] = os.environ["LD_PRELOAD"]
    else:
        os.environ["SCOREP_LD_PRELOAD_BACKUP"] = ""
    os.environ["LD_PRELOAD"] = preload_str

    if verbose:
        for var in ("LD_LIBRARY_PATH", "LD_PRELOAD"):
            # Shorten the setting to e.g.: FOO=new:$FOO
            old_val = old_env.get(var)
            new_val = os.environ[var]
            if old_val:
                new_val = new_val.replace(old_val, '$' + var)
            _print_info('%s="%s"' % (var, new_val))
Beispiel #2
0
def _err_exit(msg):
    print_err("scorep: " + msg)
    sys.exit(1)
Beispiel #3
0
def _print_info(msg):
    """Print an info message with a prefix"""
    print_err("scorep: " + msg)