swapus 1.0.2 → 1.1.0

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: a50a505a0b802b5ee8c4d06f7a8d4627fd81a6d4
4
- data.tar.gz: 0a7925bddceb4f0f8f42ea1682db102522d7b40d
3
+ metadata.gz: 1f4a80ef351b819295e802c80a25a8818bc9e72e
4
+ data.tar.gz: b20d67ee52c29c334f606d9c08505b5aaa045c24
5
5
  SHA512:
6
- metadata.gz: 5639d4ccf1eb57a8dc0f542c6296a7ffe6b55a03df023f7e4c85d203aa69ad9dc8c4cb5a2d469c1b05f7d0d011fcd92595b87f32081d3f8fb22b33f19414a424
7
- data.tar.gz: 361fb57f1cb38a199e27e4abf8998db890575e9118c01220ab43fcb87fca2dabd27ef57819d58fcffc92843acf88190d4e71ea32bd5586ccc859f96c9a508043
6
+ metadata.gz: aeaace77d0367dedef5a585b1ed053fb12eec8e1417cff09e27bb6eb9409084ebbbd1de74e7d0b5c158dc9da4eb98e950632fc9612d554a509815852c1906b9f
7
+ data.tar.gz: 35a859957104916f80f5b5655cf6a97bd6a5d9943e3fefc120875dd838ef402aefcb526442ae5b30c2d41dc9c8fedf657314442b0712a6da8405623ebf10be44
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
2
  dist: precise
3
3
  rvm:
4
- - 2.4.2
5
- - 2.3.5
4
+ - 2.5.0
5
+ - 2.4.3
6
+ - 2.3.6
6
7
  install:
7
8
  - bundle install
8
9
  - gem build swapus.gemspec
@@ -10,3 +11,4 @@ install:
10
11
  script:
11
12
  - rubocop
12
13
  - swapus
14
+ - swapus -v | grep $(cat VERSION)
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
- [![Version](https://img.shields.io/badge/latest_version-1.0.2-green.svg)](https://github.com/nishiki/swapus/releases)
2
+ [![Version](https://img.shields.io/badge/latest_version-1.1.0-green.svg)](https://github.com/nishiki/swapus/releases)
3
3
  [![Build Status](https://travis-ci.org/nishiki/swapus.svg?branch=master)](https://travis-ci.org/nishiki/swapus)
4
4
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/nishiki/swapus/blob/master/LICENSE)
5
5
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
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
- class SwapUsage
20
- def initialize
21
- @processes = {}
22
- end
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
- def get_processes
25
- Dir['/proc/[0-9]*'].map do |pid_dir|
26
- pid = File.basename(pid_dir).to_i
27
- cmd = File.read("#{pid_dir}/cmdline").tr("\x00", ' ').strip
28
- swap = File.read("#{pid_dir}/status")[/^VmSwap:\s+([0-9]+)\s+kB$/, 1].to_i
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
- @processes[pid] = { cmd: cmd, swap: swap } if swap.positive?
31
- end
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
- def show
35
- @processes.sort_by { |_, v| v[:swap] }.each do |pid, values|
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
- def run
41
- get_processes
42
- show
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.2
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-01 00:00:00.000000000 Z
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.11
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.