-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
De-factor the summarize_pings() function;
This makes both betterspeedtest.sh and netperfrunner.sh a single-file script again.
- Loading branch information
1 parent
eac7700
commit 34cfbd3
Showing
3 changed files
with
95 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,52 @@ | |
# Copyright (c) 2014-2022 - Rich Brown [email protected] | ||
# 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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] | ||
# Copyright (c) 2014-2022 - Rich Brown [email protected] | ||
# 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 -------- | ||
|