forked from csarofeen/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_history.py
executable file
·330 lines (293 loc) · 10.5 KB
/
test_history.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/env python3
import argparse
import subprocess
import sys
from datetime import datetime, timezone
from signal import SIG_DFL, signal, SIGPIPE
from typing import Dict, Iterator, List, Optional, Set, Tuple
from tools.stats.s3_stat_parser import get_cases, get_test_stats_summaries, Report
def get_git_commit_history(*, path: str, ref: str) -> List[Tuple[str, datetime]]:
rc = subprocess.check_output(
["git", "-C", path, "log", "--pretty=format:%H %ct", ref],
).decode("latin-1")
return [
(x[0], datetime.fromtimestamp(int(x[1]), tz=timezone.utc))
for x in [line.split(" ") for line in rc.split("\n")]
]
def make_column(
*,
data: Optional[Report],
filename: Optional[str],
suite_name: Optional[str],
test_name: str,
digits: int,
) -> Tuple[str, int]:
decimals = 3
num_length = digits + 1 + decimals
if data:
cases = get_cases(
data=data, filename=filename, suite_name=suite_name, test_name=test_name
)
if cases:
case = cases[0]
status = case["status"]
omitted = len(cases) - 1
if status:
return f"{status.rjust(num_length)} ", omitted
else:
return f'{case["seconds"]:{num_length}.{decimals}f}s', omitted
else:
return f'{"absent".rjust(num_length)} ', 0
else:
return " " * (num_length + 1), 0
def make_columns(
*,
jobs: List[str],
jsons: Dict[str, Report],
omitted: Dict[str, int],
filename: Optional[str],
suite_name: Optional[str],
test_name: str,
digits: int,
) -> str:
columns = []
total_omitted = 0
total_suites = 0
for job in jobs:
data = jsons.get(job)
column, omitted_suites = make_column(
data=data,
filename=filename,
suite_name=suite_name,
test_name=test_name,
digits=digits,
)
columns.append(column)
total_suites += omitted_suites
if job in omitted:
total_omitted += omitted[job]
if total_omitted > 0:
columns.append(f"({total_omitted} job re-runs omitted)")
if total_suites > 0:
columns.append(f"({total_suites} matching suites omitted)")
return " ".join(columns)
def make_lines(
*,
jobs: Set[str],
jsons: Dict[str, List[Report]],
filename: Optional[str],
suite_name: Optional[str],
test_name: str,
) -> List[str]:
lines = []
for job, reports in jsons.items():
for data in reports:
cases = get_cases(
data=data,
filename=filename,
suite_name=suite_name,
test_name=test_name,
)
if cases:
case = cases[0]
status = case["status"]
line = f'{job} {case["seconds"]}s{f" {status}" if status else ""}'
if len(cases) > 1:
line += f" ({len(cases) - 1} matching suites omitted)"
lines.append(line)
elif job in jobs:
lines.append(f"{job} (test not found)")
if lines:
return lines
else:
return ["(no reports in S3)"]
def history_lines(
*,
commits: List[Tuple[str, datetime]],
jobs: Optional[List[str]],
filename: Optional[str],
suite_name: Optional[str],
test_name: str,
delta: int,
sha_length: int,
mode: str,
digits: int,
) -> Iterator[str]:
prev_time = datetime.now(tz=timezone.utc)
for sha, time in commits:
if (prev_time - time).total_seconds() < delta * 3600:
continue
prev_time = time
if jobs is None:
summaries = get_test_stats_summaries(sha=sha)
else:
summaries = get_test_stats_summaries(sha=sha, jobs=jobs)
if mode == "columns":
assert jobs is not None
# we assume that get_test_stats_summaries here doesn't
# return empty lists
omitted = {job: len(l) - 1 for job, l in summaries.items() if len(l) > 1}
lines = [
make_columns(
jobs=jobs,
jsons={job: l[0] for job, l in summaries.items()},
omitted=omitted,
filename=filename,
suite_name=suite_name,
test_name=test_name,
digits=digits,
)
]
else:
assert mode == "multiline"
lines = make_lines(
jobs=set(jobs or []),
jsons=summaries,
filename=filename,
suite_name=suite_name,
test_name=test_name,
)
for line in lines:
yield f"{time:%Y-%m-%d %H:%M:%S}Z {sha[:sha_length]} {line}".rstrip()
class HelpFormatter(
argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter,
):
pass
def description() -> str:
return r"""
Display the history of a test.
Each line of (non-error) output starts with the timestamp and SHA1 hash
of the commit it refers to, in this format:
YYYY-MM-DD hh:mm:ss 0123456789abcdef0123456789abcdef01234567
In multiline mode, each line next includes the name of a CircleCI job,
followed by the time of the specified test in that job at that commit.
Example:
$ tools/stats/test_history.py --mode=multiline --ref=86a961af879 --sha-length=8 \
--test=test_composite_compliance_dot_cpu_float32 \
--job linux-xenial-py3.7-gcc5.4-test-default1 --job linux-xenial-py3.7-gcc7-test-default1
2022-02-18 15:47:37Z 86a961af linux-xenial-py3.7-gcc5.4-test-default1 0.001s
2022-02-18 15:47:37Z 86a961af linux-xenial-py3.7-gcc7-test-default1 0.001s
2022-02-18 15:12:34Z f5e201e4 linux-xenial-py3.7-gcc5.4-test-default1 0.001s
2022-02-18 15:12:34Z f5e201e4 linux-xenial-py3.7-gcc7-test-default1 0.001s
2022-02-18 13:14:56Z 1c0df265 linux-xenial-py3.7-gcc5.4-test-default1 0.001s
2022-02-18 13:14:56Z 1c0df265 linux-xenial-py3.7-gcc7-test-default1 0.001s
2022-02-18 13:14:56Z e73eaffd (no reports in S3)
2022-02-18 06:29:12Z 710f12f5 linux-xenial-py3.7-gcc5.4-test-default1 0.001s
Another multiline example, this time with the --all flag:
$ tools/stats/test_history.py --mode=multiline --all --ref=86a961af879 --delta=12 --sha-length=8 \
--test=test_composite_compliance_dot_cuda_float32
2022-02-18 03:49:46Z 69389fb5 linux-bionic-cuda10.2-py3.9-gcc7-test-default1 0.001s skipped
2022-02-18 03:49:46Z 69389fb5 linux-bionic-cuda10.2-py3.9-gcc7-test-slow1 0.001s skipped
2022-02-18 03:49:46Z 69389fb5 linux-xenial-cuda11.3-py3.7-gcc7-test-default1 0.001s skipped
2022-02-18 03:49:46Z 69389fb5 periodic-linux-bionic-cuda11.5-py3.7-gcc7-test-default1 0.001s skipped
2022-02-18 03:49:46Z 69389fb5 periodic-linux-xenial-cuda10.2-py3-gcc7-slow-gradcheck-test-default1 0.001s skipped
2022-02-18 03:49:46Z 69389fb5 periodic-linux-xenial-cuda11.1-py3.7-gcc7-debug-test-default1 0.001s skipped
In columns mode, the name of the job isn't printed, but the order of the
columns is guaranteed to match the order of the jobs passed on the
command line. Example:
$ tools/stats/test_history.py --mode=columns --ref=86a961af879 --sha-length=8 \
--test=test_composite_compliance_dot_cpu_float32 \
--job linux-xenial-py3.7-gcc5.4-test-default1 --job linux-xenial-py3.7-gcc7-test-default1
2022-02-18 15:47:37Z 86a961af 0.001s 0.001s
2022-02-18 15:12:34Z f5e201e4 0.001s 0.001s
2022-02-18 13:14:56Z 1c0df265 0.001s 0.001s
2022-02-18 13:14:56Z e73eaffd
2022-02-18 06:29:12Z 710f12f5 0.001s 0.001s
2022-02-18 05:20:30Z 51b04f27 0.001s 0.001s
2022-02-18 03:49:46Z 69389fb5 0.001s 0.001s
2022-02-18 00:19:12Z 056b6260 0.001s 0.001s
2022-02-17 23:58:32Z 39fb7714 0.001s 0.001s
Minor note: in columns mode, a blank cell means that no report was found
in S3, while the word "absent" means that a report was found but the
indicated test was not found in that report.
"""
def parse_args(raw: List[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(
__file__,
description=description(),
formatter_class=HelpFormatter,
)
parser.add_argument(
"--mode",
choices=["columns", "multiline"],
help="output format",
default="columns",
)
parser.add_argument(
"--pytorch",
help="path to local PyTorch clone",
default=".",
)
parser.add_argument(
"--ref",
help="starting point (most recent Git ref) to display history for",
default="master",
)
parser.add_argument(
"--delta",
type=int,
help="minimum number of hours between commits",
default=0,
)
parser.add_argument(
"--sha-length",
type=int,
help="length of the prefix of the SHA1 hash to show",
default=40,
)
parser.add_argument(
"--digits",
type=int,
help="(columns) number of digits to display before the decimal point",
default=4,
)
parser.add_argument(
"--all",
action="store_true",
help="(multiline) ignore listed jobs, show all jobs for each commit",
)
parser.add_argument(
"--file",
help="name of the file containing the test",
)
parser.add_argument(
"--suite",
help="name of the suite containing the test",
)
parser.add_argument("--test", help="name of the test", required=True)
parser.add_argument(
"--job",
help="names of jobs to display columns for, in order",
action="append",
default=[],
)
args = parser.parse_args(raw)
args.jobs = None if args.all else args.job
# We dont allow implicit or empty "--jobs", unless "--all" is specified.
if args.jobs == []:
parser.error("No jobs specified.")
return args
def run(raw: List[str]) -> Iterator[str]:
args = parse_args(raw)
commits = get_git_commit_history(path=args.pytorch, ref=args.ref)
return history_lines(
commits=commits,
jobs=args.jobs,
filename=args.file,
suite_name=args.suite,
test_name=args.test,
delta=args.delta,
mode=args.mode,
sha_length=args.sha_length,
digits=args.digits,
)
def main() -> None:
for line in run(sys.argv[1:]):
print(line, flush=True)
if __name__ == "__main__":
signal(SIGPIPE, SIG_DFL) # https://stackoverflow.com/a/30091579
try:
main()
except KeyboardInterrupt:
pass