Skip to content
Snippets Groups Projects
Commit 0377315a authored by William E Warriner's avatar William E Warriner
Browse files

initial commit of script

parents
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Extract pid-job relationship
SCONTROL_PID_COL=1
SCONTROL_JOB_COL=2
SCONTROL_WIDTH=$(scontrol listpids | awk '{print NF; exit}')
# Get pidstat -w output, extract headers and required columns
PIDSTAT_PID_COL=1
PIDSTAT_CTXTSW_COL=$(( 2 + $SCONTROL_WIDTH - 1 ))
# Extract headers and required columns from ps -aux
PS_PID_COL=1
PS_USER_COL=2
# Extract headers separately
ps_header=$(ps -eo "pid,user,cp,drs,cmd" --sort pid | head -n 1)
pidstat_header=$(pidstat -w | awk 'NR==3 {print $4, $5, $6}')
scontrol_header=$(scontrol listpids | head -n 1)
# Sort the outputs by PID, excluding headers
ps_sorted=$(ps -eo "pid,user,cp,drs,cmd" --sort pid | tail -n +2 | sort -k$PS_PID_COL,$PS_PID_COL)
pidstat_sorted=$(pidstat -w | awk 'NR>3 {print $4, $5, $6}' | sort -k$PIDSTAT_PID_COL,$PIDSTAT_PID_COL)
scontrol_sorted=$(scontrol listpids | tail -n +2 | sort -k$SCONTROL_PID_COL,$SCONTROL_PID_COL)
# Join the two outputs on the PID column
scontrol_pidstat=$(join -1 $SCONTROL_PID_COL -2 $PIDSTAT_PID_COL <(echo "$scontrol_sorted") <(echo "$pidstat_sorted"))
scontrol_pidstat_ps=$(join -1 $SCONTROL_PID_COL -2 $PS_PID_COL <(echo "$scontrol_pidstat") <(echo "$ps_sorted"))
# Aggregate
agg=$(echo "$scontrol_pidstat_ps" | awk -v key_col=$SCONTROL_JOB_COL -v val_col=$PIDSTAT_CTXTSW_COL \
'{
arr[$key_col]+=$val_col
}
END {
for (key in arr) printf("%s\t%s\n", key, arr[key])
}' | sort -k1,1)
# Combine with squeue
squeue_header=$(squeue -w $(hostname) | head -n 1 | sed 's/ \+/\t/g' | sed 's/^[ \t]*//')
printf "%s\tcontext-switches/s\n" "$squeue_header"
join -1 1 -2 1 <(squeue -w $(hostname) | sort -k1,1) <(echo "$agg") | sed 's/ \+/\t/g'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment