From 88bd2c084c940bdcf039d142e1fdf23f29057426 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 13 May 2021 22:58:36 +0200 Subject: [PATCH] misc --- .vscode/launch.py | 2 +- scripts/speedtest-fs.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.py b/.vscode/launch.py index df4bd936..809fa2a2 100644 --- a/.vscode/launch.py +++ b/.vscode/launch.py @@ -12,7 +12,7 @@ sys.path.insert(0, os.getcwd()) import jstyleson from copyparty.__main__ import main as copyparty -with open(".vscode/launch.json", "r") as f: +with open(".vscode/launch.json", "r", encoding="utf-8") as f: tj = f.read() oj = jstyleson.loads(tj) diff --git a/scripts/speedtest-fs.py b/scripts/speedtest-fs.py index a5a3f552..12bfe5a0 100644 --- a/scripts/speedtest-fs.py +++ b/scripts/speedtest-fs.py @@ -17,14 +17,15 @@ __license__ = "MIT" __url__ = "https://github.com/9001/copyparty/" -def get_spd(nbyte, nsec): +def get_spd(nbyte, nfiles, nsec): if not nsec: - return "0.000 MB 0.000 sec 0.000 MB/s" + return "0.000 MB 0 files 0.000 sec 0.000 MB/s 0.000 f/s" mb = nbyte / (1024 * 1024.0) spd = mb / nsec + nspd = nfiles / nsec - return f"{mb:.3f} MB {nsec:.3f} sec {spd:.3f} MB/s" + return f"{mb:.3f} MB {nfiles} files {nsec:.3f} sec {spd:.3f} MB/s {nspd:.3f} f/s" class Inf(object): @@ -36,6 +37,7 @@ class Inf(object): self.mtx_reports = threading.Lock() self.n_byte = 0 + self.n_file = 0 self.n_sec = 0 self.n_done = 0 self.t0 = t0 @@ -63,7 +65,8 @@ class Inf(object): continue msgs = msgs[-64:] - msgs = [f"{get_spd(self.n_byte, self.n_sec)} {x}" for x in msgs] + spd = get_spd(self.n_byte, len(self.reports), self.n_sec) + msgs = [f"{spd} {x}" for x in msgs] print("\n".join(msgs)) def report(self, fn, n_byte, n_sec): @@ -131,8 +134,9 @@ def main(): num_threads = 8 read_sz = 32 * 1024 + targs = (q, inf, read_sz) for _ in range(num_threads): - thr = threading.Thread(target=worker, args=(q, inf, read_sz,)) + thr = threading.Thread(target=worker, args=targs) thr.daemon = True thr.start() @@ -151,14 +155,14 @@ def main(): log = inf.reports log.sort() for nbyte, nsec, fn in log[-64:]: - print(f"{get_spd(nbyte, nsec)} {fn}") + spd = get_spd(nbyte, len(log), nsec) + print(f"{spd} {fn}") print() print("\n".join(inf.errors)) - print(get_spd(inf.n_byte, t2 - t0)) + print(get_spd(inf.n_byte, len(log), t2 - t0)) if __name__ == "__main__": main() -