compute_unit 0.3.3 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 392d224e4b52410a749c91ddcc25c17c213c5c0b1210d535f3bd1b11c1e88f6f
4
- data.tar.gz: 2043d45deb0e14470776ed90f04dbd89bdc02dea7b9a80b349fe4305e40f5055
3
+ metadata.gz: 95a51bd70b85087d18049b7fdcab55801859e1a6f240b58b3b26262431160b3d
4
+ data.tar.gz: 6c6da1daca1a6f46b3e9f651d0ca6c1ea9063cd78dc8ca0311cb68b99c6a6bb8
5
5
  SHA512:
6
- metadata.gz: edd810f90429892d0b21d4889fd953c9b93453786b68fceb36ee8fed628e7ed650a42a4de0e535333e4a40833a43e62fd0b59c651a2d844fe60fa2dfaca76bd2
7
- data.tar.gz: fad7d4f8fb84d70bb7613bbe4b0a34c24f108fcb8b58400a84e017ada8b4036e64d94f3be3c7a6007ab0f4164d38a7625a8b8b98c1fd27993540ea8e1b94e32d
6
+ metadata.gz: 7d7b0e432a47d65cae85ae48d86412702e037202404ece13c333495f805ed9eb75c4982e3d297d9f185ae24252b0bc559edb44a4b4168ceb5c70fbfb0c15ae3e
7
+ data.tar.gz: 4349a92b6b913d7e777ede290028bffcd6496392b2c8a7f63b36c9cec7e0d19dd7824013481a5d792d963e9138721b7ff9bec4ecf72a7f5efc4dab1bbe745c29
@@ -1,6 +1,10 @@
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
+
4
8
  ## 0.3.3
5
9
  * Fix bug with default database not being created
6
10
 
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'
@@ -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'
@@ -11,7 +11,7 @@ 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/hwdata/pci.ids'
14
+ DEFAULT_PCIDB_PATH = '/usr/share/misc/pci.ids'
15
15
 
16
16
  # @param use_opencl [Boolean]
17
17
  # @return [Array] - return a list of compute units
@@ -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)
@@ -15,6 +15,13 @@ module ComputeUnit
15
15
  end
16
16
  end
17
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
+
18
25
  def model
19
26
  raw_cpu_data[:model_name]
20
27
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ComputeUnit
4
- VERSION = '0.3.3'
4
+ VERSION = '0.4.0'
5
5
  end
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.3.3
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-10-28 00:00:00.000000000 Z
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,6 +133,7 @@ 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