linux_stat 0.3.0 → 0.3.1

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: 3e2c68de7353a60dbdff528a65e721cc0f7632e95c5d8db2e0e1dc1b7242deb1
4
- data.tar.gz: ada661cb896983bddf8f831b55822bfb006f6167c1ea2bbbd2319bf38028bd79
3
+ metadata.gz: 918383341aa375e1414e08c13b38829373caa174c64769541955180ce9d6e09c
4
+ data.tar.gz: b821c81eee9bf5c9061057ab653e336adbbeaacf51d9b4141e6a1d72073058b6
5
5
  SHA512:
6
- metadata.gz: 1399f3b227442243558ae76d4cdbc4679f21984b8d7e2aacd7ed25c471d5588e9901877c943d4a2220583f3eb4094b00e81016e6e573ef1038052574e8306fd0
7
- data.tar.gz: 79c25491f4517ef2370b375d19177ca01b6589c6e0931e40dc0aa7c92269b605c97cab4cfe42cde51895ebe9b21d418fd301daf44dfdc496ff0b8bd24788dac6
6
+ metadata.gz: 580b5af4a00f4b2078e2d7cf9e249ba9648a5ab5965fe26c15f73c0cb843eeae6470e00d28fb096100f7b5445e47fcdce354c713c3aff4139fcb8a53221d68f0
7
+ data.tar.gz: 6ebaa17fd1aaf45910a297df8b992e495e3f8c594c2b69181bdd1c9536bb2be40a8ad4fb569f4be076aac1eaf70fc0d86d7930eedde79615db6ffcfcb498dc50
data/README.md CHANGED
@@ -44,7 +44,6 @@ Or install it yourself as:
44
44
 
45
45
  ## Usage
46
46
  ### LinuxStat::BIOS
47
- ### LinuxStat::BIOS
48
47
  ```
49
48
  LinuxStat::BIOS.date
50
49
  => "04/10/2017"
@@ -1,4 +1,7 @@
1
1
  require 'mkmf'
2
- create_makefile 'linux_stat/fs_stat'
3
2
 
4
- # abort 'missing'
3
+ unless (have_header('sys/statvfs.h') && have_header('ruby.h'))
4
+ abort('Missing header')
5
+ end
6
+
7
+ create_makefile 'linux_stat/fs_stat'
@@ -1,7 +1,9 @@
1
1
  module LinuxStat
2
2
  module CPU
3
3
  class << self
4
- # Returns the cpu usage of all threads.
4
+ # stat(sleep = 0.075)
5
+ # Where sleep is the delay to gather the data.
6
+ # This method returns the cpu usage of all threads.
5
7
  #
6
8
  # The first one is aggregated CPU usage reported by the Linux kernel.
7
9
  # And the consecutive ones are the real core usages.
@@ -30,7 +32,10 @@ module LinuxStat
30
32
  end
31
33
  end
32
34
 
33
- # Returns the total cpu usage.
35
+ # total_usage(sleep = 0.075)
36
+ # Where sleep is the delay to gather the data.
37
+ # This method returns the cpu usage of all threads.
38
+ #
34
39
  # It's like running LinuxStat::CPU.stat[0] but it's much more efficient and calculates just the aggregated usage which is available at the top of the /proc/stat file.
35
40
  #
36
41
  # If the information is not available, it will return nil.
@@ -67,14 +72,26 @@ module LinuxStat
67
72
  # If the information isn't available, it will return an empty array.
68
73
  def cur_freq
69
74
  @@cpu_freqs ||= Dir["/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq"]
70
- @@cpu_freqs.map { |x| IO.read(x).to_i }
75
+ @@cur_freqs_readable ||= @@cpu_freqs.all?(&File.method(:readable?))
76
+
77
+ if @@cur_freqs_readable
78
+ @@cpu_freqs.map { |x| IO.read(x).to_i }
79
+ else
80
+ []
81
+ end
71
82
  end
72
83
 
73
84
  # Returns an array with max core frequencies corresponding to the usages.
74
85
  # If the information isn't available, it will return an empty array.
75
86
  def max_freq
76
87
  @@max_freqs ||= Dir["/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq"]
77
- @@max_freqs.map { |x| IO.read(x).to_i }
88
+ @@max_freqs_readable ||= @@max_freqs.all?(&File.method(:readable?))
89
+
90
+ if @@max_freqs_readable
91
+ @@max_freqs.map { |x| IO.read(x).to_i }
92
+ else
93
+ []
94
+ end
78
95
  end
79
96
 
80
97
  alias usages stat
@@ -17,7 +17,6 @@ module LinuxStat
17
17
  # {:total=>119981191168, :free=>43155574784, :used=>76825616384, :available=>43155574784}
18
18
  #
19
19
  # If the stat can't be acquired, this method will return an empty Hash.
20
-
21
20
  def stat(fs = ?/.freeze)
22
21
  s = stat_raw(fs)
23
22
  return {} if s.empty?
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Efficient linux system reporting gem. Linux Only | Efficient | Reliable
14
14
  email: