From 6ee8d17bf4ae3a1d1371251a359fd35542212892 Mon Sep 17 00:00:00 2001 From: David Cattermole Date: Fri, 21 Jun 2024 22:47:26 +1000 Subject: [PATCH] Image Cache UI - Update real values. --- python/mmSolver/tools/imagecache/lib.py | 86 ++++++++++--- .../tools/imagecache/ui/imagecache_layout.py | 121 ++++++++++++++++++ .../tools/imagecache/ui/imagecache_layout.ui | 32 ++--- 3 files changed, 206 insertions(+), 33 deletions(-) diff --git a/python/mmSolver/tools/imagecache/lib.py b/python/mmSolver/tools/imagecache/lib.py index fb03f6ff..6e2e3864 100644 --- a/python/mmSolver/tools/imagecache/lib.py +++ b/python/mmSolver/tools/imagecache/lib.py @@ -51,7 +51,7 @@ def format_image_sequence_size(image_plane_shp): '2,346.1MB (23.7MB x 102 frames)' """ assert maya.cmds.nodeType(image_plane_shp) == _MM_IMAGE_PLANE_SHAPE_V2 - LOG.info( + LOG.debug( 'format_image_sequence_size: image_plane_shp=%r', image_plane_shp, ) @@ -104,15 +104,13 @@ def format_cache_gpu_used(image_plane_shp): ' 42.1% (3.53GB) of 8.00GB' """ assert maya.cmds.nodeType(image_plane_shp) == _MM_IMAGE_PLANE_SHAPE_V2 - LOG.info( + LOG.debug( 'format_cache_gpu_used: image_plane_shp=%r', image_plane_shp, ) - used_bytes = maya.cmds.mmImageCache(query=True, gpuUsed=True) - capacity_bytes = maya.cmds.mmImageCache(query=True, gpuCapacity=True) - LOG.info('used_bytes: %r', used_bytes) - LOG.info('capacity_bytes: %r', capacity_bytes) + used_bytes = get_gpu_cache_used_bytes() + capacity_bytes = get_gpu_cache_capacity_bytes() return _format_cache_used(int(used_bytes), int(capacity_bytes)) @@ -124,15 +122,13 @@ def format_cache_cpu_used(image_plane_shp): ' 23.1% (34.24 GB) of 240.00 GB' """ assert maya.cmds.nodeType(image_plane_shp) == _MM_IMAGE_PLANE_SHAPE_V2 - LOG.info( + LOG.debug( 'format_cache_cpu_used: image_plane_shp=%r', image_plane_shp, ) - used_bytes = maya.cmds.mmImageCache(query=True, cpuUsed=True) - capacity_bytes = maya.cmds.mmImageCache(query=True, cpuCapacity=True) - LOG.info('used_bytes: %r', used_bytes) - LOG.info('capacity_bytes: %r', capacity_bytes) + used_bytes = get_cpu_cache_used_bytes() + capacity_bytes = get_cpu_cache_capacity_bytes() return _format_cache_used(int(used_bytes), int(capacity_bytes)) @@ -144,12 +140,15 @@ def format_memory_gpu_available(image_plane_shp): 'GPU 8.00 GB' """ assert maya.cmds.nodeType(image_plane_shp) == _MM_IMAGE_PLANE_SHAPE_V2 - LOG.info( + LOG.debug( 'format_memory_available: image_plane_shp=%r', image_plane_shp, ) - memory_gigabytes = maya.cmds.mmMemoryGPU(query=True, total=True, asGigaBytes=True) + memory_bytes = get_gpu_memory_total_bytes() + memory_gigabytes = 0.0 + if memory_bytes > 0: + memory_gigabytes = memory_bytes / _BYTES_TO_GIGABYTES text = 'GPU: {memory_gigabytes:0,.2f} GB' return text.format( @@ -165,14 +164,15 @@ def format_memory_cpu_available(image_plane_shp): 'CPU: 240.00 GB' """ assert maya.cmds.nodeType(image_plane_shp) == _MM_IMAGE_PLANE_SHAPE_V2 - LOG.info( + LOG.debug( 'format_memory_available: image_plane_shp=%r', image_plane_shp, ) - memory_gigabytes = maya.cmds.mmMemorySystem( - query=True, systemPhysicalMemoryTotal=True, asGigaBytes=True - ) + memory_bytes = get_cpu_memory_total_bytes() + memory_gigabytes = 0.0 + if memory_bytes > 0: + memory_gigabytes = memory_bytes / _BYTES_TO_GIGABYTES text = 'CPU: {memory_gigabytes:0,.2f} GB' return text.format( @@ -180,6 +180,58 @@ def format_memory_cpu_available(image_plane_shp): ) +def get_gpu_cache_item_count(): + # TODO: Query the image cache. + return 42 + + +def get_cpu_cache_item_count(): + # TODO: Query the image cache. + return 42 + + +def get_gpu_cache_used_bytes(): + return int(maya.cmds.mmImageCache(query=True, gpuUsed=True)) + + +def get_cpu_cache_used_bytes(): + return int(maya.cmds.mmImageCache(query=True, cpuUsed=True)) + + +def get_gpu_cache_capacity_bytes(): + return int(maya.cmds.mmImageCache(query=True, gpuCapacity=True)) + + +def get_cpu_cache_capacity_bytes(): + return int(maya.cmds.mmImageCache(query=True, cpuCapacity=True)) + + +def get_gpu_memory_total_bytes(): + return int(maya.cmds.mmMemoryGPU(query=True, total=True)) + + +def get_gpu_memory_used_bytes(): + return int(maya.cmds.mmMemoryGPU(query=True, used=True)) + + +def get_cpu_memory_total_bytes(): + return int( + maya.cmds.mmMemorySystem( + query=True, + systemPhysicalMemoryTotal=True, + ) + ) + + +def get_cpu_memory_used_bytes(): + return int( + maya.cmds.mmMemorySystem( + query=True, + systemPhysicalMemoryUsed=True, + ) + ) + + def cache_remove_all_image_plane_slots(cache_type, image_plane_shp): assert cache_type in const.CACHE_TYPE_VALUES assert maya.cmds.nodeType(image_plane_shp) == _MM_IMAGE_PLANE_SHAPE_V2 diff --git a/python/mmSolver/tools/imagecache/ui/imagecache_layout.py b/python/mmSolver/tools/imagecache/ui/imagecache_layout.py index a8a5535d..520c48f0 100644 --- a/python/mmSolver/tools/imagecache/ui/imagecache_layout.py +++ b/python/mmSolver/tools/imagecache/ui/imagecache_layout.py @@ -25,22 +25,132 @@ qtpyutils.override_binding_order() import mmSolver.ui.Qt.QtWidgets as QtWidgets +import mmSolver.ui.Qt.QtCore as QtCore import mmSolver.logger import mmSolver.tools.imagecache.ui.ui_imagecache_layout as ui_imagecache_layout +import mmSolver.tools.imagecache.lib as lib LOG = mmSolver.logger.get_logger() +# Memory Conversion +_BYTES_TO_KILOBYTES = 1024 # int(pow(2, 10)) +_BYTES_TO_MEGABYTES = 1048576 # int(pow(2, 20)) +_BYTES_TO_GIGABYTES = 1073741824 # int(pow(2, 30)) +_KILOBYTES_TO_MEGABYTES = 1024 # int(pow(2, 10)) +_KILOBYTES_TO_GIGABYTES = 1048576 # int(pow(2, 20)) + + +def memoryTotalUpdateUi( + label, + size_bytes, +): + gigabytes = 0.0 + if size_bytes > 0: + gigabytes = size_bytes / _BYTES_TO_GIGABYTES + text = '{:0,.2f} GB'.format(gigabytes) + label.setText(text) + + +def memoryUsedUpdateUi(label, used_size_bytes, total_size_bytes): + used_gigabytes = 0.0 + if used_size_bytes > 0: + used_gigabytes = used_size_bytes / _BYTES_TO_GIGABYTES + + used_percent = 0.0 + if used_size_bytes > 0 and total_size_bytes > 0: + used_percent = (used_size_bytes / total_size_bytes) * 100.0 + text = '{:0,.2f} GB ({:3.1f}%)'.format(used_gigabytes, used_percent) + label.setText(text) + + +def cacheItemCountUpdateUi( + label, + value, +): + text = '{:,}'.format(value) + label.setText(text) + + +def cacheCapacityUpdateUi( + label, + size_bytes, +): + gigabytes = 0.0 + if size_bytes > 0: + gigabytes = size_bytes / _BYTES_TO_GIGABYTES + text = '{:0,.2f} GB'.format(gigabytes) + label.setText(text) + + +def cacheUsedUpdateUi(label, used_size_bytes, capacity_size_bytes): + used_gigabytes = 0.0 + if used_size_bytes > 0: + used_gigabytes = used_size_bytes / _BYTES_TO_GIGABYTES + + used_percent = 0.0 + if used_size_bytes > 0 and capacity_size_bytes > 0: + used_percent = (used_size_bytes / capacity_size_bytes) * 100.0 + text = '{:0,.2f} GB ({:3.1f}%)'.format(used_gigabytes, used_percent) + label.setText(text) + + class ImageCacheLayout(QtWidgets.QWidget, ui_imagecache_layout.Ui_Form): def __init__(self, parent=None, *args, **kwargs): super(ImageCacheLayout, self).__init__(*args, **kwargs) self.setupUi(self) + # Update timer. + self.update_timer = QtCore.QTimer() + seconds = 0.5 + milliseconds = int(seconds * 1000) + self.update_timer.setInterval(milliseconds) + self.update_timer.timeout.connect(self.updateUiValues) + self.update_timer.start() + # Populate the UI with data self.populateUi() + def updateUiValues(self): + LOG.debug('updateUiValues...') + + gpu_cache_item_count = lib.get_gpu_cache_item_count() + cpu_cache_item_count = lib.get_cpu_cache_item_count() + gpu_cache_used = lib.get_gpu_cache_used_bytes() + cpu_cache_used = lib.get_cpu_cache_used_bytes() + gpu_cache_capacity = lib.get_gpu_cache_capacity_bytes() + cpu_cache_capacity = lib.get_cpu_cache_capacity_bytes() + gpu_memory_total = lib.get_gpu_memory_total_bytes() + cpu_memory_total = lib.get_cpu_memory_total_bytes() + gpu_memory_used = lib.get_gpu_memory_used_bytes() + cpu_memory_used = lib.get_cpu_memory_used_bytes() + + memoryTotalUpdateUi(self.gpuMemoryTotalValue_label, gpu_memory_total) + memoryTotalUpdateUi(self.cpuMemoryTotalValue_label, cpu_memory_total) + + memoryUsedUpdateUi( + self.gpuMemoryUsedValue_label, gpu_memory_used, gpu_memory_total + ) + memoryUsedUpdateUi( + self.cpuMemoryUsedValue_label, cpu_memory_used, cpu_memory_total + ) + + cacheItemCountUpdateUi(self.gpuCacheItemCountValue_label, gpu_cache_item_count) + cacheItemCountUpdateUi(self.cpuCacheItemCountValue_label, cpu_cache_item_count) + + cacheCapacityUpdateUi(self.gpuCacheCapacityValue_label, gpu_cache_capacity) + cacheCapacityUpdateUi(self.cpuCacheCapacityValue_label, cpu_cache_capacity) + + cacheUsedUpdateUi( + self.cpuCacheUsedValue_label, cpu_cache_used, cpu_cache_capacity + ) + cacheUsedUpdateUi( + self.gpuCacheUsedValue_label, gpu_cache_used, gpu_cache_capacity + ) + return + def reset_options(self): self.populateUi() @@ -48,4 +158,15 @@ def populateUi(self): """ Update the UI for the first time the class is created. """ + self.updateUiValues() + + # name = const.CONFIG_WIDTH_KEY + # value = configmaya.get_scene_option(name, default=const.DEFAULT_WIDTH) + # LOG.debug('key=%r value=%r', name, value) + # self.width_horizontalSlider.setValue(value) + # self.width_spinBox.setValue(value) + + # self.gpuCacheCapacityGigaBytes_label + # self.gpuCacheCapacity_horizontalSlider + # self.gpuCacheCapacity_doubleSpinBox return diff --git a/python/mmSolver/tools/imagecache/ui/imagecache_layout.ui b/python/mmSolver/tools/imagecache/ui/imagecache_layout.ui index ebc59165..e9c72d77 100644 --- a/python/mmSolver/tools/imagecache/ui/imagecache_layout.ui +++ b/python/mmSolver/tools/imagecache/ui/imagecache_layout.ui @@ -219,9 +219,9 @@ - + - Items: + Item Count: @@ -239,7 +239,7 @@ - + <html><head/><body><p><span style=" font-weight:600;">42</span></p></body></html> @@ -250,9 +250,9 @@ - + - Cache Capacity: + Capacity: @@ -270,7 +270,7 @@ - + <html><head/><body><p><span style=" font-weight:600;">2.0 GB</span></p></body></html> @@ -281,9 +281,9 @@ - + - Cache Used: + Used: @@ -301,7 +301,7 @@ - + <html><head/><body><p><span style=" font-weight:600;">0.125 GB (6.3%)</span></p></body></html> @@ -321,9 +321,9 @@ - + - Items: + Item Count: @@ -341,7 +341,7 @@ - + <html><head/><body><p><span style=" font-weight:600;">42</span></p></body></html> @@ -352,7 +352,7 @@ - + Capacity: @@ -372,7 +372,7 @@ - + <html><head/><body><p><span style=" font-weight:600;">128.0 GB</span></p></body></html> @@ -383,7 +383,7 @@ - + Used: @@ -403,7 +403,7 @@ - + <html><head/><body><p><span style=" font-weight:600;">22.5 GB (17.5%)</span></p></body></html>