This commit is contained in:
2025-11-04 06:20:00 -07:00
parent 694d7d06c4
commit 6a599668b8
2 changed files with 93 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
#!/bin/bash
# usage:
## both quoted and unquoted commands work~
## measure_performance my_command -with -args
## measure_performance "my_command -with -args"
cmd="$@" # da command as a string or as args
start_date=$(date)
start_unixseconds=$(date +%s)
poll_seconds=2
logfile=sillylog.csv
# throw a fit if no args supplied
if [ -z "$1" ]; then
echo 'USAGE: measure_performance "string_command-with -args"'
exit 1
fi
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
echo "$logfile found, deleting it"
rm -f "$logfile"
fi
# csv headers
echo "TIMESTAMP,PID,CPU USAGE %,MEMORY USAGE (KIBIBYTES),MEMORY USAGE %,READ VOLUME PER SECOND (KIBIBYTES),WRITE SIZE PER SECOND (KIBIBYTES)" > "$logfile"
# 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\""
# get exit code
ret=$?
# end times
## microseconds
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"
cat "$logfile"
# remove lines starting with # (comments), empty lines, and those starting with Linux so its a pure csv
# 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 }'
+39
View File
@@ -0,0 +1,39 @@
Linux 6.6.87.2-microsoft-standard-WSL2 (PrincessPi-Desk) 11/04/2025 _x86_64_ (24 CPU)
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262310 1000 164568 98.00 2.00 0.00 0.00 4.17 15 989.50 0.00 1762980 38784 0.24 0.00 8.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262312 1000 164568 98.00 1.00 0.00 0.00 4.13 15 807.50 0.00 1759736 45764 0.28 0.00 12.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262314 1000 164568 97.00 3.50 0.00 0.00 4.19 15 2553.00 0.00 1761956 73028 0.45 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262316 1000 164568 99.00 1.00 0.00 0.00 4.17 15 121.50 0.00 1761956 73988 0.45 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262318 1000 164568 99.50 0.50 0.00 0.00 4.17 15 34.00 0.00 1761956 74180 0.45 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262320 1000 164568 99.00 0.50 0.00 0.00 4.15 15 57.50 0.00 1761956 74756 0.46 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262322 1000 164568 99.00 1.50 0.00 0.00 4.19 15 30.00 0.00 1761956 74948 0.46 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262324 1000 164568 99.00 1.00 0.00 0.00 4.17 15 56.50 0.00 1761296 74724 0.46 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262326 1000 164568 99.00 1.00 0.00 0.00 4.17 15 39.00 0.00 1761296 75108 0.46 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262328 1000 164568 99.50 0.50 0.00 0.00 4.16 15 102.50 0.00 1761296 75876 0.46 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262330 1000 164568 257.00 0.50 0.00 0.00 10.73 15 551.00 0.00 1765464 84620 0.52 0.00 0.00 0.00 0 oniux
# Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
1762262332 1000 164568 66.00 1.00 0.00 0.00 2.79 15 328.00 0.00 1759736 82340 0.50 0.00 12.00 0.00 0 oniux
185.220.101.5
1 Linux 6.6.87.2-microsoft-standard-WSL2 (PrincessPi-Desk) 11/04/2025 _x86_64_ (24 CPU)
2 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
3 1762262310 1000 164568 98.00 2.00 0.00 0.00 4.17 15 989.50 0.00 1762980 38784 0.24 0.00 8.00 0.00 0 oniux
4 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
5 1762262312 1000 164568 98.00 1.00 0.00 0.00 4.13 15 807.50 0.00 1759736 45764 0.28 0.00 12.00 0.00 0 oniux
6 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
7 1762262314 1000 164568 97.00 3.50 0.00 0.00 4.19 15 2553.00 0.00 1761956 73028 0.45 0.00 0.00 0.00 0 oniux
8 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
9 1762262316 1000 164568 99.00 1.00 0.00 0.00 4.17 15 121.50 0.00 1761956 73988 0.45 0.00 0.00 0.00 0 oniux
10 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
11 1762262318 1000 164568 99.50 0.50 0.00 0.00 4.17 15 34.00 0.00 1761956 74180 0.45 0.00 0.00 0.00 0 oniux
12 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
13 1762262320 1000 164568 99.00 0.50 0.00 0.00 4.15 15 57.50 0.00 1761956 74756 0.46 0.00 0.00 0.00 0 oniux
14 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
15 1762262322 1000 164568 99.00 1.50 0.00 0.00 4.19 15 30.00 0.00 1761956 74948 0.46 0.00 0.00 0.00 0 oniux
16 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
17 1762262324 1000 164568 99.00 1.00 0.00 0.00 4.17 15 56.50 0.00 1761296 74724 0.46 0.00 0.00 0.00 0 oniux
18 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
19 1762262326 1000 164568 99.00 1.00 0.00 0.00 4.17 15 39.00 0.00 1761296 75108 0.46 0.00 0.00 0.00 0 oniux
20 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
21 1762262328 1000 164568 99.50 0.50 0.00 0.00 4.16 15 102.50 0.00 1761296 75876 0.46 0.00 0.00 0.00 0 oniux
22 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
23 1762262330 1000 164568 257.00 0.50 0.00 0.00 10.73 15 551.00 0.00 1765464 84620 0.52 0.00 0.00 0.00 0 oniux
24 # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
25 1762262332 1000 164568 66.00 1.00 0.00 0.00 2.79 15 328.00 0.00 1759736 82340 0.50 0.00 12.00 0.00 0 oniux
26 185.220.101.5