Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Created May 12, 2022 19:43
Show Gist options
  • Save kirbysayshi/04f9dd0432e7d062fbdaa184d61be6d5 to your computer and use it in GitHub Desktop.
Save kirbysayshi/04f9dd0432e7d062fbdaa184d61be6d5 to your computer and use it in GitHub Desktop.
process profiling with graphs (bash, gnuplot)
for log in *-anary.log; do awk '$0<200' <$log | gnuplot -e "set term png; set yrange [0:200]; unset autoscale y; set output \"$(basename $log .log).trimmed.png\";plot '-' with boxes"; done
pattern=anary;
end=$((SECONDS+60));
prefix=$(date +%s)
LOGFILE="$prefix-$pattern.log"
: > $LOGFILE # truncate
while [ $SECONDS -lt $end ]; do
for pid in $(pgrep -f $pattern); do
ps -p $pid -o %cpu= ;
done | perl -nle '$sum += $_ } END { print $sum' >> $LOGFILE;
sleep 0.5;
done;
gnuplot<<<"set term png;set output \"$prefix-$pattern.png\";plot \"$LOGFILE\" with boxes"
@kirbysayshi
Copy link
Author

Example of the raw image:

1652318539-anary

Example of "cleaned file":

1652318539-anary trimmed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment