[Notes] [Git][BuildStream/buildstream][tristan/cache-management] 3 commits: _artifactcache.py: Added ArtifactCacheUsage()



Title: GitLab

Tristan Van Berkom pushed to branch tristan/cache-management at BuildStream / buildstream

Commits:

3 changed files:

Changes:

  • buildstream/_artifactcache.py
    ... ... @@ -46,6 +46,30 @@ class ArtifactCacheSpec(CASRemoteSpec):
    46 46
         pass
    
    47 47
     
    
    48 48
     
    
    49
    +# ArtifactCacheUsage
    
    50
    +#
    
    51
    +# A simple object to report the current artifact cache
    
    52
    +# usage details.
    
    53
    +#
    
    54
    +# Note that this uses the user configured cache quota
    
    55
    +# rather than the internal quota with protective headroom
    
    56
    +# removed, to provide a more sensible value to display to
    
    57
    +# the user.
    
    58
    +#
    
    59
    +# Args:
    
    60
    +#    artifacts (ArtifactCache): The artifact cache to get the status of
    
    61
    +#
    
    62
    +class ArtifactCacheUsage():
    
    63
    +
    
    64
    +    def __init__(self, artifacts):
    
    65
    +        context = artifacts.context
    
    66
    +        self.quota_config = context.config_cache_quota       # Configured quota
    
    67
    +        self.quota_size = artifacts._cache_quota_original    # Resolved cache quota in bytes
    
    68
    +        self.used_size = artifacts.get_cache_size()          # Size used by artifacts in bytes
    
    69
    +        self.used_percent = None                             # Percentage of the quota used
    
    70
    +        self.used_percent = int(self.used_size * 100 / self.quota_size)
    
    71
    +
    
    72
    +
    
    49 73
     # An ArtifactCache manages artifacts.
    
    50 74
     #
    
    51 75
     # Args:
    
    ... ... @@ -64,6 +88,7 @@ class ArtifactCache():
    64 88
             self._required_elements = set()       # The elements required for this session
    
    65 89
             self._cache_size = None               # The current cache size, sometimes it's an estimate
    
    66 90
             self._cache_quota = None              # The cache quota
    
    91
    +        self._cache_quota_original = None     # The cache quota as specified by the user, in bytes
    
    67 92
             self._cache_lower_threshold = None    # The target cache size for a cleanup
    
    68 93
             self._remotes_setup = False           # Check to prevent double-setup of remotes
    
    69 94
     
    
    ... ... @@ -897,6 +922,7 @@ class ArtifactCache():
    897 922
             # if we end up writing more than 2G, but hey, this stuff is
    
    898 923
             # already really fuzzy.
    
    899 924
             #
    
    925
    +        self._cache_quota_original = cache_quota
    
    900 926
             self._cache_quota = cache_quota - headroom
    
    901 927
             self._cache_lower_threshold = self._cache_quota / 2
    
    902 928
     
    

  • buildstream/_context.py
    ... ... @@ -30,7 +30,7 @@ from . import _yaml
    30 30
     from ._exceptions import LoadError, LoadErrorReason, BstError
    
    31 31
     from ._message import Message, MessageType
    
    32 32
     from ._profile import Topics, profile_start, profile_end
    
    33
    -from ._artifactcache import ArtifactCache
    
    33
    +from ._artifactcache import ArtifactCache, ArtifactCacheUsage
    
    34 34
     from ._cas import CASCache
    
    35 35
     from ._workspaces import Workspaces, WorkspaceProjectCache, WORKSPACE_PROJECT_FILE
    
    36 36
     from .plugin import _plugin_lookup
    
    ... ... @@ -289,6 +289,16 @@ class Context():
    289 289
     
    
    290 290
             return self._artifactcache
    
    291 291
     
    
    292
    +    # get_artifact_cache_usage()
    
    293
    +    #
    
    294
    +    # Fetches the current usage of the artifact cache
    
    295
    +    #
    
    296
    +    # Returns:
    
    297
    +    #     (ArtifactCacheUsage): The current status
    
    298
    +    #
    
    299
    +    def get_artifact_cache_usage(self):
    
    300
    +        return ArtifactCacheUsage(self.artifactcache)
    
    301
    +
    
    292 302
         # add_project():
    
    293 303
         #
    
    294 304
         # Add a project to the context.
    

  • buildstream/_frontend/widget.py
    ... ... @@ -33,6 +33,7 @@ from .. import __version__ as bst_version
    33 33
     from .._exceptions import ImplError
    
    34 34
     from .._message import MessageType
    
    35 35
     from ..plugin import _plugin_lookup
    
    36
    +from .. import utils
    
    36 37
     
    
    37 38
     
    
    38 39
     # These messages are printed a bit differently
    
    ... ... @@ -449,12 +450,16 @@ class LogLine(Widget):
    449 450
             self._resolved_keys = {element: element._get_cache_key() for element in stream.session_elements}
    
    450 451
     
    
    451 452
             # Main invocation context
    
    453
    +        usage = context.get_artifact_cache_usage()
    
    452 454
             text += '\n'
    
    453 455
             text += self.content_profile.fmt("BuildStream Version {}\n".format(bst_version), bold=True)
    
    454 456
             values = OrderedDict()
    
    455 457
             values["Session Start"] = starttime.strftime('%A, %d-%m-%Y at %H:%M:%S')
    
    456 458
             values["Project"] = "{} ({})".format(project.name, project.directory)
    
    457 459
             values["Targets"] = ", ".join([t.name for t in stream.targets])
    
    460
    +        values["Cache Usage"] = "{} / {} ({}%)".format(
    
    461
    +            utils._pretty_size(usage.used_size, dec_places=1),
    
    462
    +            usage.quota_config, usage.used_percent)
    
    458 463
             text += self._format_values(values)
    
    459 464
     
    
    460 465
             # User configurations
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]