Skip to content

Commit 34dab01

Browse files
committed
print debug log size
1 parent 0319653 commit 34dab01

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/data_parse.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import cloudpickle
1515
from datetime import timezone, timedelta
1616
import pytz
17-
from src.utils import floor_decimal
17+
from src.utils import floor_decimal, get_unit_and_scale_by_max_file_size_mb
18+
1819

1920
def count_lines(file_name):
2021
if platform.system() in ["Linux", "Darwin"]: # Linux or macOS
@@ -109,9 +110,7 @@ def set_time_zone(self):
109110
if "listening on port" in line:
110111
parts = line.strip().split()
111112
mgr_start_datestring = f"{parts[0]} {parts[1]}"
112-
mgr_start_datestring = datetime.strptime(
113-
mgr_start_datestring, "%Y/%m/%d %H:%M:%S.%f"
114-
).replace(microsecond=0)
113+
mgr_start_datestring = datetime.strptime(mgr_start_datestring, "%Y/%m/%d %H:%M:%S.%f").replace(microsecond=0)
115114
break
116115

117116
# read the first line containing "MANAGER" and "START" in transactions file
@@ -152,8 +151,7 @@ def set_time_zone(self):
152151

153152
@lru_cache(maxsize=4096)
154153
def datestring_to_timestamp(self, datestring):
155-
equivalent_datestring = datetime.strptime(
156-
datestring, "%Y/%m/%d %H:%M:%S.%f").replace(tzinfo=self.manager.equivalent_tz)
154+
equivalent_datestring = datetime.strptime(datestring, "%Y/%m/%d %H:%M:%S.%f").replace(tzinfo=self.manager.equivalent_tz)
157155
unix_timestamp = float(equivalent_datestring.timestamp())
158156
return unix_timestamp
159157

@@ -757,7 +755,10 @@ def parse_debug(self):
757755

758756
self.current_try_id = defaultdict(int)
759757
total_lines = count_lines(self.debug)
758+
debug_file_size_mb = floor_decimal(os.path.getsize(self.debug) / 1024 / 1024, 2)
759+
unit, scale = get_unit_and_scale_by_max_file_size_mb(debug_file_size_mb)
760760

761+
print(f"Debug file size: {floor_decimal(debug_file_size_mb * scale, 2)} {unit}")
761762
with open(self.debug, 'rb') as file:
762763
pbar = tqdm(total=total_lines, desc="Parsing debug")
763764
for raw_line in file:

src/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ def all_subfolders_exists(parent: str, folder_names: list[str]) -> bool:
1212

1313
def floor_decimal(x, decimal_places):
1414
factor = 10 ** decimal_places
15-
return math.floor(x * factor) / factor
15+
return math.floor(x * factor) / factor
16+
17+
def get_unit_and_scale_by_max_file_size_mb(max_file_size_mb) -> tuple[str, float]:
18+
if max_file_size_mb >= 1024 * 1024:
19+
return 'TB', 1 / (1024 * 1024)
20+
elif max_file_size_mb >= 1024:
21+
return 'GB', 1 / 1024
22+
elif max_file_size_mb >= 1:
23+
return 'MB', 1
24+
elif max_file_size_mb >= 1 / 1024:
25+
return 'KB', 1024
26+
else:
27+
return 'Bytes', 1024 * 1024

0 commit comments

Comments
 (0)