Changed output format

This commit is contained in:
Pünkösd Marcell 2020-10-23 16:10:18 +02:00
parent 96b90f4e6e
commit 94c1fdce92

View File

@ -1,3 +1,4 @@
from typing import Optional
import time import time
import pycurl import pycurl
import itertools import itertools
@ -13,6 +14,7 @@ import sys
import csv import csv
import random import random
@dataclass(frozen=False, init=True) @dataclass(frozen=False, init=True)
class UploadRequest: class UploadRequest:
id: int id: int
@ -130,18 +132,34 @@ def run_benchmark(num_workers: int, timeout: float, filename: str):
return all_requests_completed return all_requests_completed
def csv_time_format(timestamp: Optional[float]) -> Optional[str]:
if timestamp:
return datetime.fromtimestamp(timestamp).isoformat()
else:
return None
def write_results(results, file_handle): def write_results(results, file_handle):
writer = csv.writer(file_handle) writer = csv.writer(file_handle)
# fire_time = Upload complete # Latency and rtt are in ms
# latency is in ms
writer.writerow(['id', 'fire_time', 'response_arrive_time', 'latency']) writer.writerow(
['id', 'http_start_time', 'http_complete_time', 'status_code', 'mqtt_arrive_time', 'latency', 'rtt']
)
for result in results.values(): for result in results.values():
latency = int((result.alert_arrived - result.upload_started) * 1000) if result.alert_arrived else None latency = (result.alert_arrived - result.upload_finished) * 1000 if result.alert_arrived else None
fire_time = datetime.fromtimestamp(result.upload_finished).isoformat() if result.upload_finished else None rtt = (result.alert_arrived - result.upload_started) * 1000 if result.alert_arrived else None
response_arrive_time = datetime.fromtimestamp(
result.alert_arrived).isoformat() if result.alert_arrived else None row = [
row = [result.id, fire_time, response_arrive_time, latency] result.id,
csv_time_format(result.upload_started),
csv_time_format(result.upload_finished),
result.upload_status_code,
csv_time_format(result.alert_arrived),
latency,
rtt
]
writer.writerow(row) writer.writerow(row)
@ -240,7 +258,6 @@ def main():
total_runtime = max(benchmark_results.values(), key=lambda a: a.upload_finished).upload_finished - \ total_runtime = max(benchmark_results.values(), key=lambda a: a.upload_finished).upload_finished - \
min(benchmark_results.values(), key=lambda a: a.upload_started).upload_started min(benchmark_results.values(), key=lambda a: a.upload_started).upload_started
print( print(
f"{len(benchmark_results)} requests completed: {total_successful_uploads} successfully uploaded and {total_answered} answered" f"{len(benchmark_results)} requests completed: {total_successful_uploads} successfully uploaded and {total_answered} answered"
) )