From 4f0eb52a7ecd1bfb2c2d5906d368823eb312693c Mon Sep 17 00:00:00 2001 From: Xiaojie Deng Date: Sat, 31 Dec 2016 20:22:17 +0800 Subject: [PATCH] Fix parse_log.py and parse_log.sh for negative time duration if datetime in log across year boundary --- tools/extra/extract_seconds.py | 8 ++++++++ tools/extra/parse_log.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/tools/extra/extract_seconds.py b/tools/extra/extract_seconds.py index 591a51f96bd..68af69a2788 100755 --- a/tools/extra/extract_seconds.py +++ b/tools/extra/extract_seconds.py @@ -48,11 +48,19 @@ def extract_seconds(input_file, output_file): start_datetime = get_start_time(lines, log_created_year) assert start_datetime, 'Start time not found' + last_dt = start_datetime out = open(output_file, 'w') for line in lines: line = line.strip() if line.find('Iteration') != -1: dt = extract_datetime_from_line(line, log_created_year) + + # if it's another year + if dt.month < last_dt.month: + log_created_year += 1 + dt = extract_datetime_from_line(line, log_created_year) + last_dt = dt + elapsed_seconds = (dt - start_datetime).total_seconds() out.write('%f\n' % elapsed_seconds) out.close() diff --git a/tools/extra/parse_log.py b/tools/extra/parse_log.py index 017306b5088..b47ffd0d842 100755 --- a/tools/extra/parse_log.py +++ b/tools/extra/parse_log.py @@ -38,6 +38,7 @@ def parse_log(path_to_log): logfile_year = extract_seconds.get_log_created_year(path_to_log) with open(path_to_log) as f: start_time = extract_seconds.get_start_time(f, logfile_year) + last_time = start_time for line in f: iteration_match = regex_iteration.search(line) @@ -55,6 +56,12 @@ def parse_log(path_to_log): # Skip lines with bad formatting, for example when resuming solver continue + # if it's another year + if time.month < last_time.month: + logfile_year += 1 + time = extract_seconds.extract_datetime_from_line(line, logfile_year) + last_time = time + seconds = (time - start_time).total_seconds() learning_rate_match = regex_learning_rate.search(line)