launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #32960
[Merge] ~tushar5526/launchpad-buildd:log-download-speed-in-buildd into launchpad-buildd:master
Tushar Gupta has proposed merging ~tushar5526/launchpad-buildd:log-download-speed-in-buildd into launchpad-buildd:master.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~tushar5526/launchpad-buildd/+git/launchpad-buildd/+merge/492264
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~tushar5526/launchpad-buildd:log-download-speed-in-buildd into launchpad-buildd:master.
diff --git a/lpbuildd/builder.py b/lpbuildd/builder.py
index 857d70c..a236cde 100644
--- a/lpbuildd/builder.py
+++ b/lpbuildd/builder.py
@@ -6,7 +6,6 @@
# The basic builder implementation.
-from datetime import datetime, timezone
import hashlib
import json
import os
@@ -14,6 +13,8 @@ import re
import shutil
import sys
import tempfile
+import time
+from datetime import datetime, timezone
from functools import partial
from urllib.request import (
HTTPBasicAuthHandler,
@@ -165,8 +166,8 @@ class BuildManager:
escaped_args = " ".join(shell_escape(arg) for arg in text_args)
# Log timestamps in the following form: '[Sun Jun 20 23:21:05 1993]'.
- # The day field is two characters long and is space padded if the day is
- # a single digit, e.g.: 'Wed Jun 9 04:26:40 1993'.
+ # The day field is two characters long and is space padded if the day
+ # is a single digit, e.g.: 'Wed Jun 9 04:26:40 1993'.
self._builder.log(
f"[{datetime.now().replace(tzinfo=timezone.utc).ctime()}]\n"
)
@@ -514,9 +515,23 @@ class Builder:
# Upped for great justice to 256k
# coverity[COV_PY_SIGMA.weak_hash_core_python_hashlib:SUPPRESS]
check_sum = hashlib.sha1()
- for chunk in iter(lambda: f.read(256 * 1024), b""):
+
+ total_bytes = 0
+ start_time = time.time()
+ chunk_size = 256 * 1024
+ for chunk in iter(lambda: f.read(chunk_size), b""):
of.write(chunk)
check_sum.update(chunk)
+ total_bytes += len(chunk)
+
+ elapsed = time.time() - start_time
+ if elapsed > 0:
+ total_bytes_in_mb = total_bytes / 1024 / 1024
+ speed = (total_bytes_in_mb) / elapsed
+ self.log(
+ f"Downloaded {total_bytes_in_mb:.2f} MB "
+ f"in {elapsed:.2f}s ({speed:.2f} MB/s)"
+ )
of.close()
f.close()
extra_info = "Download"
Follow ups