1762289793

This commit is contained in:
2025-11-04 13:56:32 -07:00
parent 8544c4fab4
commit dd4d32ee2a
+18 -9
View File
@@ -1,8 +1,15 @@
#!/bin/bash
# usage:
## both quoted and unquoted commands work~
## measure_performance my_command -with -args
## measure_performance "my_command -with -args"
## both quoted and unquoted commands work for oneshot mode~
### measure_performance my_command -with -args
### measure_performance "my_command -with -args"
## if $1 is a file, it will read as text and test the commands, one per line
### measure_performance path/to/file.txt
#### file.txt
#### rm -rf ~/Downloads
#### sleep 10
#### wget https://example.com/file.zip
#### unzip file.zip
# todo: calculate human readable sizes for mem, r and w
# todo: batch mode
@@ -38,6 +45,10 @@ if [ -f "$csv_file" ]; then
fi
measure_performance () {
if [ -f "$csv_file" ]; then
rm -f "$csv_file"
fi
# use microseconds for timing for ONE MILLION DOLLARS more times resolution
start_unixmicroseconds=$(date +"%s%6N") # get start microseconds fast as possible before run
@@ -60,7 +71,8 @@ measure_performance () {
else
elapsed_seconds=$((`date +%s` - $start_seconds))
# parse and appand dem 2 da csv
cat "$logfile" | sed -n '/^[0-9]/p' | tr -s ' ' ',' | awk -F, "{cpup+=\$8;memk+=\$13;memp=\$14;rkbs+=\$15;wkbs+=\$15}{print \"$position\",cpup/NR,memk/NR,memp/NR,rkbs/NR,wkbs/NR,\"$duration_microseconds\",\"$test_cmd\",\"$ret\",\"$elapsed_seconds\"}" | tee -a "$csv_file"
cat "$logfile" | sed -n '/^[0-9]/p' | tr -s ' ' ',' | awk -F, "{cpup+=\$8;memk+=\$13;memp=\$14;rkbs+=\$15;wkbs+=\$15}{print \"$position\",cpup/NR,memk/NR,memp/NR,rkbs/NR,wkbs/NR,\"$duration_microseconds\",\"$ret\",\"$elapsed_seconds\"}" | tr ' ' ',' | tee -a "$csv_file"
printf "%s" $test_cmd
# cat "$logfile" | sed '/^#\|^$\|^Linux/d' | tr -s ' ' ',' | awk -F, "{cpup+= \$8;memk+=\$13;memp +=\$14;rkbs+=\$15;wkbs+=\$16 } END {print \"$position\",\",\",cpup/NR,\",\",memk/NR,\",\",memp/NR,\",\",rkbs/NR,\",\",wkbs/NR,\",\",\"$duration_microseconds\",\",\",\"$test_cmd\",\",\",\"$ret\",\",\",\"$elapsed_seconds\"}" | tr -d ' ' | tee -a "$csv_file"
fi
}
@@ -70,17 +82,14 @@ measure_performance () {
## cat /tmp/sillylog.tmp | sed '/^#\|^$\|^Linux/d' | tr -s ' ' ',' | awk -F, '{print "Time:",$1,"UID:",$2,"PID:",$3,"%usr:",$4,"%system:",$5,"%guest:",$6,"%wait:",$7,"%CPU:",$8,"CPU:",$9,"minflt/s:",$10,"majflt/s:",$11,"VSZ:",$12,"RSS:",$13,"%MEM:",$14,"kB_rd/s:",$15,"kB_wr/s:",$16,"kB_ccwr/s:",$17,"iodelay:",$18,"Command:",$19}'
## if oneshot mode
if [ ! -f "$input" ]; then
test_cmd="$@"
test_cmd="$(echo \"$@\" | sed 's/\ /_/g')"
echo $test_cmd
measure_performance
## if batch mode
else
# settans
len=$(wc -l "$input" | awk '{print $1}') # num of lines in da fiel
count=1
# if [ -f "$csv_file" ]; then
# rm -f "$csv_file"
# fi
# add da csv headers to the results fiel
echo "0Position,CPU %,Memory (KiB),Memory %,KiB Read/Second,KiB Written/Second,Duration Microseconds,Command,Return Code,Seconds Elapsed" > "$csv_file"