diff --git a/betterspeedtest.sh b/betterspeedtest.sh index 90673f0..25facbc 100755 --- a/betterspeedtest.sh +++ b/betterspeedtest.sh @@ -21,8 +21,52 @@ # Copyright (c) 2014-2022 - Rich Brown rich.brown@blueberryhillsoftware.com # GPLv2 -# include the summarize_pings() function from the lib directory -. "./lib/summarize_pings.sh" + # Process the ping times from the passed-in file, and summarize the results + # grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them + # Use awk to build an array of those values, and print first & last (which are min, max) + # and compute average. + # If the number of samples is >= 10, also compute median, and 10th and 90th percentile readings + + # Display the values as: + # Latency: (in msec, 11 pings, 8.33% packet loss) + # Min: 16.556 + # 10pct: 16.561 + # Median: 22.370 + # Avg: 21.203 + # 90pct: 23.202 + # Max: 23.394 + +summarize_pings() { + +grep "time" < "$1" | cat | \ +sed 's/^.*time=\([^ ]*\) ms/\1/'| \ + # tee >&2 | \ + sort -n | \ + awk 'BEGIN {numdrops=0; numrows=0} \ + { \ + # print ; \ + if ( $0 ~ /timeout/ ) { \ + numdrops += 1; \ + } else { \ + numrows += 1; \ + arr[numrows]=$1; sum+=$1; \ + } \ + } \ + END { \ + pc10="-"; pc90="-"; med="-"; \ + if (numrows == 0) {numrows=1} \ + if (numrows>=10) \ + { # get the 10th pctile - never the first one + ix=int(numrows/10); if (ix=1) {ix+=1}; pc10=arr[ix]; \ + # get the 90th pctile + ix=int(numrows*9/10);pc90=arr[ix]; \ + # get the median + if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \ + }; \ + pktloss = numdrops/(numdrops+numrows) * 100; \ + printf("\n Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\ + }' +} # Print a line of dots as a progress indicator. diff --git a/lib/summarize_pings.sh b/lib/summarize_pings.sh index 8729338..4354537 100644 --- a/lib/summarize_pings.sh +++ b/lib/summarize_pings.sh @@ -1,5 +1,3 @@ -summarize_pings() { - # Process the ping times from the passed-in file, and summarize the results # grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them # Use awk to build an array of those values, and print first & last (which are min, max) @@ -15,6 +13,8 @@ summarize_pings() { # 90pct: 23.202 # Max: 23.394 +summarize_pings() { + grep "time" < "$1" | cat | \ sed 's/^.*time=\([^ ]*\) ms/\1/'| \ # tee >&2 | \ @@ -43,4 +43,4 @@ sed 's/^.*time=\([^ ]*\) ms/\1/'| \ pktloss = numdrops/(numdrops+numrows) * 100; \ printf("\n Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\ }' -} \ No newline at end of file +} diff --git a/netperfrunner.sh b/netperfrunner.sh index d1c74be..e287671 100755 --- a/netperfrunner.sh +++ b/netperfrunner.sh @@ -24,39 +24,54 @@ # -p | --ping: Host to ping to measure latency (default - gstatic.com) # -n | --number: Number of simultaneous sessions (default - 5 sessions) -# Copyright (c) 2014 - Rich Brown rich.brown@blueberryhillsoftware.com +# Copyright (c) 2014-2022 - Rich Brown rich.brown@blueberryhillsoftware.com # GPLv2 -# Summarize the contents of the ping's output file to show min, avg, median, max, etc. -# input parameter ($1) file contains the output of the ping command - -summarize_pings() { - - # Process the ping times, and summarize the results - # grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them - # awk builds an array of those values, and prints first & last (which are min, max) - # and computes average. - # If the number of samples is >= 10, also computes median, and 10th and 90th percentile readings - sed 's/^.*time=\([^ ]*\) ms/\1/' < $1 | grep -v "PING" | sort -n | \ - awk 'BEGIN {numdrops=0; numrows=0;} \ - { \ - if ( $0 ~ /timeout/ ) { \ - numdrops += 1; \ - } else { \ - numrows += 1; \ - arr[numrows]=$1; sum+=$1; \ - } \ - } \ - END { \ - pc10="-"; pc90="-"; med="-"; \ - if (numrows == 0) {numrows=1} \ - if (numrows>=10) \ - { ix=int(numrows/10); pc10=arr[ix]; ix=int(numrows*9/10);pc90=arr[ix]; \ - if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \ - }; \ - pktloss = numdrops/(numdrops+numrows) * 100; \ - printf(" Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\ - }' + # Process the ping times from the passed-in file, and summarize the results + # grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them + # Use awk to build an array of those values, and print first & last (which are min, max) + # and compute average. + # If the number of samples is >= 10, also compute median, and 10th and 90th percentile readings + + # Display the values as: + # Latency: (in msec, 11 pings, 8.33% packet loss) + # Min: 16.556 + # 10pct: 16.561 + # Median: 22.370 + # Avg: 21.203 + # 90pct: 23.202 + # Max: 23.394 + +summarize_pings() { + +grep "time" < "$1" | cat | \ +sed 's/^.*time=\([^ ]*\) ms/\1/'| \ + # tee >&2 | \ + sort -n | \ + awk 'BEGIN {numdrops=0; numrows=0} \ + { \ + # print ; \ + if ( $0 ~ /timeout/ ) { \ + numdrops += 1; \ + } else { \ + numrows += 1; \ + arr[numrows]=$1; sum+=$1; \ + } \ + } \ + END { \ + pc10="-"; pc90="-"; med="-"; \ + if (numrows == 0) {numrows=1} \ + if (numrows>=10) \ + { # get the 10th pctile - never the first one + ix=int(numrows/10); if (ix=1) {ix+=1}; pc10=arr[ix]; \ + # get the 90th pctile + ix=int(numrows*9/10);pc90=arr[ix]; \ + # get the median + if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \ + }; \ + pktloss = numdrops/(numdrops+numrows) * 100; \ + printf("\n Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\ + }' } # ------- Start of the main routine --------