5
from pathlib import Path
6
from tempfile import TemporaryDirectory
7
from typing import Any, Dict, List
9
from tools.stats.upload_stats_lib import download_s3_artifacts, unzip, upload_to_rockset
15
ARTIFACT_REGEX = re.compile(
16
r"test-reports-test-(?P<name>\w+)-\d+-\d+-(?P<runner>[\w\.]+)_(?P<job>\d+).zip"
20
def upload_dynamo_perf_stats_to_rockset(
23
workflow_run_attempt: int,
25
) -> List[Dict[str, Any]]:
27
with TemporaryDirectory() as temp_dir:
28
print("Using temporary directory:", temp_dir)
31
for artifact in ARTIFACTS:
32
artifact_paths = download_s3_artifacts(
33
artifact, workflow_run_id, workflow_run_attempt
36
# Unzip to get perf stats csv files
37
for path in artifact_paths:
38
m = ARTIFACT_REGEX.match(str(path))
40
print(f"Test report {path} has an invalid name. Skipping")
43
test_name = m.group("name")
44
runner = m.group("runner")
45
job_id = m.group("job")
50
for csv_file in Path(".").glob("**/*.csv"):
51
filename = os.path.splitext(os.path.basename(csv_file))[0]
52
print(f"Processing {filename} from {path}")
54
with open(csv_file) as csvfile:
55
reader = csv.DictReader(csvfile, delimiter=",")
58
# If the row doesn't have a dev and a name column, it's not
59
# a torch dynamo perf stats csv file
60
if "dev" not in row or "name" not in row:
65
"workflow_id": workflow_run_id, # type: ignore[dict-item]
66
"run_attempt": workflow_run_attempt, # type: ignore[dict-item]
67
"test_name": test_name,
71
"head_branch": head_branch,
74
perf_stats.append(row)
76
# Done processing the file, removing it
82
if __name__ == "__main__":
83
parser = argparse.ArgumentParser(
84
description="Upload dynamo perf stats from S3 to Rockset"
90
help="id of the workflow to get perf stats from",
93
"--workflow-run-attempt",
96
help="which retry of the workflow this is",
102
help="which GitHub repo this workflow run belongs to",
108
help="Head branch of the workflow",
110
args = parser.parse_args()
111
perf_stats = upload_dynamo_perf_stats_to_rockset(
112
args.repo, args.workflow_run_id, args.workflow_run_attempt, args.head_branch
115
collection="torch_dynamo_perf_stats",
117
workspace="inductor",