-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add program to parse throughput and retransmissions from iperf3 JSON log
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Parses iperf3 sender-side JSON output file generated by cctestbedv2.py. | ||
""" | ||
|
||
import argparse | ||
import json | ||
import sys | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description="Calculate average throughput and retransmission count" | ||
) | ||
parser.add_argument( | ||
"--in-file", | ||
type=str, | ||
help="Input JSON file (output of iperf3 sender).", | ||
required=True, | ||
) | ||
parser.add_argument("--out-file", type=str, help="Output file.", required=True) | ||
return parser.parse_args() | ||
|
||
|
||
def main(args): | ||
with open(args.in_file, "r", encoding="utf-8") as fil: | ||
res = json.load(fil) | ||
|
||
if "end" not in res: | ||
print(f"Error: 'end' key not found in JSON file: {args.in_file}") | ||
return 1 | ||
|
||
bps = res["end"]["bits_per_second"] | ||
rxmits = res["end"]["retransmits"] | ||
msg = f"Throughput: {bps / 1e9:.2f} Gbps\nRetransmits: {rxmits}" | ||
print(msg) | ||
with open(args.out_file, "w", encoding="utf-8") as fil: | ||
fil.write(msg) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main(parse_args())) |