forked from jdanceze/cg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_time_from_log.py
36 lines (29 loc) · 1.26 KB
/
find_time_from_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import re
# path to the directory containing the .log files
log_dir = "/workspace/lifestyle/output_bak"
# regular expression to match the time in the log file
time_regex = r"Total time to construct call graph: (\d+\.\d+) seconds"
# create a list to store the log file names and their corresponding times
log_times = []
# iterate over all files in the directory and its subdirectories
for root, dirs, files in os.walk(log_dir):
for filename in files:
if filename.endswith(".log"):
# read the contents of the log file
log_path = os.path.join(root, filename)
with open(log_path, "r") as f:
log_content = f.read()
# extract the time from the log file using the regular expression
match = re.search(time_regex, log_content)
if match:
time = float(match.group(1))
else:
time = None
# add the log file name and time to the list
file_base = os.path.splitext(filename)[0]
log_times.append((file_base, time))
# save the log file names and times to a text file
with open("/workspace/lifestyle/log_times.txt", "w") as f:
for log_time in log_times:
f.write(f"{log_time[0]}: {log_time[1]}\n")