Skip to content

Commit

Permalink
performance logger as independent module
Browse files Browse the repository at this point in the history
  • Loading branch information
matanbroner committed May 14, 2023
1 parent 63f76f0 commit 1e2fdcd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test
*.db
*.journal
figures/
config.yaml

# Prerequisites
*.d
Expand Down
45 changes: 44 additions & 1 deletion 5GTC/pkg/performance_logger/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import time
import sys
import argparse
import threading
from pkg.performance_logger.db import DB
from pkg.performance_logger.webui import WebUI
Expand Down Expand Up @@ -32,6 +34,9 @@ def __init__(self, sock, log="INFO"):
self._inserted_subflows_cache = {}
self.webui.log_iteration_page(self.iteration_id)

def __del__(self):
self.stop()

def init_db(self):
self.db = DB({
"db_path": "performance_log.db",
Expand Down Expand Up @@ -99,4 +104,42 @@ def _run_logger(self, interval_ms, features):
# Sleep for the interval assigned
time.sleep(interval_ms)

self.db.conn.close()
self.db.conn.close()


# Allow the PerformanceLogger to run as an independent module for
# on-server testing as opposed to just through a Transport Converter
if __name__ == "__main__":
if len(sys.argv) < 2 or "".join(sys.argv).find("--help") != -1:
print("Usage: python3 logger.py <socket fd> [--webui-host <host>] [--webui-port <port>] [--interval <interval>] [--features <features>] [--log <log>]")
print("\t<socket fd>: Socket file descriptor to log performance metrics for")
print("\t--webui-host <host>: Host to run the webui on")
print("\t--webui-port <port>: Port to run the webui on")
print("\t--interval <interval>: Interval in ms to log the performance metrics")
print("\t--features <features>: Features to log")
print("\t--log <log>: Log level")
print("Example: python3 logger.py 3 --webui-host localhost --webui-port 5000 --interval 1000 --features all --log INFO")

sys.exit(1)
# Read the command line arguments
parser = argparse.ArgumentParser(description="Performance Logger")
parser.add_argument("sockfd", type=int, help="Socket file descriptor")
parser.add_argument("--webui-host", type=str, default="localhost", help="Host to run the webui on")
parser.add_argument("--webui-port", type=int, default=5000, help="Port to run the webui on")
parser.add_argument("--interval", type=int, default=1000, help="Interval in ms to log the performance metrics")
parser.add_argument("--features", type=str, default="all", help="Features to log")
parser.add_argument("--log", type=str, default="INFO", help="Log level")
args = parser.parse_args()

# Initialize the WebUI module
webui = WebUI(args.host, args.port, log=args.log)

# Feature split by comma
features = args.features.split(",")

# Initialize the PerformanceLogger
logger = PerformanceLogger(args.sockfd, log=args.log)

# Run the logger
logger.run(interval_ms=args.interval, features=features)

3 changes: 2 additions & 1 deletion 5GTC/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flask
matplotlib
numpy
scapy
scapy
pyyaml

0 comments on commit 1e2fdcd

Please sign in to comment.