Skip to content

Commit 85e6b67

Browse files
authored
Merge pull request #5142 from lvchaxj/master
Fix parse_log tool for negative time duration if datetime across year boundary
2 parents 510249b + 4f0eb52 commit 85e6b67

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

tools/extra/extract_seconds.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@ def extract_seconds(input_file, output_file):
4848
start_datetime = get_start_time(lines, log_created_year)
4949
assert start_datetime, 'Start time not found'
5050

51+
last_dt = start_datetime
5152
out = open(output_file, 'w')
5253
for line in lines:
5354
line = line.strip()
5455
if line.find('Iteration') != -1:
5556
dt = extract_datetime_from_line(line, log_created_year)
57+
58+
# if it's another year
59+
if dt.month < last_dt.month:
60+
log_created_year += 1
61+
dt = extract_datetime_from_line(line, log_created_year)
62+
last_dt = dt
63+
5664
elapsed_seconds = (dt - start_datetime).total_seconds()
5765
out.write('%f\n' % elapsed_seconds)
5866
out.close()

tools/extra/parse_log.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def parse_log(path_to_log):
3838
logfile_year = extract_seconds.get_log_created_year(path_to_log)
3939
with open(path_to_log) as f:
4040
start_time = extract_seconds.get_start_time(f, logfile_year)
41+
last_time = start_time
4142

4243
for line in f:
4344
iteration_match = regex_iteration.search(line)
@@ -55,6 +56,12 @@ def parse_log(path_to_log):
5556
# Skip lines with bad formatting, for example when resuming solver
5657
continue
5758

59+
# if it's another year
60+
if time.month < last_time.month:
61+
logfile_year += 1
62+
time = extract_seconds.extract_datetime_from_line(line, logfile_year)
63+
last_time = time
64+
5865
seconds = (time - start_time).total_seconds()
5966

6067
learning_rate_match = regex_learning_rate.search(line)

0 commit comments

Comments
 (0)