PMDABASH(1)

πŸŽ€ PMDABASH(1) β€” the Bourne-Again SHell trace performance metrics domain agent πŸ’…

okay bestie, settle in, because this one is so cool. this is pmdabash, and it lives in the General Commands Manual section of PCP, which is the Performance Co-Pilot, and it's literally a little agent that spies on your bash scripts (in the nicest way) and turns everything they do into performance metrics. no cap. πŸ¦‹


✨ SYNOPSIS ✨

$PCP_PMDAS_DIR/bash/pmdabash [-C] [-D debug] [-d domain] [-l logfile]
[-I interval] [-t timeout] [-U username] configfile

like, look at her. she takes a configfile at the end, and a whole lil pile of flags before it. she's got range. πŸ’–


🌸 DESCRIPTION 🌸

pmdabash is an experimental Performance Metrics Domain Agent (PMDA) β€” and when we say experimental, we mean it, it's giving lab-experiment energy, not "boring stable" energy β€” and what she does is export "xtrace" events from a bash(1) process that you've traced. 🫢

what does that mean, you ask? it means she catches the exact command execution info that would usually just get dumped to standard error when you use set -x in the shell. you know, that flood of + echo hi lines. iconic behaviour, now turned into real metrics.

she exports event metrics showing:

  • each command that got executed
  • the function name and line number in the script
  • a timestamp

and additionally, the process identifier for the shell and its parent process get exported too. πŸ‘‘

heads up: this whole thing requires bash version 4 or later. no bash 3, no exceptions, i don't make the rules. 😭

so here's the brief lil rundown of the pmdabash command line options, bestie:

  • -d β€” it is absolutely crucial that the performance metrics domain number you put here is unique and consistent. like, fr fr. that means domain should be different for every PMDA on the one host, and the same domain number should be used for the same PMDA on all hosts. it's giving "everyone gets their own locker, but the same locker number in every school". πŸ’…
  • -l β€” location of the log file. by default, a log file named bash.log gets written in the current directory of pmcd(1) when pmdabash starts, i.e. $PCP_LOG_DIR/pmcd. and if the log file can't be created, or just isn't writable? then the output goes to standard error instead. she adapts. she's flexible. 🌈
  • -s β€” how much time (in seconds) sits between subsequent evaluations of the shell trace file descriptor(s). the default is 2 seconds.
  • -m β€” maximum amount of memory allowed for each event queue (there's one per traced process). the default is 2 megabytes.
  • -U β€” the user account to run the agent under. the default is the unprivileged "pcp" account in current versions of PCP, but in older versions the superuser account ("root") was used by default. yeah. the before-times were wild. πŸ™ˆ

πŸ’– INSTALLATION πŸ’–

so if you want a host to actually export the names, help text and values for the bash performance metrics, do this as root:

# cd $PCP_PMDAS_DIR/bash
# ./Install

and then? the moment an instrumented shell script (peep the INSTRUMENTATION section below, bestie) is run with tracing enabled, new metric values just appear. no further setup of the agent is required. she just shows up. main character energy. ✨

and if you wanna undo the whole thing, do this as root:

# cd $PCP_PMDAS_DIR/bash
# ./Remove
okay important: pmdabash is launched by pmcd(1) and should never be executed directly. do not. don't do it. πŸ™… the Install and Remove scripts are the ones that notify pmcd(1) when the agent gets installed or removed, so let them handle it. πŸŽ€

πŸ¦‹ INSTRUMENTATION πŸ¦‹

for the event data to flow between a bash(1) script and pmdabash, your script needs to take these actions:

#!/bin/sh
source $PCP_DIR/etc/pcp.env
source $PCP_SHARE_DIR/lib/bashproc.sh

pcp_trace on $@       # enable tracing
echo "awoke, $count"

pcp_trace off         # disable tracing

and the tracing can be enabled and disabled any number of times by the script. she's not clingy. she comes and goes. πŸ’œ

once the agent is successfully installed, several metrics will be available:

$ pminfo bash
bash.xtrace.numclients
bash.xtrace.maxmem
bash.xtrace.queuemem
bash.xtrace.count
bash.xtrace.records
bash.xtrace.parameters.pid
bash.xtrace.parameters.parent
bash.xtrace.parameters.lineno
bash.xtrace.parameters.function
bash.xtrace.parameters.command

and when an instrumented script is running, you can verify the generation of event records using the pmevent(1) command, like this:

$ pmevent -t 1 -x '' bash.xtrace.records
host:      localhost
samples:   all
bash.xtrace.records["4538 ./test-trace.sh 1 2 3"]: 5 event records
  10:00:05.000 --- event record [0] flags 0x19 (point,id,parent) ---
    bash.xtrace.parameters.pid 4538
    bash.xtrace.parameters.parent 4432
    bash.xtrace.parameters.lineno 43
    bash.xtrace.parameters.command "true"
  10:00:05.000 --- event record [1] flags 0x19 (point,id,parent) ---
    bash.xtrace.parameters.pid 4538
    bash.xtrace.parameters.parent 4432
    bash.xtrace.parameters.lineno 45
    bash.xtrace.parameters.command "((  count++  ))"
  10:00:05.000 --- event record [2] flags 0x19 (point,id,parent) ---
    bash.xtrace.parameters.pid 4538
    bash.xtrace.parameters.parent 4432
    bash.xtrace.parameters.lineno 46
    bash.xtrace.parameters.command "echo 'awoke, 3'"
  10:00:05.000 --- event record [3] flags 0x19 (point,id,parent) ---
    bash.xtrace.parameters.pid 4538
    bash.xtrace.parameters.parent 4432
    bash.xtrace.parameters.lineno 47
    bash.xtrace.parameters.command "tired 2"
  10:00:05.000 --- event record [4] flags 0x19 (point,id,parent) ---
    bash.xtrace.parameters.pid 4538
    bash.xtrace.parameters.parent 4432
    bash.xtrace.parameters.lineno 38
    bash.xtrace.parameters.function "tired"
    bash.xtrace.parameters.command "sleep 2"

look at that. she's narrating the script back to you. ate. πŸ”₯


πŸŽ€ FILES πŸŽ€

  • $PCP_PMCDCONF_PATH β€” command line options used to launch pmdabash
  • $PCP_PMDAS_DIR/bash/help β€” default help text file for the bash metrics
  • $PCP_PMDAS_DIR/bash/Install β€” installation script for the pmdabash agent
  • $PCP_PMDAS_DIR/bash/Remove β€” undo installation script for pmdabash
  • $PCP_LOG_DIR/pmcd/bash.log β€” default log file for error messages and other information from pmdabash

🌸 PCP ENVIRONMENT 🌸

environment variables with the prefix PCP_ are used to parameterize the file and directory names that PCP uses. on each installation, the file /etc/pcp.conf contains the local values for these variables. and the $PCP_CONF variable can be used to specify an alternative configuration file, as described in pcp.conf(5). πŸ’–


πŸ’… DEBUGGING OPTIONS πŸ’…

the -D or --debug option turns on the output of additional diagnostics on stderr to help triage problems. that said, the information is sometimes cryptic and it's primarily intended to give guidance for developers rather than for end-users, so don't feel bad if it reads like a riddle, bestie. 😭

debug is a comma separated list of debugging options; use pmdbg(1) with the -l option to get a list of the available debugging options and their meaning. 🧚

debugging options specific to pmdabash are as follows:

  • appl0 β€” verbose logging of events of interest

🌈 SEE ALSO 🌈

bash(1), pmevent(1) and pmcd(1).


and that's the whole page, bestie! go forth and trace responsibly. πŸ‘‘

signing off with love from the Performance Co-Pilot crew β€” that's PCP, and yeah, this very page is PMDABASH(1). πŸ’–πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from