Printing device trees on OpenBSD

I've written a small Perl utility for OpenBSD that takes dmesg output on standard input and produces a human-friendly tree of devices on standard output. Since it accepts any (OpenBSD) dmesg output, you can use it to produce a tree of hardware on someone else's system as well as examine your own.

As an example, this is what it looks like on my Lemote Yeeloong:

$ dmesg | devtree 
root
  |-mainbus0 (Lemote Yeeloong)
  |  |-apm0
  |  |-bonito0 (memory and PCI-X controller, rev 1)
  |  |  |-pci0 (bus 0)
  |  |     |-auglx0 (AMD CS5536 Audio)
  |  |     |  |-audio0
  |  |     |-ehci0 (NEC USB)
  |  |     |  |-usb0 (USB revision 2.0)
  |  |     |     |-uhub0 (NEC EHCI root hub)
  |  |     |-ehci1 (AMD CS5536 USB)
  |  |     |  |-usb1 (USB revision 2.0)
  |  |     |     |-uhub1 (AMD EHCI root hub)
  |  |     |        |-umass0 (Generic USB2.0-CRW)
  |  |     |        |  |-scsibus0 (2 targets, initiator 0)
  |  |     |        |     |-sd0 (Generic-, Multi-Card, 1.00)
  |  |     |        |-urtw0 (Realtek RTL8187B)
  |  |     |-glxpcib0 (AMD CS5536 ISA)
  |  |     |  |-glxclk0 (clock, prof)
  |  |     |  |-gpio1 (32 pins)
  |  |     |  |-iic (not configured)
  |  |     |  |-isa0
  |  |     |     |-mcclock0 (port 0x70/2: mc146818 or compatible)
  |  |     |     |-pckbc0 (port 0x60/5)
  |  |     |     |  |-pckbd0 (kbd slot)
  |  |     |     |  |  |-wskbd0 (console keyboard, using wsdisplay0)
  |  |     |     |  |-pms0 (aux slot)
  |  |     |     |     |-wsmouse0 (mux 0)
  |  |     |     |-ykbec0 (port 0x381/3)
  |  |     |-ohci0 (NEC USB)
  |  |     |  |-usb2 (USB revision 1.0)
  |  |     |     |-uhub2 (NEC OHCI root hub)
  |  |     |-ohci1 (AMD CS5536 USB)
  |  |     |  |-usb3 (USB revision 1.0)
  |  |     |     |-uhub3 (AMD OHCI root hub)
  |  |     |-pciide0 (AMD CS5536 IDE)
  |  |     |  |-wd0 (Corsair Force 3 SSD)
  |  |     |-rl0 (Realtek 8139)
  |  |     |  |-rlphy0 (phy 0: RTL internal PHY)
  |  |     |-smfb0 (Silicon Motion LynxEM+)
  |  |        |-wsdisplay0 (std, vt100 emulation)
  |  |-cpu0 (STC Loongson2F CPU 796 MHz, STC Loongson2F FPU)
  |-softraid0
  |  |-scsibus2 (256 targets)
  |-vscsi0
     |-scsibus1 (256 targets)

Source and a man page are available under the WTFPL from git://git.sjm.so/openbsd-goodies.git (or view it on GitWeb) .