Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions sdb/commands/zfs/histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def print_histogram_median(hist: drgn.Object,
offset: int = 0,
indent: int = 0) -> None:
median = ZFSHistogram.histogram_median(hist, offset)
print(f'{" " * indent}Approx. Median: {fmt.size_nicenum(median)}')
if median > 0:
print(f'{" " * indent}Approx. Median: {fmt.size_nicenum(median)}')

@staticmethod
def print_histogram(hist: drgn.Object,
Expand All @@ -135,15 +136,20 @@ def print_histogram(hist: drgn.Object,
if max_count < HISTOGRAM_WIDTH_MAX:
max_count = HISTOGRAM_WIDTH_MAX

if min_bucket <= max_bucket:
print(f'{" " * indent}seg-size count')
print(f'{" " * indent}{"-" * 8} {"-" * 5}')

for bucket in range(min_bucket, max_bucket + 1):
count = int(hist[bucket])
stars = round(count * HISTOGRAM_WIDTH_MAX / max_count)
print(f'{" " * indent}{fmt.size_nicenum(2**(bucket+offset)):>8}: '
f'{count:>6} {"*" * stars}')
if min_bucket > max_bucket:
print(f'{" " * indent}** No histogram data available **')
else:
ZFSHistogram.print_histogram_median(hist, offset, indent)

def _call(self, objs: Iterable[drgn.Object]) -> None:
for obj in objs:
print('seg-size count')
print(f'{"-" * 8} {"-" * 5}')
ZFSHistogram.print_histogram(obj, self.args.offset)
ZFSHistogram.print_histogram_median(obj, self.args.offset)
8 changes: 3 additions & 5 deletions sdb/commands/zfs/metaslab.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def metaslab_weight_print(msp: drgn.Object, print_header: bool,
if msp.ms_fragmentation == -1:
print("-".rjust(6), end="")
else:
print((str(msp.ms_fragmentation) + "%").rjust(5), end="")
print((str(int(msp.ms_fragmentation)) + "%").rjust(5), end="")
print(
str(str(int(msp.ms_allocated_space) >> 20) + "M").rjust(7),
("({0:.1f}%)".format(
Expand Down Expand Up @@ -172,10 +172,8 @@ def pretty_print(self,
if spacemap != sdb.get_typed_null(spacemap.type_):
histogram = spacemap.sm_phys.smp_histogram
ZFSHistogram.print_histogram(histogram,
int(spacemap.sm_shift), indent)
ZFSHistogram.print_histogram_median(histogram,
int(spacemap.sm_shift),
indent)
int(spacemap.sm_shift),
indent + 5)
if self.args.weight:
Metaslab.metaslab_weight_print(msp, first_time, indent)
first_time = False
Expand Down
4 changes: 1 addition & 3 deletions sdb/commands/zfs/spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ def pretty_print(self, spas: Iterable[drgn.Object]) -> None:
if self.args.histogram:
ZFSHistogram.print_histogram(spa.spa_normal_class.mc_histogram,
0, 5)
ZFSHistogram.print_histogram_median(
spa.spa_normal_class.mc_histogram, 0, 5)

if self.args.vdevs:
if self.args.vdevs or self.args.metaslab:
vdevs = sdb.execute_pipeline([spa], [Vdev()])
Vdev(self.arg_list).pretty_print(vdevs, 5)

Expand Down
34 changes: 33 additions & 1 deletion sdb/commands/zfs/vdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
# pylint: disable=missing-docstring

import argparse
from typing import Iterable, List, Optional
from typing import Iterable, List, Tuple, Optional

import drgn
import sdb
from sdb.commands.zfs.internal import enum_lookup
from sdb.commands.zfs.metaslab import Metaslab
from sdb.commands.zfs.histograms import ZFSHistogram


class Vdev(sdb.Locator, sdb.PrettyPrinter):
Expand Down Expand Up @@ -68,6 +69,31 @@ def __init__(self,
if self.args.weight:
self.arg_list.append("-w")

#
# Iterate over the metaslabs to accumulate histogram data.
#
@staticmethod
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

def pretty_print(self,
vdevs: Iterable[drgn.Object],
indent: int = 0) -> None:
Expand Down Expand Up @@ -106,6 +132,12 @@ def pretty_print(self,
"".ljust(level),
vdev.vdev_ops.vdev_op_type.string_().decode("utf-8"),
)
if self.args.histogram:
metaslabs = sdb.execute_pipeline([vdev], [Metaslab()])
histsum, shift = self.sum_histograms(metaslabs)
if shift > 0:
ZFSHistogram.print_histogram(histsum, shift, indent + 5)

if self.args.metaslab:
metaslabs = sdb.execute_pipeline([vdev], [Metaslab()])
Metaslab(self.arg_list).pretty_print(metaslabs, indent + 5)
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/data/regression_output/zfs/spa -H
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ADDR NAME
------------------------------------------------------------
0xffffa0894e720000 data
seg-size count
-------- -----
512.0B: 32 ********************************
1.0KB: 27 ***************************
2.0KB: 32 ********************************
Expand All @@ -23,6 +25,8 @@ ADDR NAME
256.0MB: 15 ***************
Approx. Median: 384.0MB
0xffffa089413b8000 meta-domain
seg-size count
-------- -----
1.0KB: 18 ******************
2.0KB: 24 ************************
4.0KB: 17 *****************
Expand All @@ -43,4 +47,4 @@ ADDR NAME
128.0MB: 4 ****
Approx. Median: 184.0MB
0xffffa08955c44000 rpool
Approx. Median: 0.0B
** No histogram data available **
Loading