Skip to content

Commit f00b322

Browse files
authored
Merge pull request #262 from delphix/master
Merge branch 'master' into '6.0/stage'
2 parents 28493b2 + db1b967 commit f00b322

19 files changed

+114
-121
lines changed

.github/scripts/install-drgn.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# These are build requirements of "drgn"; if we don't install these, the
55
# build/install of "drgn" will fail below.
66
#
7-
sudo apt-get install bison flex libelf-dev libdw-dev libomp5 libomp-dev
7+
sudo apt update
8+
sudo apt install bison flex libelf-dev libdw-dev libomp5 libomp-dev
89

910
git clone https://github.com/osandov/drgn.git
1011

.github/scripts/install-libkdumpfile.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
# all version of python3.X-dev so the Github actions jobs can install
77
# libkdumpfile with the right version.
88
#
9-
sudo apt-get install autoconf automake liblzo2-dev libsnappy1v5 libtool pkg-config zlib1g-dev
10-
sudo apt-get install python3.6-dev python3.7-dev python3.8-dev
9+
sudo apt update
10+
sudo apt install autoconf automake liblzo2-dev libsnappy1v5 libtool pkg-config zlib1g-dev
11+
sudo apt install python3.6-dev python3.7-dev python3.8-dev
1112

1213
git clone https://github.com/ptesarik/libkdumpfile.git
1314

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ The Slick/Simple Debugger
77

88
Ensure you have the following dependencies:
99
* Python 3.6 or newer
10+
* [libkdumpfile](https://github.com/ptesarik/libkdumpfile) (optional - needed for kdump-compressed crash dumps)
1011
* [drgn](https://github.com/osandov/drgn/)
1112

12-
Then run:
13+
Note that in order for `drgn` to support kdump files it needs to be *compiled* with `libkdumpfile`. Unfortunately that means that users should always install `libkdumpfile` first before installing `drgn`.
14+
15+
Finally run the following to install `sdb`:
1316
```
1417
$ git clone https://github.com/delphix/sdb.git
1518
$ cd sdb
1619
$ sudo python3 setup.py install
1720
```
1821

1922
The above should install `sdb` under `/usr/local/bin/`.
23+
24+
### Resources
25+
26+
User and developer resources for sdb can be found in the [project's wiki](https://github.com/delphix/sdb/wiki).

sdb/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
CommandInvalidInputError, SymbolNotFoundError,
3333
CommandArgumentsError, CommandEvalSyntaxError,
3434
ParserError)
35-
from sdb.target import (create_object, get_object, get_prog, get_typed_null,
36-
get_type, get_pointer_type, get_target_flags,
37-
get_symbol, type_canonical_name, type_canonicalize,
35+
from sdb.target import (create_object, get_object, get_prog, get_type,
36+
get_pointer_type, get_target_flags, get_symbol, is_null,
37+
type_canonical_name, type_canonicalize,
3838
type_canonicalize_name, type_canonicalize_size,
3939
type_equals)
4040
from sdb.command import (Address, Cast, Command, InputHandler, Locator,
@@ -63,6 +63,7 @@
6363
'create_object',
6464
'execute_pipeline',
6565
'invoke',
66+
'is_null',
6667
'get_first_type',
6768
'get_object',
6869
'get_pointer_type',
@@ -71,7 +72,6 @@
7172
'get_symbol',
7273
'get_target_flags',
7374
'get_type',
74-
'get_typed_null',
7575
'type_canonical_name',
7676
'type_canonicalize',
7777
'type_canonicalize_name',

sdb/commands/spl/avl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Avl(sdb.Walker):
2929
input_type = "avl_tree_t *"
3030

3131
def _helper(self, node: drgn.Object, offset: int) -> Iterable[drgn.Object]:
32-
if node == sdb.get_typed_null(node.type_):
32+
if sdb.is_null(node):
3333
return
3434

3535
lchild = node.avl_child[0]

sdb/commands/zfs/dbuf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def ObjsetName(os: drgn.Object) -> str:
8181
os.os_spa.spa_name.string_().decode("utf-8"))
8282
return Dbuf.DatasetName(os.os_dsl_dataset)
8383

84-
def pretty_print(self, dbufs: drgn.Object) -> None:
84+
def pretty_print(self, objs: drgn.Object) -> None:
8585
print("{:>20} {:>8} {:>4} {:>8} {:>5} {}".format(
8686
"addr", "object", "lvl", "blkid", "holds", "os"))
87-
for dbuf in filter(self.argfilter, dbufs):
87+
for dbuf in filter(self.argfilter, objs):
8888
print("{:>20} {:>8d} {:>4d} {:>8d} {:>5d} {}".format(
8989
hex(dbuf), int(dbuf.db.db_object), int(dbuf.db_level),
9090
int(dbuf.db_blkid), int(dbuf.db_holds.rc_count),

sdb/commands/zfs/histograms.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def histogram_median(hist: drgn.Object, offset: int = 0) -> int:
9090
for (bucket, value) in enumerate(hist):
9191
space_in_bucket = int(value) << (bucket + offset)
9292
if space_left <= space_in_bucket:
93-
median = 1 << (bucket + offset)
93+
median = 1 << (bucket + offset - 1)
9494
#
9595
# Size of segments may vary within one bucket thus we
9696
# attempt to approximate the median by looking at the
@@ -136,19 +136,20 @@ def print_histogram(hist: drgn.Object,
136136
if max_count < HISTOGRAM_WIDTH_MAX:
137137
max_count = HISTOGRAM_WIDTH_MAX
138138

139-
if min_bucket <= max_bucket:
140-
print(f'{" " * indent}seg-size count')
141-
print(f'{" " * indent}{"-" * 8} {"-" * 5}')
139+
if min_bucket > max_bucket:
140+
print(f'{" " * indent}** No histogram data available **')
141+
return
142+
143+
print(f'{" " * indent}seg-size count')
144+
print(f'{" " * indent}{"-" * 8} {"-" * 5}')
142145

143146
for bucket in range(min_bucket, max_bucket + 1):
144147
count = int(hist[bucket])
145148
stars = round(count * HISTOGRAM_WIDTH_MAX / max_count)
146149
print(f'{" " * indent}{fmt.size_nicenum(2**(bucket+offset)):>8}: '
147150
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)
151+
152+
ZFSHistogram.print_histogram_median(hist, offset, indent)
152153

153154
def _call(self, objs: Iterable[drgn.Object]) -> None:
154155
for obj in objs:

sdb/commands/zfs/metaslab.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def print_metaslab(msp: drgn.Object, print_header: bool,
133133
print("".ljust(indent), "-" * 65)
134134

135135
free = msp.ms_size
136-
if spacemap != sdb.get_typed_null(spacemap.type_):
136+
if not sdb.is_null(spacemap):
137137
free -= spacemap.sm_phys.smp_alloc
138138

139139
ufrees = msp.ms_unflushed_frees.rt_space
@@ -160,16 +160,16 @@ def print_metaslab(msp: drgn.Object, print_header: bool,
160160
print((str(int(msp.ms_fragmentation)) + "%").rjust(6), end="")
161161
print(nicenum(uchanges_mem).rjust(9))
162162

163-
def pretty_print(self,
164-
metaslabs: Iterable[drgn.Object],
165-
indent: int = 0) -> None:
163+
def print_indented(self,
164+
metaslabs: Iterable[drgn.Object],
165+
indent: int = 0) -> None:
166166
first_time = True
167167
for msp in metaslabs:
168168
if not self.args.weight:
169169
Metaslab.print_metaslab(msp, first_time, indent)
170170
if self.args.histogram:
171171
spacemap = msp.ms_sm
172-
if spacemap != sdb.get_typed_null(spacemap.type_):
172+
if not sdb.is_null(spacemap):
173173
histogram = spacemap.sm_phys.smp_histogram
174174
ZFSHistogram.print_histogram(histogram,
175175
int(spacemap.sm_shift),
@@ -178,6 +178,9 @@ def pretty_print(self,
178178
Metaslab.metaslab_weight_print(msp, first_time, indent)
179179
first_time = False
180180

181+
def pretty_print(self, objs: Iterable[drgn.Object]) -> None:
182+
self.print_indented(objs, 0)
183+
181184
@sdb.InputHandler("vdev_t*")
182185
def from_vdev(self, vdev: drgn.Object) -> Iterable[drgn.Object]:
183186
if self.args.metaslab_ids:

sdb/commands/zfs/spa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def __init__(self,
6565
if self.args.weight:
6666
self.arg_list.append("-w")
6767

68-
def pretty_print(self, spas: Iterable[drgn.Object]) -> None:
68+
def pretty_print(self, objs: Iterable[drgn.Object]) -> None:
6969
print("{:18} {}".format("ADDR", "NAME"))
7070
print("%s" % ("-" * 60))
71-
for spa in spas:
71+
for spa in objs:
7272
print("{:18} {}".format(hex(spa),
7373
spa.spa_name.string_().decode("utf-8")))
7474
if self.args.histogram:
@@ -77,7 +77,7 @@ def pretty_print(self, spas: Iterable[drgn.Object]) -> None:
7777

7878
if self.args.vdevs or self.args.metaslab:
7979
vdevs = sdb.execute_pipeline([spa], [Vdev()])
80-
Vdev(self.arg_list).pretty_print(vdevs, 5)
80+
Vdev(self.arg_list).print_indented(vdevs, 5)
8181

8282
def no_input(self) -> drgn.Object:
8383
spas = sdb.execute_pipeline(

sdb/commands/zfs/vdev.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# pylint: disable=missing-docstring
1818

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

2222
import drgn
2323
import sdb
@@ -69,34 +69,9 @@ def __init__(self,
6969
if self.args.weight:
7070
self.arg_list.append("-w")
7171

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:
10075
print(
10176
"".ljust(indent),
10277
"ADDR".ljust(18),
@@ -133,14 +108,16 @@ def pretty_print(self,
133108
vdev.vdev_ops.vdev_op_type.string_().decode("utf-8"),
134109
)
135110
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)
140114

141115
if self.args.metaslab:
142116
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)
144121

145122
@sdb.InputHandler("spa_t*")
146123
def from_spa(self, spa: drgn.Object) -> Iterable[drgn.Object]:

0 commit comments

Comments
 (0)