swapus 1.0.2 → 1.1.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 +4 -4
- data/.travis.yml +4 -2
- data/CHANGELOG.md +20 -0
- data/README.md +1 -1
- data/VERSION +1 -1
- data/bin/swapus +24 -20
- data/lib/swapus.rb +50 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f4a80ef351b819295e802c80a25a8818bc9e72e
|
4
|
+
data.tar.gz: b20d67ee52c29c334f606d9c08505b5aaa045c24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeaace77d0367dedef5a585b1ed053fb12eec8e1417cff09e27bb6eb9409084ebbbd1de74e7d0b5c158dc9da4eb98e950632fc9612d554a509815852c1906b9f
|
7
|
+
data.tar.gz: 35a859957104916f80f5b5655cf6a97bd6a5d9943e3fefc120875dd838ef402aefcb526442ae5b30c2d41dc9c8fedf657314442b0712a6da8405623ebf10be44
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
## v1.1.0 (2018-02-02)
|
3
|
+
|
4
|
+
* feat: add option to reverse the output result
|
5
|
+
* feat: add option to limit the number lines in output
|
6
|
+
* feat: add option to print the program version
|
7
|
+
* chore: add test with ruby 2.5.0
|
8
|
+
|
9
|
+
## v1.0.2 (2018-02-01)
|
10
|
+
|
11
|
+
* fix: remove null character
|
12
|
+
|
13
|
+
## v1.0.1 (2017-11-10)
|
14
|
+
|
15
|
+
* fix: minimal ruby version (2.3)
|
16
|
+
* fix license
|
17
|
+
|
18
|
+
## v1.0.0 (2017-10-06)
|
19
|
+
|
20
|
+
* first version
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Swapus
|
2
|
-
[](https://github.com/nishiki/swapus/releases)
|
3
3
|
[](https://travis-ci.org/nishiki/swapus)
|
4
4
|
[](https://github.com/nishiki/swapus/blob/master/LICENSE)
|
5
5
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/bin/swapus
CHANGED
@@ -16,31 +16,35 @@
|
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
20
|
+
|
21
|
+
require 'optparse'
|
22
|
+
require 'swapus'
|
23
|
+
|
24
|
+
options = {
|
25
|
+
reverse: false
|
26
|
+
}
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
OptionParser.new do |opts|
|
29
|
+
opts.banner = 'Usage: swapus [options]'
|
30
|
+
|
31
|
+
opts.on('-h', '--help', 'Show this message') do
|
32
|
+
puts opts
|
33
|
+
exit 0
|
34
|
+
end
|
29
35
|
|
30
|
-
|
31
|
-
|
36
|
+
opts.on('-n', '--number N', 'Print the N first lines') do |number|
|
37
|
+
options[:number] = number.to_i
|
32
38
|
end
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
puts "#{values[:swap]} kB [#{pid}] #{values[:cmd]}"
|
37
|
-
end
|
40
|
+
opts.on('-r', '--reverse', 'Reverse the result order') do
|
41
|
+
options[:reverse] = true
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
opts.on('-v', '--version', 'Show the version') do
|
45
|
+
puts File.read("#{File.dirname(__FILE__)}/../VERSION")
|
46
|
+
exit 0
|
43
47
|
end
|
44
|
-
end
|
48
|
+
end.parse!
|
45
49
|
|
46
|
-
SwapUsage.new.run
|
50
|
+
SwapUsage.new(options).run
|
data/lib/swapus.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
class SwapUsage
|
20
|
+
def initialize(options)
|
21
|
+
@processes = {}
|
22
|
+
@reverse = options[:reverse]
|
23
|
+
@number = options[:number]
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_processes
|
27
|
+
Dir['/proc/[0-9]*'].map do |pid_dir|
|
28
|
+
pid = File.basename(pid_dir).to_i
|
29
|
+
cmd = File.read("#{pid_dir}/cmdline").tr("\x00", ' ').strip
|
30
|
+
swap = File.read("#{pid_dir}/status")[/^VmSwap:\s+([0-9]+)\s+kB$/, 1].to_i
|
31
|
+
|
32
|
+
@processes[pid] = { cmd: cmd, swap: swap } if swap.positive?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
@processes = @processes.sort_by { |_, v| v[:swap] }
|
38
|
+
@processes = @processes.reverse if @reverse
|
39
|
+
@processes = @processes.first(@number) if @number
|
40
|
+
|
41
|
+
@processes.each do |pid, values|
|
42
|
+
puts "#{values[:swap]} kB [#{pid}] #{values[:cmd]}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def run
|
47
|
+
get_processes
|
48
|
+
show
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swapus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Waksberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -21,11 +21,13 @@ files:
|
|
21
21
|
- ".gitignore"
|
22
22
|
- ".rubocop.yml"
|
23
23
|
- ".travis.yml"
|
24
|
+
- CHANGELOG.md
|
24
25
|
- Gemfile
|
25
26
|
- LICENSE
|
26
27
|
- README.md
|
27
28
|
- VERSION
|
28
29
|
- bin/swapus
|
30
|
+
- lib/swapus.rb
|
29
31
|
- swapus.gemspec
|
30
32
|
homepage: https://github.com/nishiki/swapus
|
31
33
|
licenses:
|
@@ -47,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
49
|
version: '0'
|
48
50
|
requirements: []
|
49
51
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.6.
|
52
|
+
rubygems_version: 2.6.14
|
51
53
|
signing_key:
|
52
54
|
specification_version: 4
|
53
55
|
summary: Swapus is a little software to get processes who use swap.
|