proc_parser 0.2.3 → 0.3.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
  SHA1:
3
- metadata.gz: 895cd908217e2c6fd498e81d70f39cd965e9af8b
4
- data.tar.gz: fc934cdf6cd6c8d21921725b99f67bed37a900f8
3
+ metadata.gz: b09b59c528fac6ea7f22e7b26e7820b2a442e06f
4
+ data.tar.gz: da49854cb36185da614f59ec94591f070d6e1ff0
5
5
  SHA512:
6
- metadata.gz: df7cba287a8906c150bb67e4b2672526710463a16cd5211f8bdf510154bec450612509713a39a4dc3890a86e35b22079c1c443e55575781521a69d8f4f7e1866
7
- data.tar.gz: caeb40c5615e1813602f4bb3f98d24819d3bfd1ec667f0c5d12d50ed579764cfacbc512970731d3ccb96f35301cf43d2b4ef246d37f3ef53b22d63bd8fefb1a4
6
+ metadata.gz: c1a196fdf8d8604b4a7191c2d5ef418da6793dba01a317b256f4c8244f44a33a5af3584322fd8e245725cc9218747cf08a4ea331f83131ab7f772a475099d5e8
7
+ data.tar.gz: d77b7c009fefb38071a98db04803d1c3e73a3a3859e512ccd735fa30fe82f7e4f93ae31e7b823f068930ab01e4131ebca85474a97b1ad2f8f7bddc53a15d951f
data/README.md CHANGED
@@ -4,8 +4,8 @@ proc_parser provides a Ruby wrapper for /proc data such as those contained in
4
4
  /proc/mem_info, /proc/stat and /proc/loadavg.
5
5
 
6
6
  Interested in support of more proc files? Contributions are welcome! You can
7
- either create an [issue](https://github.com/EtienneM/mem_info/issues) or
8
- propose a [pull request](https://github.com/EtienneM/mem_info/pulls).
7
+ either create an [issue](https://github.com/EtienneM/proc_parser/issues) or
8
+ propose a [pull request](https://github.com/EtienneM/proc_parser/pulls).
9
9
 
10
10
  Wondering the meaning of some fields? Read the manual with [`man 5
11
11
  proc`](https://linux.die.net/man/5/proc).
@@ -42,28 +42,35 @@ module ProcParser
42
42
  end
43
43
 
44
44
  #
45
- ## Get the current CPU usage in percentage. It's a global percentage normalized on the number of
46
- # CPU.
45
+ # The next values (idletime, non_idletime and totaltime) are computed based on the following
46
+ # information:
47
47
  #
48
- # The CPU usage is actually everything but the idle time of the CPU.
48
+ # - https://stackoverflow.com/a/23376195/1351436
49
+ # - `htop` source code: https://github.com/hishamhm/htop/blob/e0209da88faf3b390d71ff174065abd407abfdfd/ProcessList.c#L947
50
+ # - man 5 proc
49
51
  #
50
- # cf. `htop` source code: https://github.com/hishamhm/htop/blob/e0209da88faf3b390d71ff174065abd407abfdfd/ProcessList.c#L947
51
- # cf. man 5 proc
52
- # cf. https://stackoverflow.com/a/23376195/1351436
52
+ # Computing the percentage usage is done with the following algorithm:
53
+ # totald = Total - PrevTotal
54
+ # idled = Idle - PrevIdle
55
+ # CPU_Percentage = (totald - idled)/totald
53
56
  #
54
- def percentage_usage
57
+ # With the Prev* variables fetched earlier than the current values.
58
+ def idletime
59
+ return @idle + @iowait
60
+ end
61
+
62
+ def non_idletime
55
63
  # Guest time is already accounted in user time
56
64
  user = @user - @guest
57
65
  nice = @nice - @guest_nice
58
66
 
59
- idlealltime = @idle + @iowait
60
67
  systemalltime = @system + @irq + @softirq
61
68
  virtalltime = @guest + @guest_nice
62
- non_idlealltime = user + nice + systemalltime + @steal + virtalltime
63
-
64
- total = idlealltime + non_idlealltime
69
+ return user + nice + systemalltime + @steal + virtalltime
70
+ end
65
71
 
66
- return non_idlealltime / total.to_f
72
+ def totaltime
73
+ return idletime + non_idletime
67
74
  end
68
75
  end
69
76
  end
@@ -1,3 +1,3 @@
1
1
  module ProcParser
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'bundler', '~> 1.15'
36
36
  spec.add_development_dependency 'rake', '~> 12.1'
37
37
  spec.add_development_dependency 'rspec', '~> 3.6'
38
- spec.add_development_dependency 'pry'
38
+ spec.add_development_dependency 'pry', '~> 0'
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proc_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Étienne Michon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-11 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: |-