X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/b60166b327a9108b07e3069fa6568a451529ffd9..104ad9766838ec1c572102d6fe0dd689b016b830:/lunaix-os/scripts/gdb/lunadbg/profiling/pmstat.py diff --git a/lunaix-os/scripts/gdb/lunadbg/profiling/pmstat.py b/lunaix-os/scripts/gdb/lunadbg/profiling/pmstat.py index 1e84d87..209a4c5 100644 --- a/lunaix-os/scripts/gdb/lunadbg/profiling/pmstat.py +++ b/lunaix-os/scripts/gdb/lunadbg/profiling/pmstat.py @@ -1,14 +1,18 @@ from ..symbols import LunaixSymbols from ..structs.page import PageStruct +from ..structs.pmem import PMem from ..pp import MyPrettyPrinter import math +ENTER_CONTIG = 0 +LEAVE_CONTIG = 1 + class PhysicalMemProfile: def __init__(self) -> None: super().__init__() - self._pm_list = LunaixSymbols.debug_sym("pmm", "pm_table") + self._pmem = PMem(LunaixSymbols.debug_sym("pmm", "memory").value().address) - self.max_mem_pg = int(LunaixSymbols.debug_sym("pmm", "max_pg").value()) + self.max_mem_pg = self._pmem.list_len() self.max_mem_sz = self.max_mem_pg * 4096 self.mem_distr = [] @@ -16,22 +20,34 @@ class PhysicalMemProfile: self.__mem_distr_granule = distr_granule self.mem_distr.clear() - page_per_granule = self.max_mem_pg / self.__mem_distr_granule - page_per_granule = math.ceil(page_per_granule) + pplist = self._pmem.pplist() + page_per_granule = int(self.max_mem_pg) // self.__mem_distr_granule remainder = self.max_mem_pg % self.__mem_distr_granule bucket = 0 non_contig = 0 - last_contig = False - for i in range(self.max_mem_pg): - element = PageStruct(self._pm_list[i].address) - bucket += int(element.ref > 0) - if last_contig: - last_contig = element.ref > 0 - non_contig += int(not last_contig) - else: - last_contig = element.ref > 0 - - if (i + 1) % page_per_granule == 0: + contig_state = LEAVE_CONTIG + new_state = LEAVE_CONTIG + + i = 0 + while i < self.max_mem_pg: + element = PageStruct(pplist[i].address) + + nr_pgs = 1 + if element.lead_page(): + nr_pgs = 1 << element.order + if element.busy(): + bucket += nr_pgs + new_state = ENTER_CONTIG + else: + new_state = LEAVE_CONTIG + + i += nr_pgs + + if contig_state != new_state: + non_contig += int(new_state == LEAVE_CONTIG) + contig_state = new_state + + if i % page_per_granule == 0: self.mem_distr.append(bucket) bucket = 0