<commit_before># Common bash(1) procedures to be used in the Performance Co-Pilot
# Bash PMDA trace instrumentation mechanism
#
# Copyright (c) 2012 <NAME>.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

pcp_trace()
{
    command="$1"
    shift

    case "$command"
    in
        setup|init)
            [ -z "${PCP_TMP_DIR}" ] && return 0	# incorrect call sequence
            trap "pcp_trace off" 0
            export PCP_TRACE_DIR="${PCP_TMP_DIR}/pmdabash"
            export PCP_TRACE_HEADER="${PCP_TRACE_DIR}/.$$"
            export PCP_TRACE_DATA="${PCP_TRACE_DIR}/$$"
            ;;

        stop|off)
            [ -e "${PCP_TRACE_DATA}" ] || return 0
            exec 99>/dev/null
            # unlink is performed by pmdabash to resolve race conditions
            ;;

        start|on)
            # series of sanity checks first
            [ -n "${BASH_VERSION}" ] || return 0        # wrong shell
            [ "${BASH_VERSINFO[0]}" -ge 4 ] || return 0 # no support
            [ -z "${PCP_TMP_DIR}" ] && return 0	        # incorrect setup
            [ -z "${PCP_TRACE_DIR}" ] && pcp_trace init # not yet tracing
            [ -d "${PCP_TRACE_DIR}" ] || return 0       # no pcp pmda yet

            # is this the child of a traced shell?
            [ -e /proc/self/fd/99 ] && pcp_trace init

            trap "pcp_trace on" 13	# reset on sigpipe (consumer died)
            printf -v PCP_START '%(%s)T' -2
            mkfifo -m 600 "${PCP_TRACE_DATA}" 2>/dev/null || return 0
            # header: version, command, parent, and start time
            echo "version:1 ppid:${PPID} date:${PCP_START} + ${BASH_SOURCE}" \
                "$@" > "${PCP_TRACE_HEADER}" || return 0
            # setup link between xtrace & fifo
            exec 99>"${PCP_TRACE_DATA}"
            BASH_XTRACEFD=99		# magic bash environment variable
            set -o xtrace		# start tracing from here onward
            # traces: time, line#, and (optionally) function
            PS4='time:${SECONDS} line:${LINENO} func:${FUNCNAME[0]-} + '
            ;;
    esac
}
<commit_msg>Ensure name and args of instrumented bash script not overwritten<commit_after># Common bash(1) procedures to be used in the Performance Co-Pilot
# Bash PMDA trace instrumentation mechanism
#
# Copyright (c) 2012 <NAME>.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

pcp_trace()
{
    command="$1"
    shift

    case "$command"
    in
        setup|init)
            [ -z "${PCP_TMP_DIR}" ] && return 0	# incorrect call sequence
            trap "pcp_trace off" 0
            export PCP_TRACE_DIR="${PCP_TMP_DIR}/pmdabash"
            export PCP_TRACE_HEADER="${PCP_TRACE_DIR}/.$$"
            export PCP_TRACE_DATA="${PCP_TRACE_DIR}/$$"
            ;;

        stop|off)
            exec 99>/dev/null
            # unlink is performed by pmdabash to resolve race conditions
            unset BASH_XTRACEFD PCP_TRACE_DIR PCP_TRACE_HEADER PCP_TRACE_DATA
            ;;

        start|on)
            # series of sanity checks first
            [ -n "${BASH_VERSION}" ] || return 0        # wrong shell
            [ "${BASH_VERSINFO[0]}" -ge 4 ] || return 0 # no support
            [ -z "${PCP_TMP_DIR}" ] && return 0	        # incorrect setup
            [ -z "${PCP_TRACE_DIR}" ] && pcp_trace init $@ # not yet tracing
            [ -d "${PCP_TRACE_DIR}" ] || return 0       # no pcp pmda yet

            # is this the child of a traced shell?
            [ -e /proc/self/fd/99 ] && pcp_trace init $@

            trap "pcp_trace on" 13	# reset on sigpipe (consumer died)
            printf -v PCP_START '%(%s)T' -2
            mkfifo -m 600 "${PCP_TRACE_DATA}" 2>/dev/null || return 0
            # header: version, command, parent, and start time
            echo "version:1 ppid:${PPID} date:${PCP_START} + $@" \
                > "${PCP_TRACE_HEADER}" || return 0
            # setup link between xtrace & fifo
            exec 99>"${PCP_TRACE_DATA}"
            BASH_XTRACEFD=99		# magic bash environment variable
            set -o xtrace		# start tracing from here onward
            # traces: time, line#, and (optionally) function
            PS4='time:${SECONDS} line:${LINENO} func:${FUNCNAME[0]-} + '
            ;;
    esac
}

{'fraction_non_alphanumeric': 0.10525295599922466, 'fraction_numerical': 0.013762357045939136, 'mean_word_length': 2.1695331695331697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5599993', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1499, 'n_words': 529}