Skip to content

Commit

Permalink
Add script to parse bpftrace SKB len logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ccanel committed Mar 22, 2024
1 parent fe1152a commit e5e5258
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ratemon/scripts/skb_len.py
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()))

0 comments on commit e5e5258

Please sign in to comment.