Skip to content

Commit 28493b2

Browse files
author
Prakash Surya
authored
Merge pull request #260 from delphix/master
Merge branch 'master' into '6.0/stage'
2 parents 6dc3f3e + bdd67b8 commit 28493b2

File tree

10 files changed

+1559
-539
lines changed

10 files changed

+1559
-539
lines changed

sdb/commands/zfs/histograms.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def print_histogram_median(hist: drgn.Object,
108108
offset: int = 0,
109109
indent: int = 0) -> None:
110110
median = ZFSHistogram.histogram_median(hist, offset)
111-
print(f'{" " * indent}Approx. Median: {fmt.size_nicenum(median)}')
111+
if median > 0:
112+
print(f'{" " * indent}Approx. Median: {fmt.size_nicenum(median)}')
112113

113114
@staticmethod
114115
def print_histogram(hist: drgn.Object,
@@ -135,15 +136,20 @@ def print_histogram(hist: drgn.Object,
135136
if max_count < HISTOGRAM_WIDTH_MAX:
136137
max_count = HISTOGRAM_WIDTH_MAX
137138

139+
if min_bucket <= max_bucket:
140+
print(f'{" " * indent}seg-size count')
141+
print(f'{" " * indent}{"-" * 8} {"-" * 5}')
142+
138143
for bucket in range(min_bucket, max_bucket + 1):
139144
count = int(hist[bucket])
140145
stars = round(count * HISTOGRAM_WIDTH_MAX / max_count)
141146
print(f'{" " * indent}{fmt.size_nicenum(2**(bucket+offset)):>8}: '
142147
f'{count:>6} {"*" * stars}')
148+
if min_bucket > max_bucket:
149+
print(f'{" " * indent}** No histogram data available **')
150+
else:
151+
ZFSHistogram.print_histogram_median(hist, offset, indent)
143152

144153
def _call(self, objs: Iterable[drgn.Object]) -> None:
145154
for obj in objs:
146-
print('seg-size count')
147-
print(f'{"-" * 8} {"-" * 5}')
148155
ZFSHistogram.print_histogram(obj, self.args.offset)
149-
ZFSHistogram.print_histogram_median(obj, self.args.offset)

sdb/commands/zfs/metaslab.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def metaslab_weight_print(msp: drgn.Object, print_header: bool,
9494
if msp.ms_fragmentation == -1:
9595
print("-".rjust(6), end="")
9696
else:
97-
print((str(msp.ms_fragmentation) + "%").rjust(5), end="")
97+
print((str(int(msp.ms_fragmentation)) + "%").rjust(5), end="")
9898
print(
9999
str(str(int(msp.ms_allocated_space) >> 20) + "M").rjust(7),
100100
("({0:.1f}%)".format(
@@ -172,10 +172,8 @@ def pretty_print(self,
172172
if spacemap != sdb.get_typed_null(spacemap.type_):
173173
histogram = spacemap.sm_phys.smp_histogram
174174
ZFSHistogram.print_histogram(histogram,
175-
int(spacemap.sm_shift), indent)
176-
ZFSHistogram.print_histogram_median(histogram,
177-
int(spacemap.sm_shift),
178-
indent)
175+
int(spacemap.sm_shift),
176+
indent + 5)
179177
if self.args.weight:
180178
Metaslab.metaslab_weight_print(msp, first_time, indent)
181179
first_time = False

sdb/commands/zfs/spa.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ def pretty_print(self, spas: Iterable[drgn.Object]) -> None:
7474
if self.args.histogram:
7575
ZFSHistogram.print_histogram(spa.spa_normal_class.mc_histogram,
7676
0, 5)
77-
ZFSHistogram.print_histogram_median(
78-
spa.spa_normal_class.mc_histogram, 0, 5)
7977

80-
if self.args.vdevs:
78+
if self.args.vdevs or self.args.metaslab:
8179
vdevs = sdb.execute_pipeline([spa], [Vdev()])
8280
Vdev(self.arg_list).pretty_print(vdevs, 5)
8381

sdb/commands/zfs/vdev.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
# pylint: disable=missing-docstring
1818

1919
import argparse
20-
from typing import Iterable, List, Optional
20+
from typing import Iterable, List, Tuple, Optional
2121

2222
import drgn
2323
import sdb
2424
from sdb.commands.zfs.internal import enum_lookup
2525
from sdb.commands.zfs.metaslab import Metaslab
26+
from sdb.commands.zfs.histograms import ZFSHistogram
2627

2728

2829
class Vdev(sdb.Locator, sdb.PrettyPrinter):
@@ -68,6 +69,31 @@ def __init__(self,
6869
if self.args.weight:
6970
self.arg_list.append("-w")
7071

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+
7197
def pretty_print(self,
7298
vdevs: Iterable[drgn.Object],
7399
indent: int = 0) -> None:
@@ -106,6 +132,12 @@ def pretty_print(self,
106132
"".ljust(level),
107133
vdev.vdev_ops.vdev_op_type.string_().decode("utf-8"),
108134
)
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+
109141
if self.args.metaslab:
110142
metaslabs = sdb.execute_pipeline([vdev], [Metaslab()])
111143
Metaslab(self.arg_list).pretty_print(metaslabs, indent + 5)

tests/integration/data/regression_output/zfs/spa -H

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ADDR NAME
22
------------------------------------------------------------
33
0xffffa0894e720000 data
4+
seg-size count
5+
-------- -----
46
512.0B: 32 ********************************
57
1.0KB: 27 ***************************
68
2.0KB: 32 ********************************
@@ -23,6 +25,8 @@ ADDR NAME
2325
256.0MB: 15 ***************
2426
Approx. Median: 384.0MB
2527
0xffffa089413b8000 meta-domain
28+
seg-size count
29+
-------- -----
2630
1.0KB: 18 ******************
2731
2.0KB: 24 ************************
2832
4.0KB: 17 *****************
@@ -43,4 +47,4 @@ ADDR NAME
4347
128.0MB: 4 ****
4448
Approx. Median: 184.0MB
4549
0xffffa08955c44000 rpool
46-
Approx. Median: 0.0B
50+
** No histogram data available **

0 commit comments

Comments
 (0)