|
17 | 17 | # pylint: disable=missing-docstring |
18 | 18 |
|
19 | 19 | import argparse |
20 | | -from typing import Iterable, List, Tuple, Optional |
| 20 | +from typing import Iterable, List, Optional |
21 | 21 |
|
22 | 22 | import drgn |
23 | 23 | import sdb |
@@ -69,34 +69,9 @@ def __init__(self, |
69 | 69 | if self.args.weight: |
70 | 70 | self.arg_list.append("-w") |
71 | 71 |
|
72 | | - # |
73 | | - # Iterate over the metaslabs to accumulate histogram data. |
74 | | - # |
75 | | - @staticmethod |
76 | | - def sum_histograms( |
77 | | - metaslabs: Iterable[drgn.Object]) -> Tuple[drgn.Object, int]: |
78 | | - shift = -1 |
79 | | - length = 1 |
80 | | - first_time = True |
81 | | - histsum: List[int] = [] |
82 | | - for msp in metaslabs: |
83 | | - if msp.ms_sm == sdb.get_typed_null(msp.ms_sm.type_): |
84 | | - continue |
85 | | - histogram = msp.ms_sm.sm_phys.smp_histogram |
86 | | - if first_time: |
87 | | - shift = int(msp.ms_sm.sm_shift) |
88 | | - length = len(histogram) |
89 | | - histsum = [0] * length |
90 | | - assert length == len(histogram) |
91 | | - assert shift == int(msp.ms_sm.sm_shift) |
92 | | - for (bucket, value) in enumerate(histogram): |
93 | | - histsum[bucket] += int(value) |
94 | | - first_time = False |
95 | | - return sdb.create_object(f'uint64_t[{length}]', histsum), shift |
96 | | - |
97 | | - def pretty_print(self, |
98 | | - vdevs: Iterable[drgn.Object], |
99 | | - indent: int = 0) -> None: |
| 72 | + def print_indented(self, |
| 73 | + vdevs: Iterable[drgn.Object], |
| 74 | + indent: int = 0) -> None: |
100 | 75 | print( |
101 | 76 | "".ljust(indent), |
102 | 77 | "ADDR".ljust(18), |
@@ -133,14 +108,16 @@ def pretty_print(self, |
133 | 108 | vdev.vdev_ops.vdev_op_type.string_().decode("utf-8"), |
134 | 109 | ) |
135 | 110 | if self.args.histogram: |
136 | | - metaslabs = sdb.execute_pipeline([vdev], [Metaslab()]) |
137 | | - histsum, shift = self.sum_histograms(metaslabs) |
138 | | - if shift > 0: |
139 | | - ZFSHistogram.print_histogram(histsum, shift, indent + 5) |
| 111 | + if not sdb.is_null(vdev.vdev_mg): |
| 112 | + ZFSHistogram.print_histogram(vdev.vdev_mg.mg_histogram, 0, |
| 113 | + indent + 5) |
140 | 114 |
|
141 | 115 | if self.args.metaslab: |
142 | 116 | metaslabs = sdb.execute_pipeline([vdev], [Metaslab()]) |
143 | | - Metaslab(self.arg_list).pretty_print(metaslabs, indent + 5) |
| 117 | + Metaslab(self.arg_list).print_indented(metaslabs, indent + 5) |
| 118 | + |
| 119 | + def pretty_print(self, objs: Iterable[drgn.Object]) -> None: |
| 120 | + self.print_indented(objs, 0) |
144 | 121 |
|
145 | 122 | @sdb.InputHandler("spa_t*") |
146 | 123 | def from_spa(self, spa: drgn.Object) -> Iterable[drgn.Object]: |
|
0 commit comments