sys-proctable 0.9.9-universal-linux → 1.0.0-universal-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0f13537cd8a33add0739cb78526d05006bc6aa5
4
- data.tar.gz: 18433abb3f9dd310603bc9633ec2d55e24025c87
3
+ metadata.gz: 6d0b0a05d36c394362b0da61c6996ee92c98f5cf
4
+ data.tar.gz: 6f93ad7718224d50c60010375a0d7fa72ab8df2d
5
5
  SHA512:
6
- metadata.gz: c9824df5d678bb2cfc4aaa3f8fc202b0acca08d6498d9798b97e51e4b3d9a789e0417be6dcfc4c90cb0cc340a6a3f1b2906897864411a4fe7ff800cb3676da44
7
- data.tar.gz: bef2ef2d8b351d42065327e10bcba67e0334d4a7dc758ba5d789754301382d9eab6fa4fa123bb7bf4db33f85e6b868b9c665e30e71c78f6a128295b09c36298f
6
+ metadata.gz: 8bbd13a460d6b1fa732b9a36466de419dc5f79c9d55b879d5949a77b6faf70b983cd0d4902705c3befdb984fcb02f86235c6d2a161152188a8a05344d8997686
7
+ data.tar.gz: b064d160df07a3734ddce2758bfefca86c7dd360e9de948e62b915592035479981fa13fc3e36b64addcebe65ae5cfd2a21841cd92ba4a1e44c2c022db7acd8fb
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.0.0 - 11-Jan-2016
2
+ * Added smaps information for Linux. Thanks go to Joe Rafaniello for the patch.
3
+ * This is not really a major release. I just ran out of version numbers.
4
+
1
5
  == 0.9.9 - 8-Nov-2015
2
6
  * Added support for cgroups on Linux. Thanks go to Dennis Günnewig for the patch.
3
7
  * Added a sys-proctable.rb file for convenience.
data/README CHANGED
@@ -105,7 +105,7 @@
105
105
  Artistic 2.0
106
106
 
107
107
  == Copyright
108
- (C) 2003-2015 Daniel J. Berger
108
+ (C) 2003-2016 Daniel J. Berger
109
109
  All Rights Reserved.
110
110
 
111
111
  == Contributions
data/Rakefile CHANGED
@@ -166,7 +166,7 @@ namespace :gem do
166
166
  when /linux/i
167
167
  spec.platform = Gem::Platform.new(['universal', 'linux'])
168
168
  spec.require_paths = ['lib', 'lib/linux']
169
- spec.files += ['lib/linux/sys/proctable.rb', 'lib/linux/sys/proctable/cgroup_entry.rb']
169
+ spec.files += ['lib/linux/sys/proctable.rb', 'lib/linux/sys/proctable/cgroup_entry.rb', 'lib/linux/sys/proctable/smaps.rb']
170
170
  spec.test_files << 'test/test_sys_proctable_linux.rb'
171
171
  when /sunos|solaris/i
172
172
  spec.platform = Gem::Platform.new(['universal', 'solaris'])
@@ -1,5 +1,6 @@
1
1
  require 'sys/proctable/version'
2
2
  require_relative 'proctable/cgroup_entry'
3
+ require_relative 'proctable/smaps'
3
4
 
4
5
  # The Sys module serves as a namespace only.
5
6
  module Sys
@@ -73,7 +74,8 @@ module Sys
73
74
  'pctcpu', # Percent of CPU usage (custom field)
74
75
  'pctmem', # Percent of Memory usage (custom field)
75
76
  'nlwp', # Number of Light-Weight Processes associated with the process (threads)
76
- 'cgroup' # Control groups to which the process belongs
77
+ 'cgroup', # Control groups to which the process belongs
78
+ 'smaps' # Process memory size for all mapped files
77
79
  ]
78
80
 
79
81
  public
@@ -169,6 +171,13 @@ module Sys
169
171
  # Get control groups to which the process belongs
170
172
  struct.cgroup = IO.readlines("/proc/#{file}/cgroup").map { |l| CgroupEntry.new(l) } rescue []
171
173
 
174
+ # Read smaps, returning a parsable string if we don't have permissions.
175
+ # Note: We're blindly rescuing because File.readable?/readable_real?
176
+ # are true for a file in the /proc fileystem but raises a ErrNo:EACCESS
177
+ # when your try to read it without permissions.
178
+ smaps_contents = IO.read("/proc/#{file}/smaps") rescue ""
179
+ struct.smaps = Smaps.new(file, smaps_contents)
180
+
172
181
  # Deal with spaces in comm name. Courtesy of Ara Howard.
173
182
  re = %r/\([^\)]+\)/
174
183
  comm = stat[re]
@@ -3,7 +3,7 @@ module Sys
3
3
  # This represents a cgroup entry
4
4
  #
5
5
  # Have a look at `man 5 proc` on a linux distribution, to get some more
6
- # information about the lines and there fields in `/proc/[pid]/cgroup`.
6
+ # information about the lines and their fields in `/proc/[pid]/cgroup`.
7
7
  #
8
8
  # Example:
9
9
  #
@@ -0,0 +1,118 @@
1
+ module Sys
2
+ class ProcTable
3
+ # Smaps represents a process' memory size for all mapped files
4
+ #
5
+ # A single mapped file memory entry looks like this:
6
+ #
7
+ # 00400000-004d4000 r-xp 00000000 fd:00 785 /bin/bash
8
+ # Size: 848 kB
9
+ # Rss: 572 kB
10
+ # Pss: 572 kB
11
+ # Shared_Clean: 0 kB
12
+ # Shared_Dirty: 0 kB
13
+ # Private_Clean: 572 kB
14
+ # Private_Dirty: 0 kB
15
+ # Referenced: 572 kB
16
+ # Anonymous: 0 kB
17
+ # AnonHugePages: 0 kB
18
+ # Swap: 0 kB
19
+ # KernelPageSize: 4 kB
20
+ # MMUPageSize: 4 kB
21
+ #
22
+ # Have a look at `man 5 proc` on a linux distribution, to get some more
23
+ # information about the lines and fields in `/proc/[pid]/smaps`.
24
+ #
25
+ # Example:
26
+ #
27
+ # smaps = Smaps.new(123, IO.read("/proc/1234/smaps")
28
+ # => #<Sys::ProcTable::Smaps:0x007f8ac5930768 @pid=123, @pss=107000, @rss=368000, @uss=96000, @swap=192000, @vss=136752000>
29
+ # smaps.pss # => 109568
30
+ # smaps.rss # => 376832
31
+ # smaps.uss # => 98304
32
+ # smaps.swap # => 196608
33
+ # smaps.vss # => 140034048
34
+ #
35
+ class Smaps
36
+
37
+ # Process ID for this smaps
38
+ attr_reader :pid
39
+
40
+ # Proportional set size
41
+ #
42
+ # PSS is the size of private pages added to each shared mapping's size
43
+ # divided by the number of processes that share it. It is meant to
44
+ # provide a better representation of the amount of memory actually used
45
+ # by a process.
46
+ #
47
+ # If a process has 4k of private pages, 4k of shared pages shared with one
48
+ # other process, and 3k of pages shared with two other processes, the PSS
49
+ # is:
50
+ #
51
+ # 4k + (4k / 2) + (3k / 3) = 7k
52
+ #
53
+ attr_reader :pss
54
+ alias_method :proportional_set_size, :pss
55
+
56
+ # Resident set size
57
+ #
58
+ # RSS is the total size of all pages, shared or not, mapped to a process.
59
+ attr_reader :rss
60
+ alias_method :resident_set_size, :rss
61
+
62
+ # Unique set size
63
+ #
64
+ # USS is the total size of all private pages mapped to a process.
65
+ attr_reader :uss
66
+ alias_method :unique_set_size, :uss
67
+
68
+ # Swap
69
+ #
70
+ # Swap is the total size of all swapped pages mapped to a process.
71
+ attr_reader :swap
72
+
73
+ # Virtual set size
74
+ #
75
+ # VSS is the total accessible address space in a process. Since files are
76
+ # lazily loaded, this value represents the total size of all mapped files
77
+ # if they were all loaded.
78
+ attr_reader :vss
79
+ alias_method :virtual_set_size, :vss
80
+
81
+ # Create a new smaps object
82
+ #
83
+ #
84
+ # This expects a process id and a string containing the contents of
85
+ # /proc/PID/smaps - see `man 5 proc` for a reference.
86
+ #
87
+ # The smaps contents are parsed and memory sizes are calculated in bytes.
88
+ def initialize(pid, smaps_contents)
89
+ @pid = pid
90
+ @pss = 0
91
+ @rss = 0
92
+ @uss = 0
93
+ @swap = 0
94
+ @vss = 0
95
+ smaps_contents.each_line { |line| parse_smaps_line(line) }
96
+ end
97
+
98
+ alias_method :to_s, :inspect
99
+
100
+ private
101
+
102
+ def parse_smaps_line(line)
103
+ case line
104
+ when /^Pss:\s+?(\d+)/
105
+ @pss += Regexp.last_match[1].to_i * 1000
106
+ when /^Rss:\s+?(\d+)/
107
+ @rss += Regexp.last_match[1].to_i * 1000
108
+ when /^Size:\s+?(\d+)/
109
+ @vss += Regexp.last_match[1].to_i * 1000
110
+ when /^Swap:\s+?(\d+)/
111
+ @swap += Regexp.last_match[1].to_i * 1000
112
+ when /^Private_(Clean|Dirty):\s+?(\d+)/
113
+ @uss += Regexp.last_match[2].to_i * 1000
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -1,6 +1,6 @@
1
1
  module Sys
2
2
  class ProcTable
3
3
  # The version of the sys-proctable library
4
- VERSION = '0.9.9'
4
+ VERSION = '1.0.0'
5
5
  end
6
6
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-proctable'
5
- spec.version = '0.9.9'
5
+ spec.version = '1.0.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -19,7 +19,7 @@ class TC_ProcTable_All < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_version
22
- assert_equal('0.9.9', ProcTable::VERSION)
22
+ assert_equal('1.0.0', ProcTable::VERSION)
23
23
  end
24
24
 
25
25
  def test_fields
@@ -17,7 +17,7 @@ class TC_ProcTable_Linux < Test::Unit::TestCase
17
17
  stime cutime cstime priority nice itrealvalue starttime vsize
18
18
  rss rlim startcode endcode startstack kstkesp kstkeip signal blocked
19
19
  sigignore sigcatch wchan nswap cnswap exit_signal processor environ
20
- pctcpu pctmem nlwp cgroup
20
+ pctcpu pctmem nlwp cgroup smaps
21
21
  /
22
22
  end
23
23
 
@@ -301,6 +301,11 @@ class TC_ProcTable_Linux < Test::Unit::TestCase
301
301
  assert_kind_of(ProcTable::CgroupEntry, @ptable.cgroup.first)
302
302
  end
303
303
 
304
+ def test_smaps
305
+ assert_respond_to(@ptable, :smaps)
306
+ assert_kind_of(ProcTable::Smaps, @ptable.smaps)
307
+ end
308
+
304
309
  def teardown
305
310
  @ptable = nil
306
311
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-proctable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 1.0.0
5
5
  platform: universal-linux
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -30,7 +30,7 @@ cert_chain:
30
30
  EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
31
31
  tGSHgAmcLlkdGgan182qsE/4kKM=
32
32
  -----END CERTIFICATE-----
33
- date: 2015-11-08 00:00:00.000000000 Z
33
+ date: 2016-01-11 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: test-unit
@@ -89,6 +89,7 @@ files:
89
89
  - test/test_sys_proctable_all.rb
90
90
  - lib/linux/sys/proctable.rb
91
91
  - lib/linux/sys/proctable/cgroup_entry.rb
92
+ - lib/linux/sys/proctable/smaps.rb
92
93
  homepage: http://github.com/djberg96/sys-proctable
93
94
  licenses:
94
95
  - Artistic 2.0
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.5.0
114
+ rubygems_version: 2.5.1
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: An interface for providing process table information
metadata.gz.sig CHANGED
Binary file