MCPcopy Index your code
hub / github.com/saltstack/salt / get_stats

Method get_stats

salt/utils/mmap_cache.py:1562–1612  ·  view source on GitHub ↗

Return statistics about the cache. ``occupied`` and ``deleted`` are read from the header in O(1). ``heap_live_bytes`` is computed by iterating the roster — O(occupied). Keys: ``occupied``, ``deleted``, ``empty``, ``total``, ``load_factor``, ``heap_size_byte

(self)

Source from the content-addressed store, hash-verified

1560 return ret
1561
1562 def get_stats(self):
1563 """
1564 Return statistics about the cache.
1565
1566 ``occupied`` and ``deleted`` are read from the header in O(1).
1567 ``heap_live_bytes`` is computed by iterating the roster — O(occupied).
1568
1569 Keys: ``occupied``, ``deleted``, ``empty``, ``total``,
1570 ``load_factor``, ``heap_size_bytes``, ``heap_live_bytes``.
1571 """
1572 with self._thread_lock:
1573 if not self.open(write=False):
1574 return {
1575 "occupied": 0,
1576 "deleted": 0,
1577 "empty": 0,
1578 "total": self.size - 1,
1579 "load_factor": 0.0,
1580 "heap_size_bytes": 0,
1581 "heap_live_bytes": 0,
1582 }
1583
1584 occupied, deleted, _ = self._read_header()
1585 data_size = self.size - 1
1586 empty = data_size - occupied - deleted
1587
1588 heap_live = 0
1589 for slot in self._roster_read():
1590 if slot == 0 or slot >= self.size:
1591 continue
1592 offset = slot * self.slot_size
1593 if self._mm[offset] == OCCUPIED:
1594 _, length, _ = self._read_slot_pointer(offset)
1595 heap_live += length
1596
1597 try:
1598 heap_size = os.path.getsize(self.heap_path)
1599 except OSError:
1600 heap_size = 0
1601
1602 return {
1603 "occupied": occupied,
1604 "deleted": deleted,
1605 "empty": empty,
1606 "total": data_size,
1607 "load_factor": (
1608 (occupied + deleted) / data_size if data_size > 0 else 0.0
1609 ),
1610 "heap_size_bytes": heap_size,
1611 "heap_live_bytes": heap_live,
1612 }
1613
1614 def atomic_rebuild(self, iterator):
1615 """

Calls 4

openMethod · 0.95
_read_headerMethod · 0.95
_roster_readMethod · 0.95
_read_slot_pointerMethod · 0.95