diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-20 14:36:51 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-24 13:02:08 -0500 |
commit | 7ee0c579d5c6c2e3f4a70f80e3414a03d3a18cca (patch) | |
tree | 274910d190024ac1f87cf3f3b20d850cebd31968 | |
parent | 9fd9fbb99fe54fda7599c39c014727a157c9ee2a (diff) | |
download | buildstream-7ee0c579d5c6c2e3f4a70f80e3414a03d3a18cca.tar.gz |
_artifactcache.py: Added ArtifactCacheUsage()
A simple object which creates a snapshot of current
usage statistics for easy reporting in the frontend.
-rw-r--r-- | buildstream/_artifactcache.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/buildstream/_artifactcache.py b/buildstream/_artifactcache.py index 725b5fbee..ad58c52cb 100644 --- a/buildstream/_artifactcache.py +++ b/buildstream/_artifactcache.py @@ -46,6 +46,39 @@ class ArtifactCacheSpec(CASRemoteSpec): pass +# ArtifactCacheUsage +# +# A simple object to report the current artifact cache +# usage details. +# +# Note that this uses the user configured cache quota +# rather than the internal quota with protective headroom +# removed, to provide a more sensible value to display to +# the user. +# +# Args: +# artifacts (ArtifactCache): The artifact cache to get the status of +# +class ArtifactCacheUsage(): + + def __init__(self, artifacts): + context = artifacts.context + self.quota_config = context.config_cache_quota # Configured quota + self.quota_size = artifacts._cache_quota_original # Resolved cache quota in bytes + self.used_size = artifacts.get_cache_size() # Size used by artifacts in bytes + self.used_percent = 0 # Percentage of the quota used + if self.quota_size is not None: + self.used_percent = int(self.used_size * 100 / self.quota_size) + + # Formattable into a human readable string + # + def __str__(self): + return "{} / {} ({}%)" \ + .format(utils._pretty_size(self.used_size, dec_places=1), + self.quota_config, + self.used_percent) + + # An ArtifactCache manages artifacts. # # Args: @@ -64,6 +97,7 @@ class ArtifactCache(): self._required_elements = set() # The elements required for this session self._cache_size = None # The current cache size, sometimes it's an estimate self._cache_quota = None # The cache quota + self._cache_quota_original = None # The cache quota as specified by the user, in bytes self._cache_lower_threshold = None # The target cache size for a cleanup self._remotes_setup = False # Check to prevent double-setup of remotes @@ -897,6 +931,7 @@ class ArtifactCache(): # if we end up writing more than 2G, but hey, this stuff is # already really fuzzy. # + self._cache_quota_original = cache_quota self._cache_quota = cache_quota - headroom self._cache_lower_threshold = self._cache_quota / 2 |