forked from hofmannol/AlgoDatSoSe25
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
class MemoryManager:
|
|
|
|
instance = None
|
|
|
|
@staticmethod
|
|
def get_instance():
|
|
if MemoryManager.instance is None:
|
|
MemoryManager.instance = MemoryManager()
|
|
return MemoryManager.instance
|
|
|
|
@staticmethod
|
|
def count_cells():
|
|
return len(MemoryManager.get_instance().cells)
|
|
|
|
@staticmethod
|
|
def count_reads():
|
|
return sum([cell.read_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_writes():
|
|
return sum([cell.write_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_compares():
|
|
return sum([cell.compare_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_adds():
|
|
return sum([cell.add_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_subs():
|
|
return sum([cell.sub_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_muls():
|
|
return sum([cell.mul_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_divs():
|
|
return sum([cell.div_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def count_bitops():
|
|
return sum([cell.bitop_count for cell in MemoryManager.get_instance().cells])
|
|
|
|
@staticmethod
|
|
def reset():
|
|
manager = MemoryManager.get_instance()
|
|
for cell in manager.cells:
|
|
cell.reset_counters
|
|
|
|
@staticmethod
|
|
def print_statistics():
|
|
print(f"Anzahl der Speicherzellen: {MemoryManager.count_cells()}")
|
|
print(f"Anzahl der Lesezugriffe: {MemoryManager.count_reads()}")
|
|
print(f"Anzahl der Schreibzugriffe: {MemoryManager.count_writes()}")
|
|
print(f"Anzahl der Vergleiche: {MemoryManager.count_compares()}")
|
|
|
|
def __init__(self):
|
|
self.cells = []
|
|
|
|
def add_cell(self, cell):
|
|
self.cells.append(cell)
|