This commit is contained in:
2025-11-04 06:49:27 -07:00
parent af5882d3e6
commit 4c3289bd2f
2 changed files with 24 additions and 25 deletions
+11 -12
View File
@@ -8,7 +8,7 @@ cmd="$@" # da command as a string or as args
start_date=$(date)
start_unixseconds=$(date +%s)
poll_seconds=2
logfile=sillylog.csv
logfile=/tmp/sillylog.csv
# throw a fit if no args supplied
if [ -z "$1" ]; then
@@ -16,7 +16,7 @@ if [ -z "$1" ]; then
exit 1
fi
echo "testing your gay little command $cmd at $(date +\"%h:%M:%S %Z\")" | tr [a-z] [A-Z]
echo "testing your gay little command $cmd at $(date '+%H:%M:%S %Z')" | tr [a-z] [A-Z]
# kill loeg for suretain
if [ -f "$logfile" ]; then
@@ -25,9 +25,8 @@ if [ -f "$logfile" ]; then
fi
# csv headers
echo "TIMESTAMP,PID,CPU USAGE %,MEMORY USAGE (KIBIBYTES),MEMORY USAGE %,READ VOLUME PER SECOND (KIBIBYTES),WRITE SIZE PER SECOND (KIBIBYTES)" > "$logfile"
# measurements_csv_fields="TIMESTAMP,PID,CPU USAGE %,MEMORY USAGE (KIBIBYTES),MEMORY USAGE %,READ VOLUME PER SECOND (KIBIBYTES),WRITE SIZE PER SECOND (KIBIBYTES)"
# start times
start_unixseconds=$(date +%s) # for duration seconds
start_unixmicroseconds=$(date +"%s%6N") # get start microseconds fast as possible before run
# run the command with pidstat monitoring it, using eval to handle strings and args methods
eval "pidstat -h -H -d -r -u -I $poll_seconds -e $cmd >> \"$logfile\""
@@ -38,12 +37,7 @@ ret=$?
end_unixmicroseconds=$(date +"%s%6N") # get dis fast for accuracy
duration_microseconds=$(($end_unixmicroseconds - $start_unixmicroseconds))
## seconds
end_unixseconds=$(date +%s)
duration_seconds=$(($end_unixseconds - $start_unixseconds))
# add footer
echo "START_UNIX_SECONDS,END_UNIX_SECONDS,DURATION_SECONDS,DURATION_MICROSECONDS,RETURN_CODE"
echo "$start_unixseconds,$end_unixseconds,$duration_seconds,$duration_microseconds,$ret"
duration_seconds=$(($duration_microseconds / 1000000)) # seconds = microseconds / 1,000,000
cat "$logfile"
@@ -51,5 +45,10 @@ cat "$logfile"
# then squash spaces and replace with commas
# them awk by delimiter comma to output
# and replace da original file with tha fixed one
# cat "$logfile" | sed '/^#\|^$\|^Linux/d' | tr -s ' ' ',' | awk -F, '{ cpup += $3 } END { print "sunn:",cpup / NR,$1,$3,$8,$13,$14,$15,$16,$17 }'
cat "$logfile" | sed '/^#\|^$\|^Linux/d' | tr -s ' ' ',' | awk -F, '{ cpup += $3 } END { print "sunn:",cpup / NR }'
# echo $measurements_csv_fields
echo "AVERAGES: CPU% | MEMORY USAGE (KiB) | MEMORY % | READ SIZE PER SECOND (KiB) | WRITE SIZE PER SECOND (KiB)"
cat "$logfile" | sed '/^#\|^$\|^Linux/d' | tr -s ' ' ',' | awk -F, '{ cpup += $8; memk += $13; memp += $14; rkbs += $15; wkbs += $15 } END { print "%CPU: ",cpup / NR,"Memory Usage (KiB): ",memk / NR, "Memory Usage %: ",memp / NR,"\nKiB Read Per Second: ",rkbs / NR,"\nKiB Written Per Second: ",wkbs / NR }' #$1,$3,$8,$13,$14,$15,$16,$17 }'
# add footer
info_csv_fields_data="Duration Seconds: $duration_seconds Duration Microseconds: $duration_microseconds Return Code: $ret"
echo $info_csv_fields_data
# cat "$logfile" | sed '/^#\|^$\|^Linux/d' | tr -s ' ' ',' | awk -F, '{ cpup += $3 } END { print "sunn:",cpup / NR }'