diff tests/sort_by_time.py @ 83:729738462297 draft

"planemo upload commit c0ffc68aec5836d5b20b543106493056a87edf57"
author rhpvorderman
date Wed, 15 Sep 2021 12:24:06 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sort_by_time.py	Wed Sep 15 12:24:06 2021 +0000
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+"""Small script to profile bash scripts that have been run with the following
+code inside:
+
+    exec 5> debug_output.txt
+    BASH_XTRACEFD="5"
+    PS4='$(date +%s.%N) $LINENO: '
+    set -x
+
+
+"""
+import calendar
+import time
+import sys
+
+import re
+
+SECONDS_FINDER = re.compile(r"^(\d+.\d+).*")
+
+
+def file_to_timestamped_lines(input_file):
+    with open(input_file, "rt") as file_h:
+        for line in file_h:
+            time_since_epoch = float(SECONDS_FINDER.search(line).group(1))
+            yield time_since_epoch, line
+
+
+def time_delta_lines(input_file):
+    timestamped_lines = file_to_timestamped_lines(input_file)
+    current_time, current_line = next(timestamped_lines)
+    for next_time, next_line in timestamped_lines:
+        time_since = next_time - current_time
+        yield time_since, current_line
+        current_time = next_time
+        current_line = next_line
+
+
+if __name__ == "__main__":
+    input_file = sys.argv[1]
+    # Sort by time ascending order.
+    sorted_time = sorted(time_delta_lines(input_file), key=lambda tup: tup[0])
+    for time_since, line in sorted_time:
+        if time_since > 60*60*24*365:
+            # big times are probably nonsensical parsing errors.
+            continue
+        print(time_since, line.strip())