Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SPMI space checking calculation #91697

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/coreclr/scripts/jitutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,29 @@ def determine_jit_name(host_os, target_os=None, host_arch=None, target_arch=None
raise RuntimeError("Unknown host OS.")


def get_deepest_existing_directory(path):
""" Given a path, find the deepest existing directory containing it. This
might be the path itself, or a parent directory. If no such directory
is found, None is returned.

Args:
path (str) : path to check

Returns:
As described above
"""
path = os.path.abspath(path)
lastPath = ""

# When os.path.dirname() is called on the root directory ("C:\\" on Windows or "/" on Linux),
# if returns itself.
while not os.path.isdir(path) and path != lastPath:
lastPath = path
path = os.path.dirname(path)

return path if os.path.isdir(path) else None


################################################################################
##
## Azure Storage functions
Expand Down
16 changes: 9 additions & 7 deletions src/coreclr/scripts/superpmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
from jitutil import TempDir, ChangeDir, remove_prefix, is_zero_length_file, is_nonzero_length_file, \
make_safe_filename, find_file, download_one_url, download_files, report_azure_error, \
require_azure_storage_libraries, authenticate_using_azure, \
create_unique_directory_name, create_unique_file_name, get_files_from_path, determine_jit_name
create_unique_directory_name, create_unique_file_name, get_files_from_path, determine_jit_name, \
get_deepest_existing_directory

locale.setlocale(locale.LC_ALL, '') # Use '' for auto, or force e.g. to 'en_US.UTF-8'

Expand Down Expand Up @@ -3199,20 +3200,21 @@ def process_mch_files_arg(coreclr_args):
return [ mch_cache_dir ]

# MCH files can be large. Log the disk space before and after the download.
if os.path.isdir(coreclr_args.spmi_location):
before_total, _, before_free = shutil.disk_usage(coreclr_args.spmi_location)
root_space_directory = get_deepest_existing_directory(coreclr_args.spmi_location)
if root_space_directory is not None:
before_total, _, before_free = shutil.disk_usage(root_space_directory)
before_total_gb = int(before_total / 1024 / 1024 / 1024)
before_free_gb = int(before_free / 1024 / 1024 / 1024)
logging.debug("Disk usage (%s): total %s GB; free %s GB", coreclr_args.spmi_location, format(before_total_gb, ','), format(before_free_gb, ','))
logging.debug("Disk usage (%s): total %s GB; free %s GB", root_space_directory, format(before_total_gb, ','), format(before_free_gb, ','))

local_mch_paths = download_mch_from_azure(coreclr_args, mch_cache_dir)

if os.path.isdir(coreclr_args.spmi_location): # This should always be true here; just being defensive.
after_total, _, after_free = shutil.disk_usage(coreclr_args.spmi_location)
if root_space_directory is not None:
after_total, _, after_free = shutil.disk_usage(root_space_directory)
after_total_gb = int(after_total / 1024 / 1024 / 1024)
after_free_gb = int(after_free / 1024 / 1024 / 1024)
consumed_gb = before_free_gb - after_free_gb
logging.debug("Disk usage (%s): total %s GB; free %s GB; consumed by download %s GB", coreclr_args.spmi_location, format(after_total_gb, ','), format(after_free_gb, ','), format(consumed_gb, ','))
logging.debug("Disk usage (%s): total %s GB; free %s GB; consumed by download %s GB", root_space_directory, format(after_total_gb, ','), format(after_free_gb, ','), format(consumed_gb, ','))

# Add the private store files
if coreclr_args.private_store is not None:
Expand Down