Skip to content
This repository was archived by the owner on Feb 17, 2019. It is now read-only.

Commit a4277d2

Browse files
committed
Added time measure to upload
1 parent 7f9ad82 commit a4277d2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import random
99
import signal
1010
import logging
11+
import time
1112

1213
import srp
1314

@@ -87,6 +88,9 @@ def __init__(self, loop, path, packets_per_second, username, password):
8788
self.fetch_intercal = 10.0 # should be ~ 30s in production
8889
self.pending_update_callback = None
8990

91+
# For time measurements
92+
self.times = None
93+
9094
self.username = username
9195
self.authenticator = srp.User(
9296
username, password, hash_alg=srp.SHA256, ng_type=srp.NG_2048)

lib/protocol.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import io
1212
import random
13+
import time
1314

1415
from typing import Any, Dict, Tuple
1516
from enum import Enum, unique
@@ -107,6 +108,10 @@ def __init__(self, loop, path, packets_per_second):
107108
# stores the fileinfo for the local files
108109
self.fileinfo = dict()
109110

111+
# For time measurements
112+
self.times_create = dict()
113+
self.times_start = dict()
114+
110115
# list dir
111116
local_files = files.list(path)
112117
for file in local_files:
@@ -1887,6 +1892,8 @@ def upload_file(self, session_id, filename, fileinfo=None, addr=None) -> None:
18871892
"""
18881893
Upload the given file to server.
18891894
"""
1895+
self.times_create[filename] = time.monotonic()
1896+
18901897
if fileinfo is None:
18911898
fileinfo = self.get_fileinfo(filename.decode('utf8'))
18921899
# prevent double uploads do to IO-notifications (e.g. create and
@@ -2009,6 +2016,8 @@ async def do_upload(self, session_id, filename, fileinfo, upload_id, resume_at_b
20092016
File_Upload packets. It then waits for acknowledgment and resends
20102017
the packet if the sent chunk is not acknowledged.
20112018
"""
2019+
self.times_start[filename] = time.monotonic()
2020+
20122021
filepath = self.path + filename.decode('utf8')
20132022
size = fileinfo['size']
20142023
try:
@@ -2092,6 +2101,18 @@ async def do_upload(self, session_id, filename, fileinfo, upload_id, resume_at_b
20922101

20932102
del self.active_uploads[filename]
20942103
self.epoch += 1
2104+
2105+
# print upload times TODO maybe logging?
2106+
atm_time = time.monotonic()
2107+
create_time = self.times_create[filename]
2108+
start_time = self.times_start[filename]
2109+
print("Create time: %fs, Start time: %fs, End time: %fs" % (create_time, start_time, atm_time))
2110+
print("Time till start of upload: %fs, Duration upload: %fs" %(start_time - create_time, atm_time - start_time))
2111+
2112+
# Clean lists
2113+
self.times_create.pop(filename)
2114+
self.times_start.pop(filename)
2115+
20952116
print("Upload of file \"%s\" was finished" % filename)
20962117

20972118
def resend_chunks(self, session_id: int, expired_chunks, upload_id: int, chunk_buffer, addr):

0 commit comments

Comments
 (0)