[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+
From: |
Eric Wong |
Subject: |
[PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+ |
Date: |
Sat, 17 Jan 2015 11:49:18 +0000 |
This will likely become more available and faster than GNU nproc(1)
over time.
---
bin/dtas-partstats | 12 +++++++++---
1 file 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
--
EW