compute_unit 0.2.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +6 -0
- data/compute_unit.gemspec +2 -2
- data/lib/compute_unit.rb +14 -1
- data/lib/compute_unit/compute_base.rb +18 -0
- data/lib/compute_unit/cpu.rb +9 -0
- data/lib/compute_unit/device.rb +5 -5
- data/lib/compute_unit/gpu.rb +11 -0
- data/lib/compute_unit/gpus/nvidia_gpu.rb +4 -2
- data/lib/compute_unit/version.rb +1 -1
- data/miner@192.168.0.119 +0 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95a51bd70b85087d18049b7fdcab55801859e1a6f240b58b3b26262431160b3d
|
4
|
+
data.tar.gz: 6c6da1daca1a6f46b3e9f651d0ca6c1ea9063cd78dc8ca0311cb68b99c6a6bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d7b0e432a47d65cae85ae48d86412702e037202404ece13c333495f805ed9eb75c4982e3d297d9f185ae24252b0bc559edb44a4b4168ceb5c70fbfb0c15ae3e
|
7
|
+
data.tar.gz: 4349a92b6b913d7e777ede290028bffcd6496392b2c8a7f63b36c9cec7e0d19dd7824013481a5d792d963e9138721b7ff9bec4ecf72a7f5efc4dab1bbe745c29
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
# Compute Unit Changelog
|
2
2
|
|
3
3
|
## Unrleased
|
4
|
+
## 0.4.0
|
5
|
+
* Adds ability to list attached processes to compute_unit sorted by field
|
6
|
+
* Adds ability to list top_x attached processes sorted by field
|
7
|
+
|
8
|
+
## 0.3.3
|
9
|
+
* Fix bug with default database not being created
|
10
|
+
|
11
|
+
## 0.3.2
|
12
|
+
* Fix bug with default database not being created
|
13
|
+
|
14
|
+
## 0.3.1
|
15
|
+
Released 9/24/2020
|
16
|
+
|
17
|
+
* Use the default system pcidb file instead of throwing error
|
18
|
+
* Return default data if no hmon value exist
|
19
|
+
|
20
|
+
## 0.3.0
|
21
|
+
Released 6/16/2020
|
22
|
+
|
23
|
+
* Add name method to the cpu class
|
24
|
+
* Use constant for proc path
|
25
|
+
* Use debug when kernel file doesn't exist
|
4
26
|
|
5
27
|
## 0.2.1
|
6
28
|
Released 6/6/2020
|
data/README.md
CHANGED
@@ -35,6 +35,12 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
## Usage
|
37
37
|
|
38
|
+
Ensure the pci database exist on your system. You can update it at anytime with the built in linux command.
|
39
|
+
|
40
|
+
`/usr/sbin/update-pciids` or the command from this gem `update_pcidb` installed in your gem bin directory.
|
41
|
+
|
42
|
+
Additionally, when using the `ComputeUnit.find_all_with_database` method.
|
43
|
+
|
38
44
|
Find all compute devices
|
39
45
|
```
|
40
46
|
require 'compute_unit'
|
data/compute_unit.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.metadata['homepage_uri'] = spec.homepage
|
27
27
|
spec.metadata['source_code_uri'] = spec.homepage
|
28
|
-
spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
|
28
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/-/blob/master/CHANGELOG.md"
|
29
29
|
|
30
30
|
# Specify which files should be added to the gem when it is released.
|
31
31
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.bindir = 'exe'
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
37
|
spec.require_paths = ['lib']
|
38
|
-
|
38
|
+
spec.add_dependency 'sys-proctable', '~> 1.2', '>= 1.2.0'
|
39
39
|
spec.add_dependency 'opencl_ruby_ffi', '~> 1.3.4'
|
40
40
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
41
41
|
spec.add_development_dependency 'rake', '~> 13'
|
data/lib/compute_unit.rb
CHANGED
@@ -11,23 +11,36 @@ module ComputeUnit
|
|
11
11
|
SYS_DEVICE_PATH = File.join(SYSFS_PATH, 'bus/pci/devices')
|
12
12
|
PCI_DATABASE_PATH = File.join(File.dirname(__dir__), 'pci.ids')
|
13
13
|
PCI_DATABASE_URL = 'http://pci-ids.ucw.cz/v2.2/pci.ids'
|
14
|
+
DEFAULT_PCIDB_PATH = '/usr/share/misc/pci.ids'
|
14
15
|
|
16
|
+
# @param use_opencl [Boolean]
|
17
|
+
# @return [Array] - return a list of compute units
|
15
18
|
def self.find_all(use_opencl = false)
|
16
19
|
require 'compute_unit/gpu'
|
17
20
|
require 'compute_unit/cpu'
|
18
21
|
require 'compute_unit/asic'
|
19
|
-
|
22
|
+
|
23
|
+
copy_default_database unless File.exist?(PCI_DATABASE_PATH)
|
20
24
|
|
21
25
|
ComputeUnit::Gpu.find_all(use_opencl) +
|
22
26
|
ComputeUnit::Cpu.find_all +
|
23
27
|
ComputeUnit::Asic.find_all
|
24
28
|
end
|
25
29
|
|
30
|
+
# copies the default pci database from linux filesystem over to the gem path
|
31
|
+
def self.copy_default_database
|
32
|
+
FileUtils.cp(DEFAULT_PCIDB_PATH, PCI_DATABASE_PATH)
|
33
|
+
end
|
34
|
+
|
35
|
+
# get a fresh copy of the database and then use find_all
|
36
|
+
# @param use_opencl [Boolean]
|
37
|
+
# @return [Array] - return a list of compute units
|
26
38
|
def self.find_all_with_database(use_opencl = false)
|
27
39
|
refresh_pci_database
|
28
40
|
find_all(use_opencl)
|
29
41
|
end
|
30
42
|
|
43
|
+
# downloads the pci database
|
31
44
|
def self.refresh_pci_database
|
32
45
|
ComputeUnit::Utils.check_for_root
|
33
46
|
require 'net/http'
|
@@ -4,9 +4,12 @@ require 'time'
|
|
4
4
|
require 'compute_unit/formatters'
|
5
5
|
require 'compute_unit/logger'
|
6
6
|
require 'compute_unit/device'
|
7
|
+
require 'sys/proctable'
|
7
8
|
|
8
9
|
module ComputeUnit
|
9
10
|
class ComputeBase < Device
|
11
|
+
include Sys
|
12
|
+
|
10
13
|
attr_reader :type, :serial, :meta, :uuid, :timestamp, :index, :compute_type
|
11
14
|
attr_accessor :power_offset
|
12
15
|
|
@@ -26,6 +29,21 @@ module ComputeUnit
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
32
|
+
# @summary Finds all cpu attached processes and sorts by pctcpu
|
33
|
+
# @param field [Symbol] - the field to sort by
|
34
|
+
# @return [Array] - an array of attached processes
|
35
|
+
def attached_processes(_field = :pctcpu)
|
36
|
+
raise NotImplementedError
|
37
|
+
end
|
38
|
+
|
39
|
+
# @summary Find the processes consuming the most cpu
|
40
|
+
# @param x [Integer] the number of processes to return, defaults to 1
|
41
|
+
# @param field [Symbol] - the field to sort by
|
42
|
+
# @return [Array] - an array of attached processes
|
43
|
+
def top_processes(x = 1, field = :pctcpu)
|
44
|
+
attached_processes(field).last(x)
|
45
|
+
end
|
46
|
+
|
29
47
|
# @param value [Float] a value to offset the power calculation, either a whole number, or decimal
|
30
48
|
# @return [Integer] the value set as the offset
|
31
49
|
def power_offset=(value)
|
data/lib/compute_unit/cpu.rb
CHANGED
@@ -7,12 +7,21 @@ module ComputeUnit
|
|
7
7
|
DEVICE_CLASS = '060000'
|
8
8
|
DEVICE_CLASS_NAME = 'CPU'
|
9
9
|
# @return [Array] - returns a list of device paths of all devices considered for display
|
10
|
+
alias name model
|
11
|
+
|
10
12
|
def self.devices
|
11
13
|
ComputeUnit::ComputeBase.devices.find_all do |device|
|
12
14
|
ComputeUnit::Device.device_class(device) == DEVICE_CLASS
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
# @summary Finds all cpu attached processes and sorts by pctcpu
|
19
|
+
# @param field [Symbol] - the field to sort by
|
20
|
+
# @return [Array] - an array of attached processes
|
21
|
+
def attached_processes(field = :pctcpu)
|
22
|
+
Sys::ProcTable.ps(smaps: false).sort_by(&field)
|
23
|
+
end
|
24
|
+
|
16
25
|
def model
|
17
26
|
raw_cpu_data[:model_name]
|
18
27
|
end
|
data/lib/compute_unit/device.rb
CHANGED
@@ -10,7 +10,7 @@ module ComputeUnit
|
|
10
10
|
class Device
|
11
11
|
# We can supply a mock sysfs path in order to test with containers and other scenarios
|
12
12
|
SYSFS_DEVICES_PATH = File.join(ComputeUnit::SYSFS_PATH, 'bus', 'pci', 'devices')
|
13
|
-
|
13
|
+
PROC_PATH = ENV['PROC_PATH'] || '/proc'
|
14
14
|
attr_reader :device_class_id,
|
15
15
|
:device_id,
|
16
16
|
:device_vendor_id,
|
@@ -130,7 +130,7 @@ module ComputeUnit
|
|
130
130
|
rescue Errno::EINVAL, Errno::EPERM
|
131
131
|
default
|
132
132
|
rescue Errno::ENOENT
|
133
|
-
logger.
|
133
|
+
logger.debug("File #{path} does not exist, using defaults")
|
134
134
|
default
|
135
135
|
rescue Errno::EACCES
|
136
136
|
logger.fatal('run this command as root or with sudo, using default value')
|
@@ -140,9 +140,9 @@ module ComputeUnit
|
|
140
140
|
# @param item [String] - the name of the hwmon file to read from
|
141
141
|
# @param default [Object] - the default value to return if the file is empty or not readable
|
142
142
|
# @return [String] - the value of the item looked up
|
143
|
-
def read_hwmon_data(item,
|
143
|
+
def read_hwmon_data(item, default = nil)
|
144
144
|
path = File.join(hwmon_path, item)
|
145
|
-
read_file(path)
|
145
|
+
read_file(path, default)
|
146
146
|
end
|
147
147
|
|
148
148
|
# @param item [String] - the name of the hwmon file to write to
|
@@ -271,7 +271,7 @@ module ComputeUnit
|
|
271
271
|
logger.fatal(e.message)
|
272
272
|
default
|
273
273
|
rescue Errno::ENOENT
|
274
|
-
logger.
|
274
|
+
logger.debug("File #{path} does not exist")
|
275
275
|
default
|
276
276
|
rescue Errno::EACCES
|
277
277
|
logger.fatal('Run this command as root or with sudo')
|
data/lib/compute_unit/gpu.rb
CHANGED
@@ -13,6 +13,17 @@ module ComputeUnit
|
|
13
13
|
type
|
14
14
|
end
|
15
15
|
|
16
|
+
# @summary Finds all cpu attached processes and sorts by pctcpu
|
17
|
+
# @param field [Symbol] - the field to sort by
|
18
|
+
# @return [Array] - an array of attached processes
|
19
|
+
def attached_processes(field = :pctcpu)
|
20
|
+
# looks for any fd device with dri or nvidia in the name
|
21
|
+
p = Sys::ProcTable.ps(smaps: false).find_all do |p|
|
22
|
+
p.fd.values.find { |f| f =~ %r{/dev/dri|nvidia\d+} }
|
23
|
+
end
|
24
|
+
p.sort_by(&field)
|
25
|
+
end
|
26
|
+
|
16
27
|
# @return [OpenCL_Device]
|
17
28
|
def opencl_device
|
18
29
|
@opencl_device ||= self.class.opencl_devices.find_all { |cu| cu[:type] == make }[index] if use_opencl
|
@@ -8,6 +8,7 @@ module ComputeUnit
|
|
8
8
|
MAKE = 'Nvidia'
|
9
9
|
SUBTYPE = 'nvidia'
|
10
10
|
NVIDIA_SMI = '/usr/bin/nvidia-smi'
|
11
|
+
NVIDIA_PROC_PATH = ENV['NVIDIA_PROC_PATH'] || File.join(ComputeUnit::Device::PROC_PATH, 'driver', 'nvidia', 'gpus')
|
11
12
|
|
12
13
|
def initialize(device_path, opts = {})
|
13
14
|
data = self.class.read_information_file(device_path).merge(opts)
|
@@ -159,7 +160,7 @@ module ComputeUnit
|
|
159
160
|
def information_file
|
160
161
|
@information_file ||= begin
|
161
162
|
device_name = File.basename(device_path)
|
162
|
-
File.join(
|
163
|
+
File.join(NVIDIA_PROC_PATH, device_name, 'information')
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
@@ -209,7 +210,8 @@ module ComputeUnit
|
|
209
210
|
# :device_minor=>"7"}
|
210
211
|
def self.read_information_file(device_path)
|
211
212
|
device_name = File.basename(device_path)
|
212
|
-
information_file =
|
213
|
+
information_file = File.join(NVIDIA_PROC_PATH, device_name, 'information')
|
214
|
+
|
213
215
|
File.open(information_file, 'r') do |file|
|
214
216
|
content = file.read
|
215
217
|
content.scan(/\n?([\w\s]*):\s+(.*)/).map { |key, value| [key.downcase.tr(' ', '_').to_sym, value] }.to_h
|
data/lib/compute_unit/version.rb
CHANGED
data/miner@192.168.0.119
ADDED
Binary file
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compute_unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sys-proctable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.2'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: opencl_ruby_ffi
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,13 +133,14 @@ files:
|
|
113
133
|
- lib/compute_unit/monkey_patches.rb
|
114
134
|
- lib/compute_unit/utils.rb
|
115
135
|
- lib/compute_unit/version.rb
|
136
|
+
- miner@192.168.0.119
|
116
137
|
homepage: https://gitlab.com/blockops/compute_unit
|
117
138
|
licenses:
|
118
139
|
- MIT
|
119
140
|
metadata:
|
120
141
|
homepage_uri: https://gitlab.com/blockops/compute_unit
|
121
142
|
source_code_uri: https://gitlab.com/blockops/compute_unit
|
122
|
-
changelog_uri: https://gitlab.com/blockops/compute_unit/CHANGELOG.md
|
143
|
+
changelog_uri: https://gitlab.com/blockops/compute_unit/-/blob/master/CHANGELOG.md
|
123
144
|
post_install_message:
|
124
145
|
rdoc_options: []
|
125
146
|
require_paths:
|