print transfer stats

This commit is contained in:
Daniel Langbein 2023-01-12 21:06:52 +01:00
parent 1f38720072
commit 5bb4fe6208
3 changed files with 31 additions and 1 deletions

View File

@ -11,6 +11,8 @@ from p1st.repeat import repeat_until_successful
def main():
args = parse_args()
#
ssh_source: str = args.ssh_source

View File

@ -1,12 +1,16 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import subprocess
import sys
import threading
import time
from pathlib import Path
from queue import Queue
from typing import Callable, IO, AnyStr
from p1st.data_units import DataUnitConverter
def execute_consume_chunks(command: list[str],
handle_chunks: Callable[[Queue.put], None],
@ -56,11 +60,23 @@ def execute_consume_chunks(command: list[str],
def _stdin_worker(queue_get: Queue.get,
binary_stdin: IO[AnyStr],
):
start_time = time.time()
transferred_bytes = 0
while True:
chunk_path, last_chunk = queue_get()
chunk = _read_chunk(chunk_path)
binary_stdin.write(chunk)
# binary_stdin.flush() # TODO: is this required?
current_time = time.time()
elapsed_time = current_time - start_time
transferred_bytes += len(chunk)
bytes_per_second = round(transferred_bytes / elapsed_time)
print(f'Elapsed time: {datetime.timedelta(seconds=elapsed_time)}\n'
f'Transferred: {DataUnitConverter.to_unit_auto_str(transferred_bytes)}\n'
f'Speed: {DataUnitConverter.to_unit_auto_str(bytes_per_second)}/s')
if last_chunk:
break

View File

@ -21,7 +21,8 @@ def test():
# test10()
# test11()
# test12()
test13()
# test13()
test14()
def test1():
@ -182,6 +183,17 @@ def test13():
print(f'odroid: sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}')
def test14():
ssh_source = 'rootnas'
source_path = '/mnt/data/snap/cloud.privacy1st.de/20221015T1432_u'
source_chunk_dir = '/mnt/data/btrfs-transfer-chunks'
target_path = '/mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u'
print(f'nas: sudo btrfs-send-chunks-passive --chunk-dir={source_chunk_dir} {source_path}')
print(f'odroid: sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}')
def _init(test_number: int):
print(f"TEST {test_number}")
test_dir = Path('test')