rps 0.0.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.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +5 -0
- data/autotest/discover.rb +1 -0
- data/bin/rps +4 -0
- data/lib/rps.rb +8 -0
- data/lib/rps/cli.rb +14 -0
- data/lib/rps/process_entry.rb +41 -0
- data/lib/rps/runner.rb +20 -0
- data/lib/rps/ui.rb +20 -0
- data/lib/rps/version.rb +3 -0
- data/rps.gemspec +24 -0
- data/spec/rps/cli_spec.rb +20 -0
- data/spec/rps/process_entry_spec.rb +62 -0
- data/spec/rps/runner_spec.rb +28 -0
- data/spec/rps/ui_spec.rb +20 -0
- data/spec/spec_helper.rb +2 -0
- metadata +129 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jari Bakken
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
= rps
|
2
|
+
|
3
|
+
ps for Ruby processes. Linux only at the moment.
|
4
|
+
|
5
|
+
= Example
|
6
|
+
|
7
|
+
$ rps
|
8
|
+
|
9
|
+
= Description
|
10
|
+
|
11
|
+
== Note on Patches/Pull Requests
|
12
|
+
|
13
|
+
* Fork the project.
|
14
|
+
* Make your feature addition or bug fix.
|
15
|
+
* Add tests for it. This is important so I don't break it in a
|
16
|
+
future version unintentionally.
|
17
|
+
* Commit, do not mess with rakefile, version, or history.
|
18
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
19
|
+
* Send me a pull request. Bonus points for topic branches.
|
20
|
+
|
21
|
+
== Copyright
|
22
|
+
|
23
|
+
Copyright (c) 2010 Jari Bakken. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/bin/rps
ADDED
data/lib/rps.rb
ADDED
data/lib/rps/cli.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module RPS
|
2
|
+
class ProcessEntry
|
3
|
+
def self.all
|
4
|
+
Dir['/proc/*'].map { |dir| new(dir) if File.basename(dir) =~ /^\d+$/ }.compact
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(dir)
|
8
|
+
@dir = dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def readable?
|
12
|
+
File.readable? exe_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def ruby?
|
16
|
+
exe.include? "ruby" # is this good enough?
|
17
|
+
end
|
18
|
+
|
19
|
+
def exe
|
20
|
+
@exe ||= File.readlink(exe_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def pid
|
24
|
+
@pid ||= Integer(File.basename(@dir))
|
25
|
+
end
|
26
|
+
|
27
|
+
def command_line
|
28
|
+
@command_line ||= File.read(cmdline_path).split("\000")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def exe_path
|
34
|
+
File.join(@dir, "exe")
|
35
|
+
end
|
36
|
+
|
37
|
+
def cmdline_path
|
38
|
+
File.join(@dir, "cmdline")
|
39
|
+
end
|
40
|
+
end # ProcessEntry
|
41
|
+
end # RPS
|
data/lib/rps/runner.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module RPS
|
2
|
+
class Runner
|
3
|
+
attr_accessor :ui
|
4
|
+
|
5
|
+
def initialize(ui = nil)
|
6
|
+
@ui = ui
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
raise "no ui provided" unless ui
|
11
|
+
procs.each { |proc| ui.render proc if proc.readable? && proc.ruby? }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def procs
|
17
|
+
@procs ||= ProcessEntry.all
|
18
|
+
end
|
19
|
+
end # Runner
|
20
|
+
end # RPS
|
data/lib/rps/ui.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module RPS
|
2
|
+
class UI
|
3
|
+
|
4
|
+
def initialize(io = $stdout)
|
5
|
+
@io = io
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(process)
|
9
|
+
string = format_string % [ process.pid,
|
10
|
+
process.exe,
|
11
|
+
process.command_line.join(' ') ]
|
12
|
+
|
13
|
+
@io << string
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_string
|
17
|
+
"%d [%s] %s\n"
|
18
|
+
end
|
19
|
+
end # RPS
|
20
|
+
end # UI
|
data/lib/rps/version.rb
ADDED
data/rps.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/rps/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rps"
|
6
|
+
s.version = RPS::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Jari Bakken"]
|
9
|
+
s.email = ["jari.bakken@gmail.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/rps"
|
11
|
+
s.summary = "Ruby Process Status"
|
12
|
+
s.description = "ps for Ruby processes"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "rps"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
19
|
+
s.add_development_dependency "autotest", ">= 4.4.5"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
23
|
+
s.require_path = 'lib'
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RPS
|
4
|
+
describe CLI do
|
5
|
+
it "creates a default runner" do
|
6
|
+
runner = mock(Runner, :ui => nil)
|
7
|
+
|
8
|
+
Runner.should_receive(:new).and_return(runner)
|
9
|
+
runner.should_receive(:run)
|
10
|
+
runner.should_receive(:ui=).with(instance_of(UI))
|
11
|
+
|
12
|
+
CLI.new.run
|
13
|
+
end
|
14
|
+
|
15
|
+
it "takes an optional arguments list" do
|
16
|
+
CLI.new.should be_instance_of(CLI)
|
17
|
+
CLI.new(["foo", "bar"]).should be_instance_of(CLI)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module RPS
|
4
|
+
describe ProcessEntry do
|
5
|
+
it "creates a process for each process in /proc" do
|
6
|
+
Dir.stub!(:[]).with("/proc/*").and_return(["/proc/1", "/proc/2", "/proc/3", "/proc/uptime"])
|
7
|
+
|
8
|
+
procs = ProcessEntry.all
|
9
|
+
|
10
|
+
procs.should be_instance_of(Array)
|
11
|
+
procs.size.should == 3
|
12
|
+
procs.each { |proc| proc.should be_instance_of(ProcessEntry) }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the pid" do
|
16
|
+
ProcessEntry.new("/proc/123").pid.should == 123
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the executable path" do
|
20
|
+
File.stub!(:readlink).with("/proc/1/exe").and_return("/some/executable")
|
21
|
+
ProcessEntry.new("/proc/1").exe.should == "/some/executable"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the command line" do
|
25
|
+
File.stub!(:read).with("/proc/1/cmdline").and_return("ruby\000-e\000sleep\000")
|
26
|
+
ProcessEntry.new("/proc/1").command_line.should == ["ruby", "-e", "sleep"]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "knows if the process is a ruby process" do
|
30
|
+
pe = ProcessEntry.new("/proc/1")
|
31
|
+
pe.stub!(:exe).and_return "/path/to/ruby"
|
32
|
+
|
33
|
+
pe.should be_ruby
|
34
|
+
end
|
35
|
+
|
36
|
+
it "knows if the process is not a ruby process" do
|
37
|
+
pe = ProcessEntry.new("/proc/1")
|
38
|
+
pe.stub!(:exe).and_return "/path/to/something else"
|
39
|
+
|
40
|
+
pe.should_not be_ruby
|
41
|
+
end
|
42
|
+
|
43
|
+
it "knows if the process is readable" do
|
44
|
+
File.should_receive(:readable?).
|
45
|
+
with("/proc/1/exe").
|
46
|
+
and_return(true)
|
47
|
+
|
48
|
+
pe = ProcessEntry.new("/proc/1")
|
49
|
+
pe.should be_readable
|
50
|
+
end
|
51
|
+
|
52
|
+
it "knows if the process isn't readable" do
|
53
|
+
File.should_receive(:readable?).
|
54
|
+
with("/proc/1/exe").
|
55
|
+
and_return(false)
|
56
|
+
|
57
|
+
pe = ProcessEntry.new("/proc/1")
|
58
|
+
pe.should_not be_readable
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module RPS
|
4
|
+
describe Runner do
|
5
|
+
let(:ui) { mock(UI) }
|
6
|
+
let(:runner) { Runner.new(ui) }
|
7
|
+
|
8
|
+
it "fetches the process list" do
|
9
|
+
ProcessEntry.should_receive(:all).and_return([])
|
10
|
+
runner.run
|
11
|
+
end
|
12
|
+
|
13
|
+
it "shows each readable ruby process on the UI" do
|
14
|
+
procs = [
|
15
|
+
mock(ProcessEntry, :ruby? => true, :readable? => true),
|
16
|
+
mock(ProcessEntry, :ruby? => false, :readable? => true),
|
17
|
+
mock(ProcessEntry, :ruby? => true, :readable? => false),
|
18
|
+
mock(ProcessEntry, :ruby? => true, :readable? => true)
|
19
|
+
]
|
20
|
+
ProcessEntry.should_receive(:all).and_return(procs)
|
21
|
+
|
22
|
+
ui.should_receive(:render).once.with(procs.first)
|
23
|
+
ui.should_receive(:render).once.with(procs.last)
|
24
|
+
|
25
|
+
runner.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/rps/ui_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module RPS
|
4
|
+
describe UI do
|
5
|
+
let(:io) { StringIO.new }
|
6
|
+
let(:ui) { UI.new(io) }
|
7
|
+
|
8
|
+
it "renders the given proc" do
|
9
|
+
pe = mock(ProcessEntry,
|
10
|
+
:exe => "/usr/bin/ruby1.8",
|
11
|
+
:pid => 123,
|
12
|
+
:command_line => %w[ruby -e sleep]
|
13
|
+
)
|
14
|
+
|
15
|
+
ui.render pe
|
16
|
+
io.string.should == "123 [/usr/bin/ruby1.8] ruby -e sleep\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jari Bakken
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-25 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 2.0.0
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: autotest
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 4
|
60
|
+
- 4
|
61
|
+
- 5
|
62
|
+
version: 4.4.5
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: ps for Ruby processes
|
66
|
+
email:
|
67
|
+
- jari.bakken@gmail.com
|
68
|
+
executables:
|
69
|
+
- rps
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- autotest/discover.rb
|
81
|
+
- bin/rps
|
82
|
+
- lib/rps.rb
|
83
|
+
- lib/rps/cli.rb
|
84
|
+
- lib/rps/process_entry.rb
|
85
|
+
- lib/rps/runner.rb
|
86
|
+
- lib/rps/ui.rb
|
87
|
+
- lib/rps/version.rb
|
88
|
+
- rps.gemspec
|
89
|
+
- spec/rps/cli_spec.rb
|
90
|
+
- spec/rps/process_entry_spec.rb
|
91
|
+
- spec/rps/runner_spec.rb
|
92
|
+
- spec/rps/ui_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://rubygems.org/gems/rps
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 1
|
118
|
+
- 3
|
119
|
+
- 6
|
120
|
+
version: 1.3.6
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project: rps
|
124
|
+
rubygems_version: 1.3.7
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Ruby Process Status
|
128
|
+
test_files: []
|
129
|
+
|