probench 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02c4b5040ba91ead72766e60a65c1cf32ae880d8
4
+ data.tar.gz: a68d83f6ef4ab6eb4e400afd4edca45935d6db8a
5
+ SHA512:
6
+ metadata.gz: 34ab0f7b00be60ec93f09e70a2044b5d3492c8557e719a721bf343a2360f9dae9813aa10a3019e212469133df9a8a7cac7f0c90cbe554c7da02682c229d5b8a5
7
+ data.tar.gz: 75f53a83398fa7afa92f87d481f81b1d3d5fc42c72e1e445d92e2f3918e6351df738b18d8a605c34d991a558ac9d739e24074bd5174b0e624bd575e8689d830b
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ /.bundle/
2
+ .idea/
3
+ .vagrant/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
17
+ *.swp
18
+ *.gem
19
+ pkg
20
+ Gemfile.lock
21
+ .vscode/
22
+ .vagrant/
data/CHANGELOG ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 Alex Karasulu
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/Readme.md ADDED
@@ -0,0 +1,15 @@
1
+ # What is it?
2
+
3
+ Hardware probing and benchmarking tools for Subutai. Lightweight and does not
4
+ force people to wait too long. The generate json file is used to understand
5
+ the underlying hardware for pricing.
6
+
7
+ # Today and Tomorrow
8
+
9
+ Right now this is a Ruby GEM but it should also have a python version for use
10
+ separately. The Ruby GEM is for using it with edge peers based on our vagrant
11
+ virtual machine images.
12
+
13
+ The future Python library might be used for ansible provisioning scripts to
14
+ provision hosting provider and cloud provider based peers.
15
+
data/bin/probench ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'probench'
4
+ Probench.cli
data/build.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ rm *.gem
4
+ gem uninstall probench
5
+
6
+ gem build probench.gemspec
7
+
8
+ gem install ./*.gem
data/lib/common.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'typesafe_enum'
2
+
3
+ class HardwareCategory < TypesafeEnum::Base
4
+
5
+ new :MEMORY
6
+ new :NETWORK
7
+ new :PROCESSORS
8
+ new :STORAGE
9
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'common.rb'
2
+
3
+ # converts lscpu output into hash
4
+ def lscpu
5
+ hash = {}
6
+ IO.popen('lscpu') do |io|
7
+ while (line = io.gets)
8
+ key = line.split(':')[0]
9
+ key = key.strip unless key.nil?
10
+ val = line.split(':')[1]
11
+ val = val.strip unless val.nil?
12
+ hash[key] = val unless key.nil? || val.nil?
13
+ end
14
+ end
15
+ hash
16
+ end
17
+
18
+ # converts /proc/cpuinfo into a hash
19
+ def cpuinfo
20
+ hash = {}
21
+ IO.popen('cat /proc/cpuinfo') do |io|
22
+ while (line = io.gets)
23
+ key = line.split(':')[0]
24
+ key = key.strip unless key.nil?
25
+ val = line.split(':')[1]
26
+ val = val.strip unless val.nil?
27
+ hash[key] = val unless key.nil? || val.nil?
28
+ end
29
+ end
30
+ hash
31
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'common.rb'
2
+
3
+ # convert output of sysctl to a hash
4
+ # noprefix to false to not remove key prefixes i.e. machdep.cpu etc
5
+ def sysctl(category, noprefix = true)
6
+ raise ArgumentError unless category.is_a?(HardwareCategory)
7
+
8
+ cmd = 'sysctl -a'
9
+ prefixes = []
10
+ # noinspection RubyResolve
11
+ case category
12
+ when HardwareCategory::PROCESSORS
13
+ cmd += " | egrep '(hw|cpu)'"
14
+ prefixes = %w[machdep.cpu. hw.]
15
+ when HardwareCategory::MEMORY
16
+ cmd += ' | grep machdep.mem'
17
+ prefixes = ['machdep.mem.']
18
+ else
19
+ puts 'none of the above'
20
+ end
21
+
22
+ hash = {}
23
+ IO.popen(cmd) do |io|
24
+ while (line = io.gets)
25
+ key = line.split(':')[0]
26
+ key = key.strip unless key.nil?
27
+ next if key.nil?
28
+
29
+ if noprefix && !key.nil?
30
+ prefixes.each do |prefix|
31
+ # noinspection RubyNilAnalysis
32
+ key = key[prefix.length..-1] if key.start_with?(prefix) && noprefix
33
+ end
34
+ end
35
+
36
+ val = line.split(':')[1]
37
+ val = val.strip unless val.nil?
38
+ hash[key] = val unless key.nil? || val.nil?
39
+ end
40
+ end
41
+ hash
42
+ end
data/lib/memory.rb ADDED
@@ -0,0 +1,122 @@
1
+ require 'rbconfig'
2
+ require 'yaml'
3
+ require 'highline/import'
4
+
5
+ # Base and factory for memory probes
6
+ class SystemMemory
7
+ UNLIMITED = -1
8
+
9
+ attr_accessor :speed # int in MegaHertz
10
+ attr_accessor :size # int in GigaBytes
11
+ attr_accessor :type # string DDR type
12
+ attr_accessor :is_ecc # boolean true if ECC memory and enabled
13
+ attr_accessor :swap_size # size of the swap if any in GigaBytes
14
+
15
+ def self.probe
16
+ case RbConfig::CONFIG['host_os']
17
+ when /linux/
18
+ LinuxSystemMemory.new
19
+ when /darwin/
20
+ MacSystemMemory.new
21
+ when /cygwin|mswin|mingw32|mingw|bccwin|wince|emx/
22
+ WindowsSystemMemory.new
23
+ else
24
+ RbConfig::CONFIG['host_os']
25
+ end
26
+ end
27
+ end
28
+
29
+ # Memory probe for Linux
30
+ class LinuxSystemMemory < SystemMemory
31
+ def initialize
32
+ if `which lshw | wc -l | tr -d '[:space:]'` == '0'
33
+ input = ask 'lshw is not installed, would you like to install it (y/n)?'
34
+ if input == 'y'
35
+ puts `sudo apt-get install -y lshw`
36
+ else
37
+ puts 'Cannot proceed without lshw executable, aborting.'
38
+ exit 1
39
+ end
40
+ end
41
+
42
+ cmd = "sudo lshw -c memory -short | grep 'System Memory' | " \
43
+ "sed -e 's/.*memory *//' -e 's/GiB//' | awk '{print $1}'"
44
+ @size = `#{cmd}`.to_i
45
+
46
+ cmd = 'sudo lshw -c memory -short | grep MHz | ' \
47
+ "sed -e 's/.*memory *//' -e 's/(//' | uniq | cut -f3,5 -d' '"
48
+ @type, @speed, = `#{cmd}`.split ' ', 3
49
+ @speed = @speed.to_i
50
+
51
+ cmd = "grep SwapTotal /proc/meminfo | awk '{print $2}'"
52
+ @swap_size = `#{cmd}`.to_i
53
+ @swap_size /= 1_048_576
54
+
55
+ cmd = "sudo dmidecode -t memory | grep '[Data|Total] Width' | " \
56
+ "sort | uniq | cut -d' ' -f 3 | uniq | wc -l"
57
+ @is_ecc = `#{cmd}`.to_i != 1
58
+ end
59
+ end
60
+
61
+ # Memory probe for Mac OS
62
+ class MacSystemMemory < SystemMemory
63
+ def initialize
64
+ `system_profiler SPMemoryDataType > /tmp/memdata.tmp`
65
+ cmd = 'grep ECC /tmp/memdata.tmp | sed -e \'s/.*ECC: //\' | tr -d \'[:space:]\''
66
+ @is_ecc = `#{cmd}` != 'Disabled'
67
+
68
+ cmd = "grep Type /tmp/memdata.tmp | uniq | sed -e 's/.*Type: //' | tr -d '[:space:]'"
69
+ @type = `#{cmd}`
70
+
71
+ cmd = "grep Speed /tmp/memdata.tmp | uniq | sed -e 's/.*Speed: //' | cut -f1 -d' '"
72
+ @speed = `#{cmd}`.to_i
73
+
74
+ cmd = "grep Size /tmp/memdata.tmp | uniq | sed -e 's/.*Size: //' | cut -f1 -d' '"
75
+ slot_size = `#{cmd}`.to_i
76
+ cmd = "grep Size /tmp/memdata.tmp | wc -l | tr -d '[:space:]'"
77
+ slots = `#{cmd}`.to_i
78
+
79
+ @size = slots * slot_size
80
+ @swap_size = UNLIMITED
81
+ end
82
+ end
83
+
84
+ # Memory probe for Windows
85
+ class WindowsSystemMemory < SystemMemory
86
+ # rubocop:disable Style/ClassVars
87
+ # noinspection RubyClassVariableUsageInspection
88
+ @@mem_type = ['Unknown', 'Other', 'DRAM', 'Synchronous DRAM',
89
+ 'Cache DRAM', 'EDO', 'EDRAM', 'VRAM', 'SRAM', 'RAM',
90
+ 'ROM', 'Flash', 'EEPROM', 'FEPROM', 'EPROM', 'CDRAM',
91
+ '3DRAM', 'SDRAM', 'SGRAM', 'RDRAM', 'DDR', 'DDR2',
92
+ 'DDR2 FB-DIMM', 'Undefined', 'DDR3', 'FBD2']
93
+ # rubocop:enable Style/ClassVars
94
+
95
+ def initialize
96
+ count = 0
97
+ data_width = 0
98
+ total_width = 0
99
+ IO.popen('wmic MEMORYCHIP get Capacity,Speed,MemoryType,TotalWidth,DataWidth') do |io|
100
+ while (line = io.gets)
101
+ line = line.gsub(/\s+/m, ' ')
102
+ values = line.split(' ')
103
+ next if line.start_with?('Capacity') || values.empty?
104
+
105
+ @size = values[0].to_i / 1_048_576
106
+ data_width = values[1].to_i
107
+
108
+ # noinspection RubyClassVariableUsageInspection
109
+ @type = @@mem_type[values[2].to_i]
110
+ @speed = values[3].to_i
111
+ total_width = values[4].to_i
112
+ count += 1
113
+ end
114
+ end
115
+
116
+ @size = @size * count / 1024
117
+ cmd = `systeminfo | find "Virtual Memory: Max Size:"`
118
+ cmd = cmd.gsub(/\s+/m, ' ')
119
+ @swap_size = cmd.split(' ')[4].to_i
120
+ @is_ecc = data_width != total_width
121
+ end
122
+ end
data/lib/network.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'rbconfig'
2
+ require 'yaml'
3
+ require 'highline/import'
4
+
5
+ # Base and factory for processor probes
6
+ class SystemNetwork
7
+ UNLIMITED = -1
8
+
9
+ attr_accessor :upload_speed # upload speed in Mbps
10
+ attr_accessor :download_speed # download speed in Mbps
11
+ attr_accessor :default_gateway # the default gateway
12
+ attr_accessor :default_device # the default gateway device used
13
+ attr_accessor :dev_id
14
+ attr_accessor :dev_type
15
+ attr_accessor :dev_link_speed # device link speed in Mbps
16
+
17
+ def self.probe
18
+ case RbConfig::CONFIG['host_os']
19
+ when /linux/
20
+ LinuxSystemNetwork.new
21
+ when /darwin/
22
+ MacSystemNetwork.new
23
+ when /cygwin|mswin|mingw32|mingw|bccwin|wince|emx/
24
+ WindowsSystemNetwork.new
25
+ else
26
+ RbConfig::CONFIG['host_os']
27
+ end
28
+ end
29
+ end
30
+
31
+ # Processor probe for Linux systems
32
+ class LinuxSystemNetwork < SystemNetwork
33
+ lshw_xml = ``
34
+ def initialize
35
+ puts 'Implement me'
36
+ end
37
+ end
38
+
39
+ # Processor probe for Mac systems
40
+ class MacSystemNetwork < SystemNetwork
41
+ def initialize
42
+ puts 'Implement me'
43
+ end
44
+ end
45
+
46
+ # Processor probe for Windows systems
47
+ class WindowsSystemNetwork < SystemNetwork
48
+ def initialize
49
+ puts 'Implement me'
50
+ end
51
+ end
52
+
53
+ netprobe = SystemNetwork.probe
54
+ puts netprobe.to_yaml
data/lib/probench.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative '../lib/memory'
2
+
3
+ class Probench
4
+ def self.cli
5
+ end
6
+ end
data/lib/processors.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'rbconfig'
2
+ require 'yaml'
3
+
4
+ # Base and factory for processor probes
5
+ class SystemProcessors
6
+ UNLIMITED = -1
7
+
8
+ attr_accessor :speed # [DONE] current speed in GigaHertz
9
+ attr_accessor :count # [DONE] number of processors
10
+ attr_accessor :architecture # [DONE] enum x86_64, ARM64
11
+ attr_accessor :core_count # [DONE] number of total cores enabled
12
+ attr_accessor :thread_count # [DONE] total number of threads
13
+ attr_accessor :l2_cache # [DONE] L2 cache in KB
14
+ attr_accessor :l3_cache # [DONE] L3 cache in KB
15
+ attr_accessor :manufacturer # [DONE] manufacturer descriptor: i.e. GenuineIntel
16
+ attr_accessor :model # [DONE] model/version number
17
+ attr_accessor :model_name # [DONE] model/version descriptor
18
+ attr_accessor :family # [DONE] family number
19
+
20
+ def self.probe
21
+ case RbConfig::CONFIG['host_os']
22
+ when /linux/
23
+ LinuxSystemProcessors.new
24
+ when /darwin/
25
+ MacSystemProcessors.new
26
+ when /cygwin|mswin|mingw32|mingw|bccwin|wince|emx/
27
+ WindowsSystemProcessors.new
28
+ else
29
+ RbConfig::CONFIG['host_os']
30
+ end
31
+ end
32
+ end
33
+
34
+ # Processor probe for Linux systems
35
+ # noinspection RubyTooManyInstanceVariablesInspection
36
+ class LinuxSystemProcessors < SystemProcessors
37
+ require_relative 'linux_wrappers.rb'
38
+
39
+ def initialize
40
+ proc = lscpu
41
+ @model = proc['Model']
42
+ @model_name = proc['Model name']
43
+ @speed = (@model_name.split[5][0..-4].to_f * 1000).to_i
44
+ @family = proc['CPU family']
45
+ @architecture = proc['Architecture']
46
+ @count = proc['Socket(s)'].to_i
47
+ @core_count = proc['Core(s) per socket'].to_i * @count
48
+ @thread_count = proc['Thread(s) per core'].to_i * @core_count
49
+ @l2_cache = proc['L2 cache'][0..-2].to_i * @core_count
50
+ @l3_cache = proc['L3 cache'][0..-2].to_i
51
+ @manufacturer = proc['Vendor ID']
52
+ end
53
+ end
54
+
55
+ # Processor probe for Mac systems
56
+ # noinspection RubyTooManyInstanceVariablesInspection
57
+ class MacSystemProcessors < SystemProcessors
58
+ require_relative 'mac_wrappers.rb'
59
+
60
+ def initialize
61
+ # noinspection RubyResolve
62
+ proc = sysctl(HardwareCategory::PROCESSORS)
63
+ @model = proc['model']
64
+ @speed = proc['cpufrequency'].to_i / 1_000_000
65
+ @family = proc['family']
66
+ @architecture = 'x86_64' if proc['cpu64bit_capable'] == '1'
67
+ @count = `system_profiler SPHardwareDataType | grep Processors: | sed -e 's/ *Number of Processors: //'`.to_i
68
+ @core_count = proc['core_count'].to_i * @count
69
+ @thread_count = proc['thread_count'].to_i * @count
70
+ @l2_cache = `system_profiler SPHardwareDataType | grep 'L2 Cache' | sed -e 's/ *L2 Cache (per Core): //'`
71
+ @l2_cache = @l2_cache.to_i * @core_count
72
+ @l3_cache = `system_profiler SPHardwareDataType | grep 'L3 Cache' | sed -e 's/ *L3 Cache: //'`.to_i * 1024
73
+ @manufacturer = proc['vendor']
74
+ @model_name = proc['brand_string']
75
+ end
76
+ end
77
+
78
+ # Processor probe for Windows systems
79
+ # noinspection RubyTooManyInstanceVariablesInspection
80
+ class WindowsSystemProcessors < SystemProcessors
81
+ require_relative 'windows_wrappers.rb'
82
+
83
+ def initialize
84
+ # noinspection RubyResolve
85
+ proc = wmic HardwareCategory::PROCESSORS
86
+ @speed = proc['CurrentClockSpeed'].to_i.round(-1)
87
+ @model_name = proc['Name']
88
+ description = proc['Description'].split
89
+ @family = description[2]
90
+ @model = description[4]
91
+ @count = proc['count']
92
+ @core_count = proc['NumberOfCores'] * @count
93
+ @thread_count = proc['ThreadCount'] * @count
94
+ @l2_cache = proc['L2CacheSize'].to_i
95
+ @l3_cache = proc['L3CacheSize'].to_i
96
+ @manufacturer = proc['Manufacturer']
97
+ @architecture = 'x86_64' if proc['AddressWidth'] == '64'
98
+ end
99
+ end
data/lib/storage.rb ADDED
File without changes
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Probench
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'common.rb'
2
+
3
+ def wmic(category)
4
+ raise ArgumentError unless category.is_a?(HardwareCategory)
5
+
6
+ cmd = 'wmic '
7
+ # noinspection RubyResolve
8
+ case category
9
+ when HardwareCategory::PROCESSORS
10
+ cmd += 'cpu'
11
+ when HardwareCategory::MEMORY
12
+ cmd += 'memory'
13
+ else
14
+ raise ArgumentError 'Bad category'
15
+ end
16
+
17
+ lines = []
18
+ IO.popen(cmd) do |io|
19
+ while (line = io.gets)
20
+ lines << line
21
+ end
22
+ end
23
+
24
+ keys_str = lines[0]
25
+ vals_str = lines[2]
26
+
27
+ hash = {}
28
+ index = -1
29
+ key = nil
30
+ val = nil
31
+ while index < keys_str.size - 1
32
+ index += 1
33
+ lookahead = index < keys_str.size - 2 ? keys_str[index + 1] : nil
34
+
35
+ # transiting to inside when space turns into nonspace
36
+ if keys_str[index] == ' ' && lookahead != ' '
37
+ # noinspection RubyNilAnalysis
38
+ key = key.strip
39
+ # noinspection RubyNilAnalysis
40
+ val = val.strip
41
+ hash[key] = val unless val.nil? || val.size.zero?
42
+ key = nil
43
+ val = nil
44
+ elsif key.nil? && val.nil?
45
+ key = keys_str[index]
46
+ val = vals_str[index]
47
+ elsif !key.nil? && !val.nil?
48
+ key << keys_str[index]
49
+ val << vals_str[index]
50
+ end
51
+ end
52
+
53
+ # presuming multiple processors add extra lines
54
+ hash['count'] = lines.size - 5
55
+ hash
56
+ end
data/probench.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require_relative 'lib/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'probench'
7
+ s.version = Probench::VERSION
8
+ s.date = '2019-01-10'
9
+ s.summary = 'Hardware probing and benchmarking tools for Subutai'
10
+ s.description = 'The generate json file is used to understand the underlying hardware for pricing.'
11
+ s.authors = ['Subutai']
12
+ s.email = 'info@subutai.io'
13
+ s.homepage = 'https://github.com/subutai-io/probench'
14
+ s.metadata = { 'source_code_uri' => 'https://github.com/subutai-io/probench' }
15
+ s.files = `git ls-files`.split($\)
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.license = 'Apache-2.0'
19
+
20
+ s.add_runtime_dependency 'highline'
21
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: probench
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Subutai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: The generate json file is used to understand the underlying hardware
28
+ for pricing.
29
+ email: info@subutai.io
30
+ executables:
31
+ - probench
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - CHANGELOG
37
+ - LICENSE
38
+ - Readme.md
39
+ - bin/probench
40
+ - build.sh
41
+ - lib/common.rb
42
+ - lib/linux_wrappers.rb
43
+ - lib/mac_wrappers.rb
44
+ - lib/memory.rb
45
+ - lib/network.rb
46
+ - lib/probench.rb
47
+ - lib/processors.rb
48
+ - lib/storage.rb
49
+ - lib/version.rb
50
+ - lib/windows_wrappers.rb
51
+ - probench.gemspec
52
+ homepage: https://github.com/subutai-io/probench
53
+ licenses:
54
+ - Apache-2.0
55
+ metadata:
56
+ source_code_uri: https://github.com/subutai-io/probench
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.5.2.1
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Hardware probing and benchmarking tools for Subutai
77
+ test_files: []