From 52ea16a93a4ef75698565a06fe28b191250dc8eb Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Tue, 28 May 2024 14:14:22 +0200 Subject: [PATCH] Update log file size calculation method The code for calculating the size of the log file has been revised. Instead of using os.path.getsize, which simply captures the size of the file on disk, we're now calculating the size of the payload after it has been serialized and encoded, plus an overhead of 100 bytes. This change provides a more accurate measure of the data that will be sent. --- selfdrive/athena/athenad.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index ee47e53bea..8ec1094124 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -583,14 +583,14 @@ def add_log_to_queue(log_path, log_id, is_sunnylink = False): cloudlog.warning(f"Log file {log_path} is empty.") return - # Log the current size of the file - current_size = os.path.getsize(log_path) - cloudlog.info(f"Current size of log file {log_path}: {current_size} bytes") - # Initialize variables for encoding payload = data is_compressed = False + # Log the current size of the file + current_size = len(json.dumps(payload).encode("utf-8")) + len(log_id.encode("utf-8")) + 100 # Add 100 bytes to account for encoding overhead + cloudlog.info(f"Current size of log file {log_path}: {current_size} bytes") + if is_sunnylink and current_size > MAX_SIZE_BYTES: # Compress and encode the data if it exceeds the maximum size compressed_data = gzip.compress(data.encode())