Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions util/avg.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/python3

"""
Reads lines and extracts the first floating-point number to appear on
each line; prints both the individual values and the average of them.
Usage: avg.py [file]
"""

from __future__ import division, print_function
from glob import glob
from optparse import OptionParser
import math
Expand Down
12 changes: 6 additions & 6 deletions util/diff_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
diff_metrics file1 file2
"""

from __future__ import division, print_function
from __future__ import annotations
from glob import glob
from optparse import OptionParser
import math
Expand All @@ -25,7 +25,7 @@
# metric names, values are metric values.
metrics = {}

def scan_first(name):
def scan_first(name: str) -> None:
"""
Scan the metrics file given by 'name' and record its metrics.
"""
Expand All @@ -37,10 +37,10 @@ def scan_first(name):
if not match:
print("Didn't match: %s\n" % (line))
continue
metrics[match.group(1)] = long(match.group(2))
metrics[match.group(1)] = int(match.group(2))
f.close()

def scan_second(name):
def scan_second(name: str) -> None:
"""
Scan the metrics file given by 'name', compare its metrics to
those that have been recorded, and print an output line with
Expand All @@ -55,7 +55,7 @@ def scan_second(name):
print("Didn't match: %s\n" % (line))
continue
name = match.group(1)
value = long(match.group(2))
value = int(match.group(2))
comment = match.group(3)
if not name in metrics:
print("No metric for %s\n" % (name))
Expand All @@ -68,7 +68,7 @@ def scan_second(name):
f.close()

if len(sys.argv) != 3:
printf("Usage: %s file file2\n" % sys.argv[0])
print("Usage: %s file file2\n" % sys.argv[0])
exit(1)

scan_first(sys.argv[1])
Expand Down
8 changes: 4 additions & 4 deletions util/diff_rtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Usage: diff_rtts.py file1 file2
"""

from __future__ import division, print_function
from __future__ import annotations
from glob import glob
from operator import itemgetter
from optparse import OptionParser
Expand All @@ -19,7 +19,7 @@
import string
import sys

def read_rtts(file):
def read_rtts(file: str) -> list[list[float]]:
"""
Read a .rtts file and returns a list of (length, slowdown) pairs.

Expand All @@ -44,7 +44,7 @@ def read_rtts(file):
f.close()
return slowdowns

def avg_slowdown(slowdowns):
def avg_slowdown(slowdowns: list[list[float]]) -> float:
"""
Return average slowdown from a list of (length, slowdown) pairs.

Expand All @@ -55,7 +55,7 @@ def avg_slowdown(slowdowns):
sum += item[1]
return sum/len(slowdowns)

def deciles(slowdowns):
def deciles(slowdowns: list[list[float]]) -> tuple[list[float], list[float], list[float], list[float], list[float], list[float]]:
"""
Given a list of (length, slowdown) pairs, divide into 10 groups by
length, then returns 6 lists (each with one entry per decile),
Expand Down
7 changes: 4 additions & 3 deletions util/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
what has changed. File defaults to ~/.homa_metrics.
"""

from __future__ import division, print_function
from __future__ import annotations
from typing import TextIO
from glob import glob
from optparse import OptionParser
import math
Expand Down Expand Up @@ -42,7 +43,7 @@
# Read in metrics, parse the results for internal use, and, optionally
# copy the raw metrics to an output file. Also reinitialize symbols

def read_metrics(metrics_file, out):
def read_metrics(metrics_file: str, out: TextIO | None) -> list[dict[str, int]]:
"""
Read metrics from the file whose name is "metrics_file" and generate
a data structure in the format described above for "prev". In
Expand Down Expand Up @@ -80,7 +81,7 @@ def read_metrics(metrics_file, out):
f.close()
return metrics

def scale_number(number):
def scale_number(number: float) -> str:
"""
Return a string describing a number, but with a "K", "M", or "G"
suffix to keep the number small and readable
Expand Down
21 changes: 12 additions & 9 deletions util/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

# This file provides a library of functions for generating plots.

from __future__ import annotations
from typing import Any

import matplotlib
import matplotlib.pyplot as plt
import os
Expand Down Expand Up @@ -38,7 +41,7 @@
# in that column.
file_data = {}

def __read_file(file):
def __read_file(file: str) -> None:
"""
Read a file and add its contents to the file_data variable. If the
file has already been read, then this function does nothing.
Expand Down Expand Up @@ -83,7 +86,7 @@ def __read_file(file):
f.close()
file_data[file] = columns

def get_column(file, column):
def get_column(file: str, column: str) -> list[float | str]:
"""
Return a list containing the values of a given column in a given file.

Expand All @@ -96,15 +99,15 @@ def get_column(file, column):
raise Exception('Column %s doesn\'t exist in %s' % (column, name))
return file_data[file][column]

def get_column_names(file):
def get_column_names(file: str) -> Any:
"""
Returns a list containing the names of all of the columns in file.
"""

__read_file(file)
return file_data[file].keys()

def get_numbers(file):
def get_numbers(file: str) -> list[int]:
"""
Scans all of the column names in file for numbers and returns a
sorted list of all the unique numbers found.
Expand All @@ -117,7 +120,7 @@ def get_numbers(file):
numbers.add(int(match.group(1)))
return sorted(list(numbers))

def max_value(file, columns):
def max_value(file: str, columns: list[str]) -> float | str | None:
"""
Returns the largest value in a set of columns.

Expand All @@ -131,7 +134,7 @@ def max_value(file, columns):
overall_max = col_max
return overall_max

def node_name(file):
def node_name(file: str) -> str:
"""
Given the name of a trace file, return a shorter name that can be
used (e.g. in titles) to identify the node represented by the file.
Expand All @@ -142,8 +145,8 @@ def node_name(file):
name = name[i+1:]
return name

def start_plot(max_x, max_y, title="", x_label="", y_label="", size=10,
figsize=[6,4]):
def start_plot(max_x: float, max_y: float, title: str = "", x_label: str = "",
y_label: str = "", size: int = 10, figsize: list[int] = [6,4]) -> Any:
"""
Create a basic pyplot graph without plotting any data. Returns the
Axes object for the plot.
Expand All @@ -169,7 +172,7 @@ def start_plot(max_x, max_y, title="", x_label="", y_label="", size=10,
ax.set_ylabel(y_label, size=size)
return ax

def plot_colors(file):
def plot_colors(file: str) -> None:
"""
Generates a test plot that shows the standard colors defined above.

Expand Down
5 changes: 3 additions & 2 deletions util/plot_tthoma.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# This file provides a collection of functions that plot data generated
# by tthoma.py. Invoke with the --help option for more information.

from __future__ import annotations
from glob import glob
from optparse import OptionParser
import math
Expand All @@ -19,7 +20,7 @@

import plot

def backlog(data_file, plot_file):
def backlog(data_file: str, plot_file: str) -> None:
"""
Generates a plot of network backlog data produced by the "net"
analyzer of tthoma.py.
Expand Down Expand Up @@ -51,7 +52,7 @@ def backlog(data_file, plot_file):
plt.savefig(plot_file)


def colors(plot_file):
def colors(plot_file: str) -> None:
"""
Generates a plot displaying standard colors.

Expand Down
10 changes: 5 additions & 5 deletions util/rpcid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
about the RPC described by that line.
"""

from __future__ import division, print_function
from __future__ import annotations
from glob import glob
from optparse import OptionParser
import math
Expand Down Expand Up @@ -54,7 +54,7 @@

rpcs_analyzed = 0

def track_nic_queue(line, time):
def track_nic_queue(line: str, time: float) -> None:
"""
Update info about the NIC queue length to reflect the transmission
of a new packet (or several packets if there is TSO)
Expand Down Expand Up @@ -83,7 +83,7 @@ def track_nic_queue(line, time):
# print("NIC queue: bytes %d, usecs %.3f, time %.3f empty_time %.3f" %
# (bytes, usecs, time, nic_empty_time))

def add_stat(name, value):
def add_stat(name: str, value: float) -> None:
"""
Record a statistic with a given name and value (either appends to an
existing list in stats or starts a new one).
Expand All @@ -95,13 +95,13 @@ def add_stat(name, value):
else:
stats[name].append(value)

def avg_stat(name):
def avg_stat(name: str) -> float:
global stats
if not name in stats:
return 0.0
return sum(stats[name]) / len(stats[name])

def analyze_rpc(id, client_num, server_num):
def analyze_rpc(id: str, client_num: int | str, server_num: str) -> None:
"""
Analyze the client and server timetraces for a given RPC and output
a latency breakdown for the RPC.
Expand Down
11 changes: 6 additions & 5 deletions util/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
The existing timetrace is in tt_file (or stdin in tt_file is omitted).
"""

from __future__ import division, print_function
from __future__ import annotations
from typing import Any
from glob import glob
from optparse import OptionParser
import math
Expand Down Expand Up @@ -73,7 +74,7 @@
max = 0
max_id = ""

def average(dict, key):
def average(dict: list[dict[str, Any]], key: str) -> float:
sum = 0.0
if len(dict) == 0:
return 0.0
Expand All @@ -84,7 +85,7 @@ def average(dict, key):
sum += record[key]
return sum/len(dict)

def largest(dict, key):
def largest(dict: list[dict[str, Any]], key: str) -> dict[str, Any] | float | None:
max = None
if len(dict) == 0:
return 0.0
Expand All @@ -93,7 +94,7 @@ def largest(dict, key):
max = record
return max

def smallest(dict, key):
def smallest(dict: list[dict[str, Any]], key: str) -> dict[str, Any] | float | None:
min = None
if len(dict) == 0:
return 0.0
Expand All @@ -102,7 +103,7 @@ def smallest(dict, key):
min = record
return min

def collect(dict, key):
def collect(dict: list[dict[str, Any]], key: str) -> list[float]:
result = []
for record in dict:
if key in record:
Expand Down
1 change: 0 additions & 1 deletion util/smi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
The existing timetrace is in tt_file (or stdin in tt_file is omitted).
"""

from __future__ import division, print_function
from glob import glob
from optparse import OptionParser
import math
Expand Down
13 changes: 7 additions & 6 deletions util/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#endif /* See strip.py */
"""

from __future__ import annotations
from collections import defaultdict
from glob import glob
from optparse import OptionParser
Expand All @@ -74,7 +75,7 @@

exit_code = 0

def remove_close(line):
def remove_close(line: str) -> str:
"""
Given a line of text containing a '}', remove the '}' and any
following white space. If there is no '}', returns the original line.
Expand All @@ -87,7 +88,7 @@ def remove_close(line):
break
return line[0:i] + line [j:]

def remove_open(line):
def remove_open(line: str) -> str:
"""
Given a line of text containing a '{', remove the '{' and any
preceding white space. If there is no '{', returns the original line.
Expand All @@ -101,7 +102,7 @@ def remove_open(line):
break
return line[0:j+1] + line [i+1:]

def leading_space(line):
def leading_space(line: str) -> int:
"""
Return the number of characters of leading space in a line (a tab counts
as 8 spaces).
Expand All @@ -117,7 +118,7 @@ def leading_space(line):
break
return count

def last_non_blank(s):
def last_non_blank(s: str) -> str | None:
"""
Return the last non-blank character in s, or None if there is no
non-blank character in s.
Expand All @@ -127,7 +128,7 @@ def last_non_blank(s):
return s2[-1]
return None

def blank_next_ok(line):
def blank_next_ok(line: str) -> bool:
"""
Given a line, return True if it is OK for this line to be followed by
a blank line. False means that if the next line to be output is blank,
Expand All @@ -140,7 +141,7 @@ def blank_next_ok(line):
return False
return True

def scan(file):
def scan(file: str) -> list[str]:
"""
Read a file, remove information that shouldn't appear in the Linux kernel
version, and return an array of lines representing the stripped file.
Expand Down
Loading