|
17 | 17 | # pylint: disable=missing-docstring |
18 | 18 |
|
19 | 19 | import argparse |
20 | | -from typing import Iterable, List, Optional |
| 20 | +from typing import Iterable, List, Tuple, Optional |
21 | 21 |
|
22 | 22 | import drgn |
23 | 23 | import sdb |
24 | 24 | from sdb.commands.zfs.internal import enum_lookup |
25 | 25 | from sdb.commands.zfs.metaslab import Metaslab |
| 26 | +from sdb.commands.zfs.histograms import ZFSHistogram |
26 | 27 |
|
27 | 28 |
|
28 | 29 | class Vdev(sdb.Locator, sdb.PrettyPrinter): |
@@ -68,6 +69,31 @@ def __init__(self, |
68 | 69 | if self.args.weight: |
69 | 70 | self.arg_list.append("-w") |
70 | 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 | + |
71 | 97 | def pretty_print(self, |
72 | 98 | vdevs: Iterable[drgn.Object], |
73 | 99 | indent: int = 0) -> None: |
@@ -106,6 +132,12 @@ def pretty_print(self, |
106 | 132 | "".ljust(level), |
107 | 133 | vdev.vdev_ops.vdev_op_type.string_().decode("utf-8"), |
108 | 134 | ) |
| 135 | + 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) |
| 140 | + |
109 | 141 | if self.args.metaslab: |
110 | 142 | metaslabs = sdb.execute_pipeline([vdev], [Metaslab()]) |
111 | 143 | Metaslab(self.arg_list).pretty_print(metaslabs, indent + 5) |
|
0 commit comments