Skip to content

Commit

Permalink
Image Cache UI - Update real values.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cattermole committed Jun 21, 2024
1 parent 0427c2c commit 6ee8d17
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 33 deletions.
86 changes: 69 additions & 17 deletions python/mmSolver/tools/imagecache/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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))


Expand All @@ -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))


Expand All @@ -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(
Expand All @@ -165,21 +164,74 @@ 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(
memory_gigabytes=memory_gigabytes,
)


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
Expand Down
121 changes: 121 additions & 0 deletions python/mmSolver/tools/imagecache/ui/imagecache_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,148 @@
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 = '<b>{:0,.2f} GB</b>'.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 = '<b>{:0,.2f} GB ({:3.1f}%)</b>'.format(used_gigabytes, used_percent)
label.setText(text)


def cacheItemCountUpdateUi(
label,
value,
):
text = '<b>{:,}</b>'.format(value)
label.setText(text)


def cacheCapacityUpdateUi(
label,
size_bytes,
):
gigabytes = 0.0
if size_bytes > 0:
gigabytes = size_bytes / _BYTES_TO_GIGABYTES
text = '<b>{:0,.2f} GB</b>'.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 = '<b>{:0,.2f} GB ({:3.1f}%)</b>'.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()

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
Loading

0 comments on commit 6ee8d17

Please sign in to comment.