Skip to content

Commit 66b31ca

Browse files
authored
Upload dasm files as artifacts for "asmdiffs pipeline" (#61700)
* Temp change to disable align loop * download specific artifacts to squash: * Upload .dasm files * fix the build id * Add ci_run and retainOnlyTopFiles * Rename ci_run to retainOnlyTop * Disable struct promo to test asmdiff * Revert "Disable struct promo to test asmdiff" This reverts commit 3ef7adb. * fix the parameter retainOnlyTopFiles * add missing - * Revert "Temp change to disable align loop" This reverts commit b1de5c4. * Revert "download specific artifacts" This reverts commit db3de57. * Review comments
1 parent 30550d6 commit 66b31ca

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

eng/pipelines/coreclr/templates/run-superpmi-asmdiffs-job.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ jobs:
111111
targetFolder: '$(SpmiAsmdiffsLocation)'
112112
condition: always()
113113

114+
- task: CopyFiles@2
115+
displayName: Copying dasm files of all partitions
116+
inputs:
117+
sourceFolder: '$(HelixResultLocation)'
118+
contents: '**/Asmdiffs_*.zip'
119+
targetFolder: '$(SpmiAsmdiffsLocation)'
120+
condition: always()
121+
114122
- script: $(PythonScript) $(Build.SourcesDirectory)/src/coreclr/scripts/superpmi_asmdiffs_summarize.py -diff_summary_dir $(SpmiAsmdiffsLocation) -arch $(archType)
115123
displayName: ${{ format('Summarize ({0})', parameters.archType) }}
116124
condition: always()

src/coreclr/scripts/superpmi-asmdiffs.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<HelixWorkItem Include="@(SPMI_Partition)">
6868
<Command>$(WorkItemCommand) -arch %(HelixWorkItem.Architecture) -platform %(HelixWorkItem.Platform)</Command>
6969
<Timeout>$(WorkItemTimeout)</Timeout>
70-
<DownloadFilesFromResults>superpmi_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).log;superpmi_download_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).log;superpmi_diff_summary_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).md</DownloadFilesFromResults>
70+
<DownloadFilesFromResults>superpmi_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).log;superpmi_download_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).log;superpmi_diff_summary_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).md;Asmdiffs_%(HelixWorkItem.Platform)_%(HelixWorkItem.Architecture).zip</DownloadFilesFromResults>
7171
</HelixWorkItem>
7272
</ItemGroup>
7373
</Project>

src/coreclr/scripts/superpmi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
asm_diff_parser.add_argument("-diff_jit_option", action="append", help="Option to pass to the diff JIT. Format is key=value, where key is the option name without leading COMPlus_...")
319319
asm_diff_parser.add_argument("-tag", help="Specify a word to add to the directory name where the asm diffs will be placed")
320320
asm_diff_parser.add_argument("-metrics", action="append", help="Metrics option to pass to jit-analyze. Can be specified multiple times, or pass comma-separated values.")
321+
asm_diff_parser.add_argument("-retainOnlyTopFiles", action="store_true", help="Retain only top .dasm files with largest improvements or regressions and delete remaining files.")
321322

322323
# subparser for upload
323324
upload_parser = subparsers.add_parser("upload", description=upload_description, parents=[core_root_parser, target_parser])
@@ -1628,6 +1629,8 @@ async def create_one_artifact(jit_path: str, location: str, flags) -> str:
16281629
summary_file_info = ( mch_file, md_summary_file )
16291630
all_md_summary_files.append(summary_file_info)
16301631
command = [ jit_analyze_path, "--md", md_summary_file, "-r", "--base", base_asm_location, "--diff", diff_asm_location ]
1632+
if self.coreclr_args.retainOnlyTopFiles:
1633+
command += [ "--retainOnlyTopFiles" ]
16311634
if self.coreclr_args.metrics:
16321635
command += [ "--metrics", ",".join(self.coreclr_args.metrics) ]
16331636
elif base_bytes is not None and diff_bytes is not None:
@@ -3261,6 +3264,11 @@ def verify_replay_common_args():
32613264
lambda unused: True,
32623265
"Unable to set metrics.")
32633266

3267+
coreclr_args.verify(args,
3268+
"retainOnlyTopFiles",
3269+
lambda unused: True,
3270+
"Unable to set retainOnlyTopFiles.")
3271+
32643272
process_base_jit_path_arg(coreclr_args)
32653273

32663274
jit_in_product_location = False

src/coreclr/scripts/superpmi_asmdiffs.py

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
################################################################################
1414

1515
import argparse
16-
import os
16+
from os import walk, path
1717
import shutil
1818
from coreclr_arguments import *
19-
from jitutil import run_command
19+
from jitutil import run_command, TempDir
2020

2121
parser = argparse.ArgumentParser(description="description")
2222

@@ -66,6 +66,54 @@ def setup_args(args):
6666

6767
return coreclr_args
6868

69+
def copy_dasm_files(spmi_location, upload_directory, tag_name):
70+
"""Copies .dasm files to a tempDirectory, zip it, and copy the compressed file to the upload directory.
71+
72+
Args:
73+
spmi_location (string): Location where .dasm files are present
74+
upload_directory (string): Upload directory
75+
tag_name (string): tag_name used in zip file name.
76+
"""
77+
78+
print("Copy .dasm files")
79+
80+
# Create upload_directory
81+
if not os.path.isdir(upload_directory):
82+
os.makedirs(upload_directory)
83+
84+
# Create temp directory to copy all issues to upload. We don't want to create a sub-folder
85+
# inside issues_directory because that will also get included twice.
86+
with TempDir() as prep_directory:
87+
for file_path, dirs, files in walk(spmi_location, topdown=True):
88+
# Credit: https://stackoverflow.com/a/19859907
89+
dirs[:] = [d for d in dirs]
90+
for name in files:
91+
if not name.lower().endswith(".dasm"):
92+
continue
93+
94+
dasm_src_file = path.join(file_path, name)
95+
dasm_dst_file = dasm_src_file.replace(spmi_location, prep_directory)
96+
dst_directory = path.dirname(dasm_dst_file)
97+
if not os.path.exists(dst_directory):
98+
os.makedirs(dst_directory)
99+
try:
100+
shutil.copy2(dasm_src_file, dasm_dst_file)
101+
except PermissionError as pe_error:
102+
print('Ignoring PermissionError: {0}'.format(pe_error))
103+
104+
# Zip compress the files we will upload
105+
zip_path = os.path.join(prep_directory, "Asmdiffs_" + tag_name)
106+
print("Creating archive: " + zip_path)
107+
shutil.make_archive(zip_path, 'zip', prep_directory)
108+
109+
zip_path += ".zip"
110+
dst_zip_path = os.path.join(upload_directory, "Asmdiffs_" + tag_name + ".zip")
111+
print("Copying {} to {}".format(zip_path, dst_zip_path))
112+
try:
113+
shutil.copy2(zip_path, dst_zip_path)
114+
except PermissionError as pe_error:
115+
print('Ignoring PermissionError: {0}'.format(pe_error))
116+
69117

70118
def main(main_args):
71119
""" Run superpmi asmdiffs process on the Helix machines.
@@ -156,7 +204,8 @@ def main(main_args):
156204
"-spmi_location", spmi_location,
157205
"-error_limit", "100",
158206
"-log_level", "debug",
159-
"-log_file", log_file])
207+
"-log_file", log_file,
208+
"-retainOnlyTopFiles"])
160209

161210
# If there are asm diffs, and jit-analyze ran, we'll get a diff_summary.md file in the spmi_location directory.
162211
# We make sure the file doesn't exist before we run diffs, so we don't need to worry about superpmi.py creating
@@ -169,6 +218,8 @@ def main(main_args):
169218
shutil.copy2(overall_md_summary_file, overall_md_summary_file_target)
170219
except PermissionError as pe_error:
171220
print('Ignoring PermissionError: {0}'.format(pe_error))
221+
222+
copy_dasm_files(spmi_location, log_directory, "{}_{}".format(platform_name, arch_name))
172223
else:
173224
# Write a basic summary file. Ideally, we should not generate a summary.md file. However, currently I'm seeing
174225
# errors where the Helix work item fails to upload this specified file if it doesn't exist. We should change the
@@ -178,9 +229,6 @@ def main(main_args):
178229
No diffs found
179230
""")
180231

181-
# TODO: the superpmi.py asmdiffs command returns a failure code if there are MISSING data even if there are
182-
# no asm diffs. We should probably only fail if there are actual failures (not MISSING or asm diffs).
183-
184232
if return_code != 0:
185233
print("Failure in {}".format(log_file))
186234
return 1

0 commit comments

Comments
 (0)