get time elapsed from log files
This commit is contained in:
+44
-2
@@ -26,6 +26,7 @@ _WIN_DRIVE_PATH_RE = re.compile(r"^[A-Za-z]:[\\/]")
|
||||
_SCAN_STATE_LOCK = threading.Lock()
|
||||
_ACTIVE_SCAN_COUNT = 0
|
||||
_DEFAULT_SCAN_EXCLUSIONS = ""
|
||||
_ELAPSED_TIME_LINE_RE = re.compile(r"Elapsed\s+time\s*:\s*(\d+):(\d{1,2}):(\d{1,2}(?:\.\d+)?)", re.IGNORECASE)
|
||||
|
||||
def _parse_scan_exclusions(value):
|
||||
raw = value if value not in (None, "") else _DEFAULT_SCAN_EXCLUSIONS
|
||||
@@ -277,6 +278,45 @@ def _read_text_lines(path):
|
||||
yield line
|
||||
|
||||
|
||||
def _is_candidate_log_file(filename):
|
||||
name = (filename or "").strip().lower()
|
||||
if not name or name == "measurement.db":
|
||||
return False
|
||||
|
||||
if name.endswith(".log") or name.endswith(".txt"):
|
||||
return True
|
||||
|
||||
return "log" in name
|
||||
|
||||
|
||||
def _parse_elapsed_time_to_seconds(line):
|
||||
match = _ELAPSED_TIME_LINE_RE.search(line or "")
|
||||
if not match:
|
||||
return None
|
||||
|
||||
hours = int(match.group(1))
|
||||
minutes = int(match.group(2))
|
||||
seconds = float(match.group(3))
|
||||
return int(hours * 3600 + minutes * 60 + seconds)
|
||||
|
||||
|
||||
def extract_elapsed_seconds_from_logs(result_dir_path, files):
|
||||
elapsed_seconds = None
|
||||
log_files = [name for name in files if _is_candidate_log_file(name)]
|
||||
|
||||
for log_name in log_files:
|
||||
log_path = _join_path(result_dir_path, log_name)
|
||||
try:
|
||||
for line in _read_text_lines(log_path):
|
||||
parsed = _parse_elapsed_time_to_seconds(line)
|
||||
if parsed is not None:
|
||||
elapsed_seconds = parsed
|
||||
except OSError as exc:
|
||||
print(f"[scanner] Cannot read log file {log_path}: {exc}")
|
||||
|
||||
return elapsed_seconds
|
||||
|
||||
|
||||
def scan_results_only(results_dir, results_dir_ref):
|
||||
"""Re-scan only the results directories without clearing or re-scanning targets."""
|
||||
results_dir = _normalize_input_path(results_dir)
|
||||
@@ -444,6 +484,8 @@ def process_result_dir(results_dir, result_dir_name):
|
||||
print(f"[scanner] Cannot read result dir {result_dir_name}: {exc}")
|
||||
return None
|
||||
|
||||
elapsed_seconds = extract_elapsed_seconds_from_logs(result_dir_path, files)
|
||||
|
||||
measurement_db = next((name for name in files if name.lower() == "measurement.db"), None)
|
||||
if not measurement_db:
|
||||
print(f"[scanner] completed (no measurement.db yet): {test_id}")
|
||||
@@ -451,7 +493,7 @@ def process_result_dir(results_dir, result_dir_name):
|
||||
"test_id": test_id,
|
||||
"device": device,
|
||||
"completed_at": None,
|
||||
"duration_seconds": None,
|
||||
"duration_seconds": elapsed_seconds,
|
||||
"tput_results": None,
|
||||
}
|
||||
|
||||
@@ -467,7 +509,7 @@ def process_result_dir(results_dir, result_dir_name):
|
||||
"test_id": test_id,
|
||||
"device": device,
|
||||
"completed_at": completed_at,
|
||||
"duration_seconds": data["duration_seconds"],
|
||||
"duration_seconds": elapsed_seconds,
|
||||
"tput_results": data["tputResults"],
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user