about summary refs log tree commit homepage
path: root/bin
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-01-03 03:28:34 +0000
committerEric Wong <e@80x24.org>2015-01-19 09:56:52 +0000
commit5de3064be43ad6f54df33bcb781b064d83bdd8c8 (patch)
treeebdedac9bc17387dd8c388370cb76de2b129be2b /bin
parentfe577e8d5649521954bb9d73f99dca1b35ce384c (diff)
downloaddtas-5de3064be43ad6f54df33bcb781b064d83bdd8c8.tar.gz
This will likely become more available and faster than GNU nproc(1)
over time.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dtas-partstats12
1 files changed, 9 insertions, 3 deletions
diff --git a/bin/dtas-partstats b/bin/dtas-partstats
index 7026b2e..fd9bb0b 100755
--- a/bin/dtas-partstats
+++ b/bin/dtas-partstats
@@ -9,9 +9,15 @@
 require 'dtas/partstats'
 infile = ARGV[0] or abort "usage: #$0 INFILE"
 ps = DTAS::PartStats.new(infile)
-opts = {
-  jobs: `nproc 2>/dev/null || echo 2`.to_i
-}
+
+def nproc
+  require 'etc'
+  Etc.nprocessors
+rescue NoMethodError
+  `nproc 2>/dev/null || echo 2`.to_i
+end
+
+opts = { jobs: nproc }
 stats = ps.run(opts)
 
 headers = ps.key_idx.to_a