Skip to content

Commit 0586bdd

Browse files
committed
fix:execution_time in get_final_stats
1 parent f9a3790 commit 0586bdd

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

st_engine/utils/stats_manager.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import time
99
from typing import Any, Dict, List
1010

11-
from core import GlobalStateManager, TokenStats
11+
from engine.core import GlobalStateManager
1212

1313
from utils.logger import logger
1414

@@ -52,7 +52,29 @@ def get_final_stats(self) -> Dict[str, Any]:
5252
start_time = self.global_state.start_time
5353
end_time = time.time()
5454

55-
execution_time = max(end_time - start_time, 0.001) if start_time else 60.0
55+
# Calculate execution time with fallback strategy
56+
execution_time = 0.0
57+
if start_time:
58+
# Priority 1: Use start_time to calculate actual execution time
59+
execution_time = max(end_time - start_time, 0.001)
60+
else:
61+
# Priority 2: Use task.duration as fallback
62+
try:
63+
duration = self.global_state.config.duration
64+
if duration and duration > 0:
65+
execution_time = float(duration)
66+
else:
67+
# Both start_time and duration are invalid
68+
execution_time = 0.0
69+
self.task_logger.error(
70+
"Failed to calculate execution_time: both start_time and task.duration are invalid"
71+
)
72+
except Exception as e:
73+
# Exception occurred while getting duration
74+
execution_time = 0.0
75+
self.task_logger.error(
76+
f"Failed to calculate execution_time: start_time is invalid and error getting task.duration: {e}"
77+
)
5678

5779
return {
5880
"reqs_count": stats.reqs_count,

0 commit comments

Comments
 (0)