Skip to content

Commit

Permalink
Add type hints to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dstolpmann committed Mar 21, 2024
1 parent f652a9e commit 9368f50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tools/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Set FIFO queue buffer size
print(f"[{perf_counter() - timestamp_start}] Set FIFO queue buffer size to {round(i)} packets!")
flowemuctl.setModuleParameter(module, parameter, round(i))
flowemuctl.setModuleParameter(module, parameter, str(round(i)))

# Increase timestamp
timestamp += 10
Expand Down
21 changes: 12 additions & 9 deletions tools/control_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,35 @@
import matplotlib.pyplot as plt
import flowemu.control as flowemu

from typing import List


flowemuctl = flowemu.Control()

# Create data arrays
buffer_size_x = []
buffer_size_y = []
queue_length_x = []
queue_length_y = []
buffer_size_x: List[float] = []
buffer_size_y: List[float] = []
queue_length_x: List[float] = []
queue_length_y: List[float] = []

# Warm up
flowemuctl.setModuleParameter("fifo_queue", "buffer_size", 0)
flowemuctl.setModuleParameter("fifo_queue", "buffer_size", str(0))
sleep(1)

# Get start timestamp
timestamp_start = perf_counter()

# Register statistic handlers
@flowemuctl.onModuleStatistic("fifo_queue", "queue_length")
def onFifoQueueQueueLength(value):
def onFifoQueueQueueLength(value: str) -> None:
timestamp = perf_counter() - timestamp_start
value_int = round(float(value))
print(f"[{timestamp}] Queue length: {value_int} packets")
queue_length_x.append(timestamp)
queue_length_y.append(value_int)

@flowemuctl.onModuleStatistic("fifo_queue", "buffer_size")
def onFifoQueueBufferSize(value):
def onFifoQueueBufferSize(value: str) -> None:
timestamp = perf_counter() - timestamp_start
value_int = round(float(value))
print(f"[{timestamp}] FIFO queue buffer size: {value_int} packets")
Expand All @@ -64,7 +67,7 @@ def onFifoQueueBufferSize(value):

# Set FIFO queue buffer size
print(f"[{perf_counter() - timestamp_start}] Set FIFO queue buffer size to {round(i)} packets!")
flowemuctl.setModuleParameter(module, parameter, round(i))
flowemuctl.setModuleParameter(module, parameter, str(round(i)))

# Increase timestamp
timestamp += 10
Expand Down Expand Up @@ -96,4 +99,4 @@ def onFifoQueueBufferSize(value):

# Show plot
plt.tight_layout()
plt.show()
plt.show() # type: ignore
9 changes: 6 additions & 3 deletions tools/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import re
import matplotlib.pyplot as plt

from typing import List


# Get path to log file
log_path = sys.argv[1]

# Create data arrays
x = []
y = []
x: List[float] = []
y: List[float] = []

# Read data from log file
with open(log_path, mode="r") as log_file:
Expand All @@ -54,4 +57,4 @@

# Show plot
plt.tight_layout()
plt.show()
plt.show() # type: ignore

0 comments on commit 9368f50

Please sign in to comment.