summaryrefslogtreecommitdiff
path: root/perf_tools
diff options
context:
space:
mode:
authorXiaoqin Ma <xiaoqinma@google.com>2022-10-31 21:06:12 +0000
committerXiaoqin Ma <xiaoqinma@google.com>2022-10-31 21:06:12 +0000
commitdc161230305ed673e8f06852801249ca5326f9b0 (patch)
tree644313f365e006b0e052d34bd09f466dd7fdaf88 /perf_tools
parent51cbaa40fab82382a0916bfbc60feabbcbf61a05 (diff)
downloadextras-dc161230305ed673e8f06852801249ca5326f9b0.tar.gz
Report SBT key progress status timing and relative timestamp.
Test: manually. Change-Id: If578cd21b40edbedee2a90f93357242786ed195f
Diffstat (limited to 'perf_tools')
-rw-r--r--perf_tools/progress_report.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/perf_tools/progress_report.py b/perf_tools/progress_report.py
new file mode 100644
index 00000000..9d1d8afc
--- /dev/null
+++ b/perf_tools/progress_report.py
@@ -0,0 +1,78 @@
+import sys
+import os
+from datetime import datetime
+
+#find boot_progress_start line and boot_progress_enable_screen find the time difference
+# return the start time string
+def find_boot_progress_start_end(fp):
+ start = ""
+ end = ""
+ for line in fp:
+ if "boot_progress_start" in line:
+ start = line
+ if "boot_progress_enable_screen" in line and len(start):
+ end = line
+ break
+ return [start, end]
+
+def replace_timestamp_abs(line, timestamp_str, date_time_obj0):
+ if line[:5] != timestamp_str[:5]:
+ return line
+
+ index = line.find(" ", 6)
+ if index <= 0:
+ return line
+ substr0 = line[:index]
+ substr1 = line[index:]
+
+ try:
+ date_time_obj = datetime.strptime(substr0, '%m-%d %H:%M:%S.%f')
+ except ValueError:
+ return line
+
+ date_time_delta = date_time_obj - date_time_obj0
+ date_time_delta_str = str(date_time_delta)
+ return date_time_delta_str + substr1
+
+def in_time_range(start, end, line):
+ try:
+ current_time = datetime.strptime(line[:18], '%m-%d %H:%M:%S.%f')
+ except ValueError:
+ return False
+
+ if current_time >= start and current_time <= end:
+ return True
+
+ return False
+
+def write_to_new_file(fp, output_fp, summary_fp, timestamps):
+ start_timestamp_obj = datetime.strptime(timestamps[0][:18], '%m-%d %H:%M:%S.%f')
+ end_timestamp_obj = datetime.strptime(timestamps[1][:18], '%m-%d %H:%M:%S.%f')
+
+ for line in fp:
+ newline = replace_timestamp_abs(line, timestamps[0][:18], start_timestamp_obj)
+ output_fp.write(newline)
+ if "boot_progress_" in newline and in_time_range(start_timestamp_obj, end_timestamp_obj, line):
+ summary_fp.write(newline)
+
+
+def main():
+ filepath = sys.argv[1]
+ if not os.path.isfile(filepath):
+ print("File path {} does not exist. Exiting...".format(filepath))
+ sys.exit()
+
+ output_fp = open(sys.argv[2], 'w')
+ summary_fp = open(sys.argv[3], 'w')
+
+ with open(filepath, 'r', errors = 'ignore') as fp:
+ timestamps = find_boot_progress_start_end(fp)
+ fp.seek(0)
+ write_to_new_file(fp, output_fp, summary_fp, timestamps)
+
+ fp.close()
+ output_fp.close()
+ summary_fp.close()
+
+if __name__ == '__main__':
+ main()