forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_history.py
executable file
·239 lines (216 loc) · 5.87 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
#!/usr/bin/env python3
import argparse
import bz2
import json
import subprocess
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
import boto3 # type: ignore[import]
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])))
for x in [line.split(" ") for line in rc.split("\n")]
]
def get_ossci_jsons(
*,
bucket: Any,
sha: str,
jobs: Optional[List[str]]
) -> Dict[str, Any]:
prefix = f"test_time/{sha}/"
objs: List[Any]
if jobs is None:
objs = list(bucket.objects.filter(Prefix=prefix))
else:
objs = []
for job in jobs:
objs.extend(list(bucket.objects.filter(Prefix=f"{prefix}{job}/")))
# initial pass to avoid downloading more than necessary
# in the case where there are multiple reports for a single sha+job
uniqueified = {obj.key.split('/')[2]: obj for obj in objs}
return {
job: json.loads(bz2.decompress(obj.get()['Body'].read()))
for job, obj in uniqueified.items()
}
def get_case(
*,
data: Any,
suite_name: str,
test_name: str,
) -> Optional[Dict[str, Any]]:
suite = data.get('suites', {}).get(suite_name)
if suite:
testcase_times = {
case['name']: case
for case in suite['cases']
}
return testcase_times.get(test_name)
return None
def case_status(case: Dict[str, Any]) -> Optional[str]:
for k in {'errored', 'failed', 'skipped'}:
if case[k]:
return k
return None
def make_column(
*,
data: Any,
suite_name: str,
test_name: str,
digits: int,
) -> str:
decimals = 3
num_length = digits + 1 + decimals
case = get_case(data=data, suite_name=suite_name, test_name=test_name)
if case:
status = case_status(case)
if status:
return f'{status.rjust(num_length)} '
else:
return f'{case["seconds"]:{num_length}.{decimals}f}s'
return ' ' * (num_length + 1)
def make_columns(
*,
bucket: Any,
sha: str,
jobs: List[str],
suite_name: str,
test_name: str,
digits: int,
) -> str:
jsons = get_ossci_jsons(bucket=bucket, sha=sha, jobs=jobs)
return ' '.join(
make_column(
data=jsons.get(job, {}),
suite_name=suite_name,
test_name=test_name,
digits=digits,
)
for job in jobs
)
def make_lines(
*,
bucket: Any,
sha: str,
jobs: Optional[List[str]],
suite_name: str,
test_name: str,
) -> List[str]:
jsons = get_ossci_jsons(bucket=bucket, sha=sha, jobs=jobs)
lines = []
for job, data in jsons.items():
case = get_case(data=data, suite_name=suite_name, test_name=test_name)
if case:
status = case_status(case)
lines.append(f'{job} {case["seconds"]} {status or ""}')
return lines
def display_history(
*,
bucket: Any,
commits: List[Tuple[str, datetime]],
jobs: Optional[List[str]],
suite_name: str,
test_name: str,
delta: int,
mode: str,
digits: int,
) -> None:
prev_time = datetime.now()
for sha, time in commits:
if (prev_time - time).total_seconds() < delta * 3600:
continue
prev_time = time
lines: List[str]
if mode == 'columns':
assert jobs is not None
lines = [make_columns(
bucket=bucket,
sha=sha,
jobs=jobs,
suite_name=suite_name,
test_name=test_name,
digits=digits,
)]
else:
assert mode == 'multiline'
lines = make_lines(
bucket=bucket,
sha=sha,
jobs=jobs,
suite_name=suite_name,
test_name=test_name,
)
for line in lines:
print(f"{time} {sha} {line}".rstrip())
if __name__ == "__main__":
parser = argparse.ArgumentParser(
__file__,
description='Display the history of a test.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
'mode',
choices=['columns', 'multiline'],
help='output format',
)
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 rows',
default=12,
)
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(
'suite',
help='name of the suite containing the test',
)
parser.add_argument(
'test',
help='name of the test',
)
parser.add_argument(
'job',
nargs='*',
help='names of jobs to display columns for, in order',
default=[],
)
args = parser.parse_args()
commits = get_git_commit_history(path=args.pytorch, ref=args.ref)
s3 = boto3.resource("s3")
bucket = s3.Bucket('ossci-metrics')
display_history(
bucket=bucket,
commits=commits,
jobs=None if args.all else args.job,
suite_name=args.suite,
test_name=args.test,
delta=args.delta,
mode=args.mode,
digits=args.digits,
)