summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-01-21 14:22:06 -0500
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-01-24 13:02:08 -0500
commit8074ebf4a704cacfe344d4df58076dd144bef636 (patch)
treeaa00e86b78a97fd09a6dc55e9293bb9ae65c176d
parent5797238b2c1f4e664fffb638f8837c062afd33a5 (diff)
downloadbuildstream-8074ebf4a704cacfe344d4df58076dd144bef636.tar.gz
_artifactcache.py: Add status messages in cache management operations
Added some useful status messages when: * Calculating a new artifact cache usage size * Starting a cleanup * Finishing a cleanup Also enhanced messaging about what was cleaned up so far when aborting a cleanup.
-rw-r--r--buildstream/_artifactcache.py58
1 files changed, 53 insertions, 5 deletions
diff --git a/buildstream/_artifactcache.py b/buildstream/_artifactcache.py
index ad58c52cb..a3365c2d3 100644
--- a/buildstream/_artifactcache.py
+++ b/buildstream/_artifactcache.py
@@ -255,6 +255,25 @@ class ArtifactCache():
#
def clean(self):
artifacts = self.list_artifacts()
+ context = self.context
+
+ # Some accumulative statistics
+ removed_ref_count = 0
+ space_saved = 0
+
+ # Start off with an announcement with as much info as possible
+ volume_size, volume_avail = self._get_cache_volume_size()
+ self._message(MessageType.STATUS, "Starting cache cleanup",
+ detail=("Elements required by the current build plan: {}\n" +
+ "User specified quota: {} ({})\n" +
+ "Cache usage: {}\n" +
+ "Cache volume: {} total, {} available")
+ .format(len(self._required_elements),
+ context.config_cache_quota,
+ utils._pretty_size(self._cache_quota_original, dec_places=2),
+ utils._pretty_size(self.get_cache_size(), dec_places=2),
+ utils._pretty_size(volume_size, dec_places=2),
+ utils._pretty_size(volume_avail, dec_places=2)))
# Build a set of the cache keys which are required
# based on the required elements at cleanup time
@@ -279,11 +298,18 @@ class ArtifactCache():
# can't remove them, we have to abort the build.
#
# FIXME: Asking the user what to do may be neater
+ #
default_conf = os.path.join(os.environ['XDG_CONFIG_HOME'],
'buildstream.conf')
- detail = ("There is not enough space to complete the build.\n"
- "Please increase the cache-quota in {}."
- .format(self.context.config_origin or default_conf))
+ detail = ("Aborted after removing {} refs and saving {} disk space.\n"
+ "The remaining {} in the cache is required by the {} elements in your build plan\n\n"
+ "There is not enough space to complete the build.\n"
+ "Please increase the cache-quota in {} and/or make more disk space."
+ .format(removed_ref_count,
+ utils._pretty_size(space_saved, dec_places=2),
+ utils._pretty_size(self.get_cache_size(), dec_places=2),
+ len(self._required_elements),
+ (context.config_origin or default_conf)))
if self.has_quota_exceeded():
raise ArtifactError("Cache too full. Aborting.",
@@ -298,10 +324,25 @@ class ArtifactCache():
# Remove the actual artifact, if it's not required.
size = self.remove(to_remove)
+ removed_ref_count += 1
+ space_saved += size
+
+ self._message(MessageType.STATUS,
+ "Freed {: <7} {}".format(
+ utils._pretty_size(size, dec_places=2),
+ to_remove))
+
# Remove the size from the removed size
self.set_cache_size(self._cache_size - size)
- # This should be O(1) if implemented correctly
+ # Informational message about the side effects of the cleanup
+ self._message(MessageType.INFO, "Cleanup completed",
+ detail=("Removed {} refs and saving {} disk space.\n" +
+ "Cache usage is now: {}")
+ .format(removed_ref_count,
+ utils._pretty_size(space_saved, dec_places=2),
+ utils._pretty_size(self.get_cache_size(), dec_places=2)))
+
return self.get_cache_size()
# compute_cache_size()
@@ -313,7 +354,14 @@ class ArtifactCache():
# (int): The size of the artifact cache.
#
def compute_cache_size(self):
- self._cache_size = self.cas.calculate_cache_size()
+ old_cache_size = self._cache_size
+ new_cache_size = self.cas.calculate_cache_size()
+
+ if old_cache_size != new_cache_size:
+ self._cache_size = new_cache_size
+
+ usage = ArtifactCacheUsage(self)
+ self._message(MessageType.STATUS, "Cache usage recomputed: {}".format(usage))
return self._cache_size