in tools/waf_perf.py [0:0]
def test(path, server, time_limit, connection, output):
src_packet_files = []
packet_files = []
if os.path.isdir(path):
for file in glob.glob(os.path.join(path, "*.txt")):
src_packet_files.append(_file)
elif os.path.isfile(path):
src_packet_files = [path]
hostname = re.search(r"^(?:https?://)?([^?/]+)", server).group(1)
for file in src_packet_files:
_file = "".join(os.path.splitext(file)[:-1]) + ".pkt"
with open(file, "rb") as src_fd:
with open(_file, "wb") as dst_fd:
content = src_fd.read().decode("utf-8")
content = re.sub(r"Host: (\S+)", "Host: " +
hostname, content, count=1, flags=re.I)
content = str(len(content.encode("utf-8"))) + "\n" + content
dst_fd.write(content.encode("utf-8"))
packet_files.append(_file)
packet_files = sorted(packet_files)
process_count = 0
with open(output, "w") as fd:
fd = csv.writer(fd)
for file in packet_files:
packet_name = re.search(r"([^/]+).pkt$", file).group(1)
error = ""
_command = command.format(time_limit=time_limit,
packet_file=file, server=server, connection=connection)
print(_command)
proc = subprocess.Popen(
_command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False,
)
latency = {}
try:
if proc.wait(timeout=(time_limit * 2)) == 0:
latency = extract_latency(proc.communicate()[0])
else:
error = proc.communicate()[1]
except subprocess.TimeoutExpired:
error = "Process timeout"
sys.stderr.write(str(error) + "\n")
if process_count == 0:
titles = ["id", "packet_name"] + list(latency.keys())
fd.writerow(titles)
process_count += 1
print("%s %s rps [%s/%s]" % (packet_name, latency, process_count, len(packet_files)))
values = [process_count, packet_name] + list(latency.values())
fd.writerow(values)