|
10 | 10 | import os
|
11 | 11 | import io
|
12 | 12 | import random
|
| 13 | +import time |
13 | 14 |
|
14 | 15 | from typing import Any, Dict, Tuple
|
15 | 16 | from enum import Enum, unique
|
@@ -107,6 +108,10 @@ def __init__(self, loop, path, packets_per_second):
|
107 | 108 | # stores the fileinfo for the local files
|
108 | 109 | self.fileinfo = dict()
|
109 | 110 |
|
| 111 | + # For time measurements |
| 112 | + self.times_create = dict() |
| 113 | + self.times_start = dict() |
| 114 | + |
110 | 115 | # list dir
|
111 | 116 | local_files = files.list(path)
|
112 | 117 | for file in local_files:
|
@@ -1887,6 +1892,8 @@ def upload_file(self, session_id, filename, fileinfo=None, addr=None) -> None:
|
1887 | 1892 | """
|
1888 | 1893 | Upload the given file to server.
|
1889 | 1894 | """
|
| 1895 | + self.times_create[filename] = time.monotonic() |
| 1896 | + |
1890 | 1897 | if fileinfo is None:
|
1891 | 1898 | fileinfo = self.get_fileinfo(filename.decode('utf8'))
|
1892 | 1899 | # 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
|
2009 | 2016 | File_Upload packets. It then waits for acknowledgment and resends
|
2010 | 2017 | the packet if the sent chunk is not acknowledged.
|
2011 | 2018 | """
|
| 2019 | + self.times_start[filename] = time.monotonic() |
| 2020 | + |
2012 | 2021 | filepath = self.path + filename.decode('utf8')
|
2013 | 2022 | size = fileinfo['size']
|
2014 | 2023 | try:
|
@@ -2092,6 +2101,18 @@ async def do_upload(self, session_id, filename, fileinfo, upload_id, resume_at_b
|
2092 | 2101 |
|
2093 | 2102 | del self.active_uploads[filename]
|
2094 | 2103 | 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 | + |
2095 | 2116 | print("Upload of file \"%s\" was finished" % filename)
|
2096 | 2117 |
|
2097 | 2118 | def resend_chunks(self, session_id: int, expired_chunks, upload_id: int, chunk_buffer, addr):
|
|
0 commit comments