Fix parse_log.py and parse_log.sh for negative time duration if datetime in log acros...
authorXiaojie Deng <xiaojie.deng@intel.com>
Sat, 31 Dec 2016 12:22:17 +0000 (20:22 +0800)
committerXiaojie Deng <xiaojie.deng@intel.com>
Sat, 31 Dec 2016 12:22:17 +0000 (20:22 +0800)
tools/extra/extract_seconds.py
tools/extra/parse_log.py

index 591a51f..68af69a 100755 (executable)
@@ -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()
index 017306b..b47ffd0 100755 (executable)
@@ -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)