-
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 script to parse bpftrace SKB len logs
- 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 bpftrace.log files generated by cctestbedv2.py's receiver metrics logging. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
|
||
import numpy as np | ||
|
||
PERCENTILES = [10, 25, 50, 75, 90, 95, 99, 100] | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description="Calculate statistics about SKB length" | ||
) | ||
parser.add_argument("--in-file", type=str, help="Input file.", required=True) | ||
parser.add_argument("--out-file", type=str, help="Output file.", required=True) | ||
return parser.parse_args() | ||
|
||
|
||
def main(args): | ||
lens = [] | ||
with open(args.in_file, "r", encoding="utf-8") as fil: | ||
for line in fil: | ||
if "len," in line: | ||
lens.append(int(line.strip().split(",")[2])) | ||
print(f"Found {len(lens)} SKB lengths.") | ||
lens = np.asarray(lens) | ||
metrics = dict(zip(PERCENTILES, np.percentile(lens, PERCENTILES))) | ||
metrics["avg"] = np.mean(lens) | ||
msg = "Percentiles:\n\t" + "\n\t".join( | ||
f"{a}: {b}" for a, b in sorted(metrics.items(), key=lambda x: x[0]) | ||
) | ||
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())) |