def _helper(self, node: drgn.Object, offset: int) -> Iterable[drgn.Object]: if node == sdb.get_typed_null(node.type_): return lchild = node.avl_child[0] yield from self._helper(lchild, offset) obj = sdb.create_object("void *", int(node) - offset) yield obj rchild = node.avl_child[1] yield from self._helper(rchild, offset)
def pretty_print(self, metaslabs, indent=0): first_time = True for msp in metaslabs: if not self.args.histogram and not self.args.weight: Metaslab.print_metaslab(msp, first_time, indent) if self.args.histogram: spacemap = msp.ms_sm if spacemap != sdb.get_typed_null(spacemap.type_): histogram = spacemap.sm_phys.smp_histogram print_histogram(histogram, 32, spacemap.sm_shift) if self.args.weight: Metaslab.metaslab_weight_print(msp, first_time, indent) first_time = False
def pretty_print(self, metaslabs: Iterable[drgn.Object], indent: int = 0) -> None: first_time = True for msp in metaslabs: if not self.args.weight: Metaslab.print_metaslab(msp, first_time, indent) if self.args.histogram: spacemap = msp.ms_sm if spacemap != sdb.get_typed_null(spacemap.type_): histogram = spacemap.sm_phys.smp_histogram ZFSHistogram.print_histogram(histogram, int(spacemap.sm_shift), indent + 5) if self.args.weight: Metaslab.metaslab_weight_print(msp, first_time, indent) first_time = False
def print_metaslab(msp: drgn.Object, print_header: bool, indent: int) -> None: spacemap = msp.ms_sm if print_header: print( "".ljust(indent), "ADDR".ljust(18), "ID".rjust(4), "OFFSET".rjust(16), "FREE".rjust(8), "FRAG".rjust(5), "UCMU".rjust(8), ) print("".ljust(indent), "-" * 65) free = msp.ms_size if spacemap != sdb.get_typed_null(spacemap.type_): free -= spacemap.sm_phys.smp_alloc ufrees = msp.ms_unflushed_frees.rt_space uallocs = msp.ms_unflushed_allocs.rt_space free = free + ufrees - uallocs uchanges_free_mem = msp.ms_unflushed_frees.rt_root.bt_num_nodes uchanges_free_mem *= BTREE_LEAF_SIZE uchanges_alloc_mem = msp.ms_unflushed_allocs.rt_root.bt_num_nodes uchanges_alloc_mem *= BTREE_LEAF_SIZE uchanges_mem = uchanges_free_mem + uchanges_alloc_mem print( "".ljust(indent), hex(msp).ljust(16), str(int(msp.ms_id)).rjust(4), hex(msp.ms_start).rjust(16), nicenum(free).rjust(8), end="", ) if msp.ms_fragmentation == -1: print("-".rjust(6), end="") else: print((str(int(msp.ms_fragmentation)) + "%").rjust(6), end="") print(nicenum(uchanges_mem).rjust(9))
def sum_histograms( metaslabs: Iterable[drgn.Object]) -> Tuple[drgn.Object, int]: shift = -1 length = 1 first_time = True histsum: List[int] = [] for msp in metaslabs: if msp.ms_sm == sdb.get_typed_null(msp.ms_sm.type_): continue histogram = msp.ms_sm.sm_phys.smp_histogram if first_time: shift = int(msp.ms_sm.sm_shift) length = len(histogram) histsum = [0] * length assert length == len(histogram) assert shift == int(msp.ms_sm.sm_shift) for (bucket, value) in enumerate(histogram): histsum[bucket] += int(value) first_time = False return sdb.create_object(f'uint64_t[{length}]', histsum), shift