Skip to content

Commit 0080438

Browse files
authored
Cleanup file progress logs (#309)
1 parent f10c89d commit 0080438

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/ansys/hps/data_transfer/client/api/handler.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def __init__(self):
4747
"""Initializes the WaitHandler class object."""
4848
self.start = time.time()
4949
self.report_threshold = 2.0 # seconds
50-
self.min_progress_interval = 3.0 # seconds
51-
self.last_progress = self.start
50+
self.min_progress_interval = 15.0 # seconds
51+
self.last_progress = {}
52+
self.completed_ids = []
5253

5354
def __call__(self, ops: list[Operation]):
5455
"""Handle operations after they are fetched."""
@@ -60,9 +61,15 @@ def _log_ops(self, ops: list[Operation]) -> str:
6061
for op in ops:
6162
if op.children_detail is not None and self.Meta.expand_group:
6263
for ch in op.children_detail or []:
64+
# For ops with lots of children, avoid logging completed children on every loop iteration
65+
# If there are 29 small files and 1 large file in the group, we dont want to log 29 files
66+
# are done 1000 times while the large file copies.
67+
if ch.id not in self.completed_ids:
68+
self._log_op(logging.DEBUG, ch)
6369
if ch.state not in self.final:
6470
num_running += 1
65-
self._log_op(logging.DEBUG, ch)
71+
elif ch.id not in self.completed_ids:
72+
self.completed_ids.append(ch.id)
6673

6774
if op.state not in self.final:
6875
num_running += 1
@@ -73,7 +80,7 @@ def _log_op(self, lvl: int, op: Operation):
7380
op_type = "operation" if op.children is None or len(op.children) == 0 else "operation group"
7481
op_done = op.state in self.final
7582

76-
msg = f"Data transfer {op_type} '{op.description}'({op.id}) done? {op_done}"
83+
msg = f"Data transfer {op_type} '{op.description}'({op.id}) {'finished. ' if op_done else 'is in progress. '}"
7784

7885
try:
7986
start = op.started_at
@@ -88,17 +95,22 @@ def _log_op(self, lvl: int, op: Operation):
8895
duration = 0
8996
duration_str = "unknown"
9097

98+
# Initialize last progress time if not set, set it back in time
99+
# so it logs right away (report threshold) the first time.
100+
if self.last_progress.get(op.id, None) is None:
101+
self.last_progress[op.id] = time.time() - self.min_progress_interval
102+
91103
state = op.state.value
92104
if op_done:
93-
msg += f" has {state} after {duration_str}"
105+
msg += f"{state.title()} after {duration_str}"
94106
msg += self._info_str(op)
95107
# if op.messages:
96108
# msg += f', messages="{"; ".join(op.messages)}"'
97109
log.log(lvl, msg)
98-
elif duration > self.report_threshold and time.time() - self.last_progress > self.min_progress_interval:
99-
self.last_progress = time.time()
100-
msg += f" is {state}, {duration_str} so far"
101-
if op.progress_current > 0:
110+
elif duration > self.report_threshold and time.time() - self.last_progress[op.id] > self.min_progress_interval:
111+
self.last_progress[op.id] = time.time()
112+
msg += f"{state.title()} for {duration_str}"
113+
if op.progress and op.progress > 0.0:
102114
msg += f", progress {op.progress * 100.0:.1f}%"
103115
msg += self._info_str(op)
104116
log.log(lvl, msg)

0 commit comments

Comments
 (0)