-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
check_times.py
94 lines (72 loc) · 2.96 KB
/
check_times.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Check the frequency of the rebuild loop.
This must be run in a directory that has the ``docsbuild*`` log files.
For example:
.. code-block:: bash
$ mkdir -p docsbuild-logs
$ scp "[email protected]:/var/log/docsbuild/docsbuild*" docsbuild-logs/
$ python check_times.py
"""
import gzip
import tomllib
from pathlib import Path
from build_docs import format_seconds
LOGS_ROOT = Path("docsbuild-logs").resolve()
def get_lines(filename: str = "docsbuild.log") -> list[str]:
lines = []
zipped_logs = list(LOGS_ROOT.glob(f"{filename}.*.gz"))
zipped_logs.sort(key=lambda p: int(p.name.split(".")[-2]), reverse=True)
for logfile in zipped_logs:
with gzip.open(logfile, "rt", encoding="utf-8") as f:
lines += f.readlines()
with open(LOGS_ROOT / filename, encoding="utf-8") as f:
lines += f.readlines()
return lines
def calc_time(lines: list[str]) -> None:
in_progress = False
in_progress_line = ""
print("Start | Version | Language | Build | Trigger")
print(":-- | :--: | :--: | --: | :--:")
for line in lines:
line = line.strip()
if "Saved new rebuild state for" in line:
_, state = line.split("Saved new rebuild state for", 1)
key, state_toml = state.strip().split(": ", 1)
language, version = key.strip("/").split("/", 1)
state_data = tomllib.loads(f"t = {state_toml}")["t"]
start = state_data["last_build_start"]
fmt_duration = format_seconds(state_data["last_build_duration"])
reason = state_data["triggered_by"]
print(
f"{start:%Y-%m-%d %H:%M UTC} | {version: <7} | {language: <8} | {fmt_duration :<14} | {reason}"
)
if line.endswith("Build start."):
in_progress = True
in_progress_line = line
if in_progress and ": Build done " in line:
in_progress = False
if ": Full build done" in line:
timestamp = f"{line[:16]} UTC"
_, fmt_duration = line.removesuffix(").").split("(")
print(
f"{timestamp: <20} | --FULL- | -BUILD-- | {fmt_duration :<14} | -----------"
)
if in_progress:
start_timestamp = f"{in_progress_line[:16]} UTC"
language, version = in_progress_line.split(" ")[3].removesuffix(":").split("/")
print(
f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | ..."
)
print()
if __name__ == "__main__":
print("Build times (HTML only; English)")
print("=======================")
print()
calc_time(get_lines("docsbuild-only-html-en.log"))
print("Build times (HTML only)")
print("=======================")
print()
calc_time(get_lines("docsbuild-only-html.log"))
print("Build times (no HTML)")
print("=====================")
print()
calc_time(get_lines("docsbuild-no-html.log"))