duffy 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb8eb853b9f7031529ff8e262da8326f4fc71717
4
- data.tar.gz: 3870efe3410dda8f56315c70131fd74bee2a9b13
3
+ metadata.gz: 21c3ea1e97e41dfc1f1e3f82e5c35b53d560f96c
4
+ data.tar.gz: 200eab70b8d0017ff974f42b7d95ea1d530d5c9d
5
5
  SHA512:
6
- metadata.gz: e70c4895da1389f502e4720fdb10cf015df66b83c525fa23786126ae1aec20061cfa31af56677dd1ed2069371ca16fd0e8d4ab0a5a031f1030e59e05b3c0a426
7
- data.tar.gz: bc6794238f7fd77396bbd5ae5146ba84a13f152a6d89a506f951ded7c72d0bc35e2f63e5e59edc3d13ddb98aa8bd0c37987637a4e99020ad182ed70f3d5fa834
6
+ metadata.gz: 3559f84b6cb9d4d6bdd222985823ced43d62b25b11087d05dd1657a02cba276ea6f71ba2879d41ab56973bb1f04e3d86f0afc29166286aa6cf6b6d01ee62bbf7
7
+ data.tar.gz: 07aa37fc3a695b5f8179312084ee1b1c4b829f638161226bb7fc322464ecb2a3b20d4515d385a48c9d1b0f8b8ef87e793e71bb0807fe0aaf65dfa45c44b6b6d7
data/README.md CHANGED
@@ -75,7 +75,8 @@ Duffy::Git.branch | Current git branch.
75
75
 
76
76
 
77
77
  ## CPU Detection:
78
- * Linux and Mac only for now, each method returns 1 on unsupported hosts.
78
+ * Linux and Mac only for now, numeric methods return 1 on unsupported hosts.
79
+ * `virtual?` detects if the system is hypervisor guest. Will return false if unable to determine.
79
80
  * Example results for my dual core i5 with hyperthreading.
80
81
 
81
82
  Method | Result
@@ -85,6 +86,7 @@ Duffy::System.cores | 2
85
86
  Duffy::System.threads | 4
86
87
  Duffy::System.sane_load | 3
87
88
  Duffy::System.cpu_percent| 16
89
+ Duffy::System.virtual? | true
88
90
 
89
91
  ## Memory Statistics:
90
92
  * All values returned in Megabytes.
data/lib/duffy/system.rb CHANGED
@@ -21,7 +21,7 @@ module Duffy
21
21
  # Mac: hw.physicalcpu
22
22
  def cores
23
23
  case RUBY_PLATFORM
24
- when /linux/ then File.read('/proc/cpuinfo').scan(/(cpu cores).*(\d+)/)[0][1].to_i * cpus
24
+ when /linux/ then File.read('/proc/cpuinfo').scan(/(cpu cores)(\D)*(\d+)/)[0][2].to_i * cpus
25
25
  when /darwin/ then `sysctl -n hw.physicalcpu`.to_i
26
26
  else 1
27
27
  end
@@ -40,10 +40,20 @@ module Duffy
40
40
  1
41
41
  end
42
42
 
43
+ def virtual?
44
+ case RUBY_PLATFORM
45
+ when /linux/ then !!File.read('/proc/cpuinfo').scan(/^flags.*(hypervisor)/)[0]
46
+ when /darwin/ then false # PENDING
47
+ else false
48
+ end
49
+ rescue
50
+ false
51
+ end
52
+
43
53
  # What is a sane number of threads to use for data processing.
44
- # Only using physical cores is a waste, using all logical cores decreases performance.
54
+ # You want to leave some headroom for your database etc running in other processes.
45
55
  def sane_load
46
- (cores + threads) / 2
56
+ threads * 3 / 4
47
57
  end
48
58
 
49
59
  # The system's current CPU utilization.
data/lib/duffy/version.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Duffy
2
- VERSION = "0.3.4"
2
+ VERSION = '0.3.5'
3
3
  end
4
4
 
5
5
  # History
6
+ # 0.3.5 - Fixed linux cores detection for very high core count CPUs. Added virtualization detection on linux.
6
7
  # 0.3.4 - pretty_phone now adds the dash for 7 digit phone numbers.
7
8
  # 0.3.3 - Added beginning_of_fiscal_year and end_of_fiscal_year methods to Date
8
9
  # 0.3.2 - Added mem_percentage as a convenience and safeguard against div/0 in user code.
data/spec/system_spec.rb CHANGED
@@ -22,7 +22,12 @@ describe Duffy::System do
22
22
  it "returns the total number of threads" do
23
23
  expect(Duffy::System.threads).to be_an(Integer)
24
24
  expect(Duffy::System.threads).to be >= 1
25
+ end
26
+ end
25
27
 
28
+ describe "virtual?" do
29
+ it "returns true if in a hypervisor, false otherwise." do
30
+ expect(Duffy::System.virtual?).to be_in [true, false]
26
31
  end
27
32
  end
28
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-28 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport