<commit_before>#!/bin/bash

SCRIPT_PATH="$(readlink -f "$(dirname "$0")")"

C_NONE="\033[0;00m"
C_RED="\033[1;31m"
C_GREEN="\033[1;32m"

INSTALL_DIRS=(bin
              sofaboard
              plugins
              tools
              )
BIN_FILES=(bin/sofa
           bin/sofa_record.py
           bin/sofa_preprocess.py
           bin/sofa_analyze.py
           bin/sofa_deepprof.py
           bin/STree.py
           bin/sofa_viz.py
           bin/sofa_config.py
           bin/sofa_print.py
           bin/sofa_common.py
           sofa-pcm/pcm-core.x
           sofa-pcm/pcm-numa.x
           sofa-pcm/pcm-pcie.x
           sofa-pcm/pcm-memory.x
           )
PLUGIN_FILES=(plugins/.placeholder
              )
SOFABOARD_FILES=(sofaboard/index.html
                 sofaboard/cpu-report.html
                 sofaboard/gpu-report.html
                 sofaboard/comm-report.html
                 sofaboard/overhead.html
                 sofaboard/timeline.js
                 )

print_help(){
    echo "This script will install the sofa scripts to your system under the specified <PREFIX> directory."
    echo ""
    echo "Usage: $0 PREFIX"
    echo "Examples: $0 ~/third-parties/sofa"
    echo "          sudo $0 /opt/sofa"
}

function clear_install_dir()
{
    # Use uninstall script to safely remove old files
    if [[ -f ${PREFIX}/tools/uninstall.sh ]]; then
        echo "Uninstalling SOFA..."
        bash ${PREFIX}/tools/uninstall.sh
    fi
    echo "Creating directories..."
    mkdir -p ${PREFIX}
    mkdir -p ${PREFIX}/bin
    mkdir -p ${PREFIX}/sofaboard
    mkdir -p ${PREFIX}/plugins
    mkdir -p ${PREFIX}/tools
}

function install_sofa()
{
    echo "Installing..."
    cp sofa-pcm/pcm-pcie.x          ${PREFIX}/bin
    cp sofa-pcm/pcm-numa.x          ${PREFIX}/bin
    cp sofa-pcm/pcm-core.x          ${PREFIX}/bin
    cp sofa-pcm/pcm-memory.x    ${PREFIX}/bin
    cp -rf ${SCRIPT_PATH}/bin       ${PREFIX}
    cp -rf ${SCRIPT_PATH}/bin       ${PREFIX}
    cp -rf ${SCRIPT_PATH}/plugins   ${PREFIX}
    cp -rf ${SCRIPT_PATH}/sofaboard ${PREFIX}
    cp -rf ${SCRIPT_PATH}/papi/src/build ${PREFIX}

    # Create a new file for SOFA environment
################## heredoc style
    cat > ${PREFIX}/tools/activate.sh <<EOF
export PATH=${PREFIX}/bin:\$PATH
export PATH=\$PATH:/usr/local/cuda/bin
export PATH=\$PATH:/usr/local/intelpcm/bin
EOF
##################

    # Create an uninstall script
################## heredoc style
    cat > ${PREFIX}/tools/uninstall.sh <<EOF
# Change the directory
cd ${PREFIX}
[[ \$(pwd) != ${PREFIX} ]] && echo "Fail to change directory. Stop uninstalling..." && exit 1
# Remove installed files
rm -f ${BIN_FILES[@]}
rm -f ${PLUGIN_FILES[@]}
rm -f ${SOFABOARD_FILES[@]}
# Remove all python caches
rm -rf __pycache__ plugins/__pycache__ bin/__pycache__
# Remove generated files
rm -f tools/activate.sh
rm -f tools/uninstall.sh
# Remove directory only if it is empty!
rmdir --ignore-fail-on-non-empty ${INSTALL_DIRS[@]}
rmdir --ignore-fail-on-non-empty ${PREFIX}
EOF
##################<commit_msg>Fix installation bug for papi<commit_after>#!/bin/bash

SCRIPT_PATH="$(readlink -f "$(dirname "$0")")"

C_NONE="\033[0;00m"
C_RED="\033[1;31m"
C_GREEN="\033[1;32m"

INSTALL_DIRS=(bin
              sofaboard
              plugins
              tools
              )
BIN_FILES=(bin/sofa
           bin/sofa_record.py
           bin/sofa_preprocess.py
           bin/sofa_analyze.py
           bin/sofa_deepprof.py
           bin/STree.py
           bin/sofa_viz.py
           bin/sofa_config.py
           bin/sofa_print.py
           bin/sofa_common.py
           sofa-pcm/pcm-core.x
           sofa-pcm/pcm-numa.x
           sofa-pcm/pcm-pcie.x
           sofa-pcm/pcm-memory.x
           )
PLUGIN_FILES=(plugins/.placeholder
              )
SOFABOARD_FILES=(sofaboard/index.html
                 sofaboard/cpu-report.html
                 sofaboard/gpu-report.html
                 sofaboard/comm-report.html
                 sofaboard/overhead.html
                 sofaboard/timeline.js
                 )

print_help(){
    echo "This script will install the sofa scripts to your system under the specified <PREFIX> directory."
    echo ""
    echo "Usage: $0 PREFIX"
    echo "Examples: $0 ~/third-parties/sofa"
    echo "          sudo $0 /opt/sofa"
}

function clear_install_dir()
{
    # Use uninstall script to safely remove old files
    if [[ -f ${PREFIX}/tools/uninstall.sh ]]; then
        echo "Uninstalling SOFA..."
        bash ${PREFIX}/tools/uninstall.sh
    fi
    echo "Creating directories..."
    mkdir -p ${PREFIX}
    mkdir -p ${PREFIX}/bin
    mkdir -p ${PREFIX}/sofaboard
    mkdir -p ${PREFIX}/plugins
    mkdir -p ${PREFIX}/tools
}

function install_sofa()
{
    echo "Installing..."
    cp sofa-pcm/pcm-pcie.x          ${PREFIX}/bin
    cp sofa-pcm/pcm-numa.x          ${PREFIX}/bin
    cp sofa-pcm/pcm-core.x          ${PREFIX}/bin
    cp sofa-pcm/pcm-memory.x    ${PREFIX}/bin
    cp -rf ${SCRIPT_PATH}/bin       ${PREFIX}
    cp -rf ${SCRIPT_PATH}/bin       ${PREFIX}
    cp -rf ${SCRIPT_PATH}/plugins   ${PREFIX}
    cp -rf ${SCRIPT_PATH}/sofaboard ${PREFIX}
    cp -arTf ${SCRIPT_PATH}/papi/src/build ${PREFIX}/papi

    # Create a new file for SOFA environment
################## heredoc style
    cat > ${PREFIX}/tools/activate.sh <<EOF
export PATH=${PREFIX}/bin:\$PATH
export PATH=\$PATH:/usr/local/cuda/bin
export PATH=\$PATH:/usr/local/intelpcm/bin
EOF
##################

    # Create an uninstall script
################## heredoc style
    cat > ${PREFIX}/tools/uninstall.sh <<EOF
# Change the directory
cd ${PREFIX}
[[ \$(pwd) != ${PREFIX} ]] && echo "Fail to change directory. Stop uninstalling..." && exit 1
# Remove installed files
rm -f ${BIN_FILES[@]}
rm -f ${PLUGIN_FILES[@]}
rm -f ${SOFABOARD_FILES[@]}
# Remove all python caches
rm -rf __pycache__ plugins/__pycache__ bin/__pycache__
# Remove generated files
rm -f tools/activate.sh
rm -f tools/uninstall.sh
# Remove directory only if it is empty!
rmdir --ignore-fail-on-non-empty ${INSTALL_DIRS[@]}
rmdir --ignore-fail-on-non-empty ${PREFIX}
EOF
##################
{'fraction_non_alphanumeric': 0.15403503028318874, 'fraction_numerical': 0.007529873956457685, 'mean_word_length': 2.2465462274176407, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2514870', 'n_tokens_mistral': 2084, 'n_tokens_neox': 1995, 'n_words': 454}