summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2024-05-23 10:44:54 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-05-28 23:46:21 +0100
commite598b2d135712d79577ac8ec95fc89735571687f (patch)
treef86f0c0660135fb012f082e63165ca500dcc2f72
parente9400f091c25c028aee753592b372ee6b79ae40f (diff)
downloadpoky-e598b2d135712d79577ac8ec95fc89735571687f.tar.gz
bitbake: bitbake-hashclient: Improve ping command line options
Adds a --quiet option to suppress the message for each ping, and report the median ping time. (Bitbake rev: 3c85b5e2d9b9c39507ed362aaa115b7f6f155966) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xbitbake/bin/bitbake-hashclient13
1 files changed, 10 insertions, 3 deletions
diff --git a/bitbake/bin/bitbake-hashclient b/bitbake/bin/bitbake-hashclient
index 8d15604b34..5d6f67046b 100755
--- a/bitbake/bin/bitbake-hashclient
+++ b/bitbake/bin/bitbake-hashclient
@@ -242,18 +242,24 @@ def main():
242 def handle_ping(args, client): 242 def handle_ping(args, client):
243 times = [] 243 times = []
244 for i in range(1, args.count + 1): 244 for i in range(1, args.count + 1):
245 print(f"Ping {i} of {args.count}... ", end="") 245 if not args.quiet:
246 print(f"Ping {i} of {args.count}... ", end="")
246 start_time = time.perf_counter() 247 start_time = time.perf_counter()
247 client.ping() 248 client.ping()
248 elapsed = time.perf_counter() - start_time 249 elapsed = time.perf_counter() - start_time
249 times.append(elapsed) 250 times.append(elapsed)
250 print(f"{elapsed:.3f}s") 251 if not args.quiet:
252 print(f"{elapsed:.3f}s")
251 253
252 mean = statistics.mean(times) 254 mean = statistics.mean(times)
255 median = statistics.median(times)
253 std_dev = statistics.pstdev(times) 256 std_dev = statistics.pstdev(times)
254 257
255 print("------------------------") 258 if not args.quiet:
259 print("------------------------")
260 print(f"Number of pings: {len(times)}")
256 print(f"Average round trip time: {mean:.3f}s") 261 print(f"Average round trip time: {mean:.3f}s")
262 print(f"Median round trip time: {median:.3f}s")
257 print(f"Round trip time std dev: {std_dev:.3f}s") 263 print(f"Round trip time std dev: {std_dev:.3f}s")
258 print(f"Min time is: {min(times):.3f}s") 264 print(f"Min time is: {min(times):.3f}s")
259 print(f"Max time is: {max(times):.3f}s") 265 print(f"Max time is: {max(times):.3f}s")
@@ -358,6 +364,7 @@ def main():
358 364
359 ping_parser = subparsers.add_parser('ping', help="Ping server") 365 ping_parser = subparsers.add_parser('ping', help="Ping server")
360 ping_parser.add_argument("-n", "--count", type=int, help="Number of pings. Default is %(default)s", default=10) 366 ping_parser.add_argument("-n", "--count", type=int, help="Number of pings. Default is %(default)s", default=10)
367 ping_parser.add_argument("-q", "--quiet", action="store_true", help="Don't print each ping; only print results")
361 ping_parser.set_defaults(func=handle_ping) 368 ping_parser.set_defaults(func=handle_ping)
362 369
363 args = parser.parse_args() 370 args = parser.parse_args()