]> git.proxmox.com Git - mirror_zfs.git/blobdiff - cmd/dbufstat/dbufstat.in
Replace config/config.awk with simple sed invocation
[mirror_zfs.git] / cmd / dbufstat / dbufstat.in
index 98eb7905738861eec8c46e9c76dc5b30de514341..b716a0c9749b0a5df2dacf9c268b6c8fe5336aa1 100755 (executable)
@@ -27,7 +27,7 @@
 # Copyright (C) 2013 Lawrence Livermore National Security, LLC.
 # Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
 #
-# This script must remain compatible with Python 2.6+ and Python 3.4+.
+# This script must remain compatible with and Python 3.6+.
 #
 
 import sys
@@ -113,10 +113,25 @@ cmd = ("Usage: dbufstat [-bdhnrtvx] [-i file] [-f fields] [-o file] "
 raw = 0
 
 
+if sys.platform.startswith("freebsd"):
+    import io
+    # Requires py-sysctl on FreeBSD
+    import sysctl
+
+    def default_ifile():
+        dbufs = sysctl.filter("kstat.zfs.misc.dbufs")[0].value
+        sys.stdin = io.StringIO(dbufs)
+        return "-"
+
+elif sys.platform.startswith("linux"):
+    def default_ifile():
+        return "/proc/spl/kstat/zfs/dbufs"
+
+
 def print_incompat_helper(incompat):
     cnt = 0
     for key in sorted(incompat):
-        if cnt is 0:
+        if cnt == 0:
             sys.stderr.write("\t")
         elif cnt > 8:
             sys.stderr.write(",\n\t")
@@ -645,9 +660,9 @@ def main():
             sys.exit(1)
 
     if not ifile:
-        ifile = '/proc/spl/kstat/zfs/dbufs'
+        ifile = default_ifile()
 
-    if ifile is not "-":
+    if ifile != "-":
         try:
             tmp = open(ifile, "r")
             sys.stdin = tmp