Changed output format
This commit is contained in:
parent
96b90f4e6e
commit
94c1fdce92
@ -1,3 +1,4 @@
|
||||
from typing import Optional
|
||||
import time
|
||||
import pycurl
|
||||
import itertools
|
||||
@ -13,6 +14,7 @@ import sys
|
||||
import csv
|
||||
import random
|
||||
|
||||
|
||||
@dataclass(frozen=False, init=True)
|
||||
class UploadRequest:
|
||||
id: int
|
||||
@ -130,18 +132,34 @@ def run_benchmark(num_workers: int, timeout: float, filename: str):
|
||||
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):
|
||||
writer = csv.writer(file_handle)
|
||||
# fire_time = Upload complete
|
||||
# latency is in ms
|
||||
writer.writerow(['id', 'fire_time', 'response_arrive_time', 'latency'])
|
||||
# Latency and rtt are in ms
|
||||
|
||||
writer.writerow(
|
||||
['id', 'http_start_time', 'http_complete_time', 'status_code', 'mqtt_arrive_time', 'latency', 'rtt']
|
||||
)
|
||||
|
||||
for result in results.values():
|
||||
latency = int((result.alert_arrived - result.upload_started) * 1000) if result.alert_arrived else None
|
||||
fire_time = datetime.fromtimestamp(result.upload_finished).isoformat() if result.upload_finished else None
|
||||
response_arrive_time = datetime.fromtimestamp(
|
||||
result.alert_arrived).isoformat() if result.alert_arrived else None
|
||||
row = [result.id, fire_time, response_arrive_time, latency]
|
||||
latency = (result.alert_arrived - result.upload_finished) * 1000 if result.alert_arrived else None
|
||||
rtt = (result.alert_arrived - result.upload_started) * 1000 if result.alert_arrived else None
|
||||
|
||||
row = [
|
||||
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)
|
||||
|
||||
|
||||
@ -240,7 +258,6 @@ def main():
|
||||
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
|
||||
|
||||
|
||||
print(
|
||||
f"{len(benchmark_results)} requests completed: {total_successful_uploads} successfully uploaded and {total_answered} answered"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user